blob: 20ad79799d38a5ae1efe0de9c34b49585ddbbf78 [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 Lattner6af02f32004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner0132aff2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
27 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000028 </ol>
29 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000030 <li><a href="#typesystem">Type System</a>
31 <ol>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000032 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000033 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000034 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000035 </ol>
36 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000037 <li><a href="#t_derived">Derived Types</a>
38 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000039 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000040 <li><a href="#t_function">Function Type</a></li>
41 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000042 <li><a href="#t_struct">Structure Type</a></li>
Chris Lattnerc8cb6952004-08-12 19:12:28 +000043 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000044 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000045 </ol>
46 </li>
47 </ol>
48 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000049 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000050 <ol>
51 <li><a href="#simpleconstants">Simple Constants</a>
52 <li><a href="#aggregateconstants">Aggregate Constants</a>
53 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
54 <li><a href="#undefvalues">Undefined Values</a>
55 <li><a href="#constantexprs">Constant Expressions</a>
56 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000057 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000058 <li><a href="#othervalues">Other Values</a>
59 <ol>
60 <li><a href="#inlineasm">Inline Assembler Expressions</a>
61 </ol>
62 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000063 <li><a href="#instref">Instruction Reference</a>
64 <ol>
65 <li><a href="#terminators">Terminator Instructions</a>
66 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000067 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
68 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000069 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
70 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000071 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000072 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000073 </ol>
74 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000075 <li><a href="#binaryops">Binary Operations</a>
76 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000077 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
78 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
79 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
80 <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li>
81 <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000082 <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000083 </ol>
84 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000085 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
86 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000087 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000088 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000089 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
90 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
91 <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000092 </ol>
93 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000094 <li><a href="#memoryops">Memory Access Operations</a>
95 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000096 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
97 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
98 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000099 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
100 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
101 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000102 </ol>
103 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000104 <li><a href="#otherops">Other Operations</a>
105 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000106 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000107 <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000108 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000109 <li><a href="#i_vset">'<tt>vset</tt>' Instruction</a></li>
110 <li><a href="#i_vselect">'<tt>vselect</tt>' Instruction</a></li>
Robert Bocchinob5f210f2006-01-05 17:37:02 +0000111 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +0000112 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000113 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000114 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000115 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000116 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000117 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000118 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000119 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000120 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000121 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
122 <ol>
123 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
124 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
125 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
126 </ol>
127 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000128 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
129 <ol>
130 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
131 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
132 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
133 </ol>
134 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000135 <li><a href="#int_codegen">Code Generator Intrinsics</a>
136 <ol>
137 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
138 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner2f0f0012006-01-13 02:03:13 +0000139 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
140 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattnerc8a2c222005-02-28 19:24:19 +0000141 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharthb4427912005-03-28 20:05:49 +0000142 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth01aa5632005-11-11 16:47:30 +0000143 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000144 </ol>
145 </li>
146 <li><a href="#int_os">Operating System Intrinsics</a>
147 <ol>
Chris Lattner3b4f4372004-06-11 02:28:03 +0000148 <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li>
149 <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li>
John Criswella4501222004-04-12 15:02:16 +0000150 <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li>
151 <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000152 </ol>
Chris Lattnerfee11462004-02-12 17:01:32 +0000153 <li><a href="#int_libc">Standard C Library Intrinsics</a>
154 <ol>
Chris Lattner0c8b2592006-03-03 00:07:20 +0000155 <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
156 <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
157 <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
Chris Lattner069b5bd2006-01-16 22:38:59 +0000158 <li><a href="#i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a></li>
159 <li><a href="#i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
Chris Lattner8a8f2e52005-07-21 01:29:16 +0000160
Chris Lattnerfee11462004-02-12 17:01:32 +0000161 </ol>
162 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000163 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000164 <ol>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000165 <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000166 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
167 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
168 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000169 </ol>
170 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000171 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000172 </ol>
173 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000174</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000175
176<div class="doc_author">
177 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
178 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000179</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000180
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000182<div class="doc_section"> <a name="abstract">Abstract </a></div>
183<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000184
Misha Brukman76307852003-11-08 01:05:38 +0000185<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000186<p>This document is a reference manual for the LLVM assembly language.
187LLVM is an SSA based representation that provides type safety,
188low-level operations, flexibility, and the capability of representing
189'all' high-level languages cleanly. It is the common code
190representation used throughout all phases of the LLVM compilation
191strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000192</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000193
Chris Lattner2f7c9632001-06-06 20:29:01 +0000194<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000195<div class="doc_section"> <a name="introduction">Introduction</a> </div>
196<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000197
Misha Brukman76307852003-11-08 01:05:38 +0000198<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000199
Chris Lattner48b383b02003-11-25 01:02:51 +0000200<p>The LLVM code representation is designed to be used in three
201different forms: as an in-memory compiler IR, as an on-disk bytecode
202representation (suitable for fast loading by a Just-In-Time compiler),
203and as a human readable assembly language representation. This allows
204LLVM to provide a powerful intermediate representation for efficient
205compiler transformations and analysis, while providing a natural means
206to debug and visualize the transformations. The three different forms
207of LLVM are all equivalent. This document describes the human readable
208representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000209
John Criswell4a3327e2005-05-13 22:25:59 +0000210<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000211while being expressive, typed, and extensible at the same time. It
212aims to be a "universal IR" of sorts, by being at a low enough level
213that high-level ideas may be cleanly mapped to it (similar to how
214microprocessors are "universal IR's", allowing many source languages to
215be mapped to them). By providing type information, LLVM can be used as
216the target of optimizations: for example, through pointer analysis, it
217can be proven that a C automatic variable is never accessed outside of
218the current function... allowing it to be promoted to a simple SSA
219value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000220
Misha Brukman76307852003-11-08 01:05:38 +0000221</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000222
Chris Lattner2f7c9632001-06-06 20:29:01 +0000223<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000224<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000225
Misha Brukman76307852003-11-08 01:05:38 +0000226<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000227
Chris Lattner48b383b02003-11-25 01:02:51 +0000228<p>It is important to note that this document describes 'well formed'
229LLVM assembly language. There is a difference between what the parser
230accepts and what is considered 'well formed'. For example, the
231following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000232
233<pre>
234 %x = <a href="#i_add">add</a> int 1, %x
235</pre>
236
Chris Lattner48b383b02003-11-25 01:02:51 +0000237<p>...because the definition of <tt>%x</tt> does not dominate all of
238its uses. The LLVM infrastructure provides a verification pass that may
239be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000240automatically run by the parser after parsing input assembly and by
Chris Lattner48b383b02003-11-25 01:02:51 +0000241the optimizer before it outputs bytecode. The violations pointed out
242by the verifier pass indicate bugs in transformation passes or input to
243the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000244
Chris Lattner48b383b02003-11-25 01:02:51 +0000245<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000246
Chris Lattner2f7c9632001-06-06 20:29:01 +0000247<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000248<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000249<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000250
Misha Brukman76307852003-11-08 01:05:38 +0000251<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000252
Chris Lattner48b383b02003-11-25 01:02:51 +0000253<p>LLVM uses three different forms of identifiers, for different
254purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000255
Chris Lattner2f7c9632001-06-06 20:29:01 +0000256<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000257 <li>Named values are represented as a string of characters with a '%' prefix.
258 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
259 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
260 Identifiers which require other characters in their names can be surrounded
261 with quotes. In this way, anything except a <tt>"</tt> character can be used
262 in a name.</li>
263
264 <li>Unnamed values are represented as an unsigned numeric value with a '%'
265 prefix. For example, %12, %2, %44.</li>
266
Reid Spencer8f08d802004-12-09 18:02:53 +0000267 <li>Constants, which are described in a <a href="#constants">section about
268 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000269</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000270
271<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
272don't need to worry about name clashes with reserved words, and the set of
273reserved words may be expanded in the future without penalty. Additionally,
274unnamed identifiers allow a compiler to quickly come up with a temporary
275variable without having to avoid symbol table conflicts.</p>
276
Chris Lattner48b383b02003-11-25 01:02:51 +0000277<p>Reserved words in LLVM are very similar to reserved words in other
278languages. There are keywords for different opcodes ('<tt><a
Chris Lattnerd79749a2004-12-09 16:36:40 +0000279href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a
280href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
281href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
282and others. These reserved words cannot conflict with variable names, because
283none of them start with a '%' character.</p>
284
285<p>Here is an example of LLVM code to multiply the integer variable
286'<tt>%X</tt>' by 8:</p>
287
Misha Brukman76307852003-11-08 01:05:38 +0000288<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000289
290<pre>
291 %result = <a href="#i_mul">mul</a> uint %X, 8
292</pre>
293
Misha Brukman76307852003-11-08 01:05:38 +0000294<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000295
296<pre>
297 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
298</pre>
299
Misha Brukman76307852003-11-08 01:05:38 +0000300<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000301
302<pre>
303 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
304 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
305 %result = <a href="#i_add">add</a> uint %1, %1
306</pre>
307
Chris Lattner48b383b02003-11-25 01:02:51 +0000308<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
309important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000310
Chris Lattner2f7c9632001-06-06 20:29:01 +0000311<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000312
313 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
314 line.</li>
315
316 <li>Unnamed temporaries are created when the result of a computation is not
317 assigned to a named value.</li>
318
Misha Brukman76307852003-11-08 01:05:38 +0000319 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000320
Misha Brukman76307852003-11-08 01:05:38 +0000321</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000322
John Criswell02fdc6f2005-05-12 16:52:32 +0000323<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000324demonstrating instructions, we will follow an instruction with a comment that
325defines the type and name of value produced. Comments are shown in italic
326text.</p>
327
Misha Brukman76307852003-11-08 01:05:38 +0000328</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000329
330<!-- *********************************************************************** -->
331<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
332<!-- *********************************************************************** -->
333
334<!-- ======================================================================= -->
335<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
336</div>
337
338<div class="doc_text">
339
340<p>LLVM programs are composed of "Module"s, each of which is a
341translation unit of the input programs. Each module consists of
342functions, global variables, and symbol table entries. Modules may be
343combined together with the LLVM linker, which merges function (and
344global variable) definitions, resolves forward declarations, and merges
345symbol table entries. Here is an example of the "hello world" module:</p>
346
347<pre><i>; Declare the string constant as a global constant...</i>
348<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
349 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
350
351<i>; External declaration of the puts function</i>
352<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
353
354<i>; Definition of main function</i>
355int %main() { <i>; int()* </i>
356 <i>; Convert [13x sbyte]* to sbyte *...</i>
357 %cast210 = <a
358 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
359
360 <i>; Call puts function to write out the string to stdout...</i>
361 <a
362 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
363 <a
364 href="#i_ret">ret</a> int 0<br>}<br></pre>
365
366<p>This example is made up of a <a href="#globalvars">global variable</a>
367named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
368function, and a <a href="#functionstructure">function definition</a>
369for "<tt>main</tt>".</p>
370
Chris Lattnerd79749a2004-12-09 16:36:40 +0000371<p>In general, a module is made up of a list of global values,
372where both functions and global variables are global values. Global values are
373represented by a pointer to a memory location (in this case, a pointer to an
374array of char, and a pointer to a function), and have one of the following <a
375href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000376
Chris Lattnerd79749a2004-12-09 16:36:40 +0000377</div>
378
379<!-- ======================================================================= -->
380<div class="doc_subsection">
381 <a name="linkage">Linkage Types</a>
382</div>
383
384<div class="doc_text">
385
386<p>
387All Global Variables and Functions have one of the following types of linkage:
388</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000389
390<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000391
Chris Lattner6af02f32004-12-09 16:11:40 +0000392 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000393
394 <dd>Global values with internal linkage are only directly accessible by
395 objects in the current module. In particular, linking code into a module with
396 an internal global value may cause the internal to be renamed as necessary to
397 avoid collisions. Because the symbol is internal to the module, all
398 references can be updated. This corresponds to the notion of the
399 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++.
Chris Lattner6af02f32004-12-09 16:11:40 +0000400 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000401
Chris Lattner6af02f32004-12-09 16:11:40 +0000402 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000403
404 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
405 the twist that linking together two modules defining the same
406 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
407 is typically used to implement inline functions. Unreferenced
408 <tt>linkonce</tt> globals are allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000409 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000410
Chris Lattner6af02f32004-12-09 16:11:40 +0000411 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000412
413 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
414 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
415 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000416 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000417
Chris Lattner6af02f32004-12-09 16:11:40 +0000418 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000419
420 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
421 pointer to array type. When two global variables with appending linkage are
422 linked together, the two global arrays are appended together. This is the
423 LLVM, typesafe, equivalent of having the system linker append together
424 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000425 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000426
Chris Lattner6af02f32004-12-09 16:11:40 +0000427 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000428
429 <dd>If none of the above identifiers are used, the global is externally
430 visible, meaning that it participates in linkage and can be used to resolve
431 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000432 </dd>
433</dl>
434
Chris Lattner6af02f32004-12-09 16:11:40 +0000435<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
436variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
437variable and was linked with this one, one of the two would be renamed,
438preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
439external (i.e., lacking any linkage declarations), they are accessible
440outside of the current module. It is illegal for a function <i>declaration</i>
441to have any linkage type other than "externally visible".</a></p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000442
Chris Lattner6af02f32004-12-09 16:11:40 +0000443</div>
444
445<!-- ======================================================================= -->
446<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000447 <a name="callingconv">Calling Conventions</a>
448</div>
449
450<div class="doc_text">
451
452<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
453and <a href="#i_invoke">invokes</a> can all have an optional calling convention
454specified for the call. The calling convention of any pair of dynamic
455caller/callee must match, or the behavior of the program is undefined. The
456following calling conventions are supported by LLVM, and more may be added in
457the future:</p>
458
459<dl>
460 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
461
462 <dd>This calling convention (the default if no other calling convention is
463 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000464 supports varargs function calls and tolerates some mismatch in the declared
Chris Lattner0132aff2005-05-06 22:57:40 +0000465 prototype and implemented declaration of the function (as does normal C).
466 </dd>
467
468 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
469
470 <dd>This calling convention attempts to make calls as fast as possible
471 (e.g. by passing things in registers). This calling convention allows the
472 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000473 without having to conform to an externally specified ABI. Implementations of
474 this convention should allow arbitrary tail call optimization to be supported.
475 This calling convention does not support varargs and requires the prototype of
476 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000477 </dd>
478
479 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
480
481 <dd>This calling convention attempts to make code in the caller as efficient
482 as possible under the assumption that the call is not commonly executed. As
483 such, these calls often preserve all registers so that the call does not break
484 any live ranges in the caller side. This calling convention does not support
485 varargs and requires the prototype of all callees to exactly match the
486 prototype of the function definition.
487 </dd>
488
Chris Lattner573f64e2005-05-07 01:46:40 +0000489 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000490
491 <dd>Any calling convention may be specified by number, allowing
492 target-specific calling conventions to be used. Target specific calling
493 conventions start at 64.
494 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000495</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000496
497<p>More calling conventions can be added/defined on an as-needed basis, to
498support pascal conventions or any other well-known target-independent
499convention.</p>
500
501</div>
502
503<!-- ======================================================================= -->
504<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000505 <a name="globalvars">Global Variables</a>
506</div>
507
508<div class="doc_text">
509
Chris Lattner5d5aede2005-02-12 19:30:21 +0000510<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000511instead of run-time. Global variables may optionally be initialized, may have
512an explicit section to be placed in, and may
Chris Lattner54611b42005-11-06 08:02:57 +0000513have an optional explicit alignment specified. A
John Criswell4c0cf7f2005-10-24 16:17:18 +0000514variable may be defined as a global "constant," which indicates that the
Chris Lattner5d5aede2005-02-12 19:30:21 +0000515contents of the variable will <b>never</b> be modified (enabling better
516optimization, allowing the global data to be placed in the read-only section of
517an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000518cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000519
520<p>
521LLVM explicitly allows <em>declarations</em> of global variables to be marked
522constant, even if the final definition of the global is not. This capability
523can be used to enable slightly better optimization of the program, but requires
524the language definition to guarantee that optimizations based on the
525'constantness' are valid for the translation units that do not include the
526definition.
527</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000528
529<p>As SSA values, global variables define pointer values that are in
530scope (i.e. they dominate) all basic blocks in the program. Global
531variables always define a pointer to their "content" type because they
532describe a region of memory, and all memory objects in LLVM are
533accessed through pointers.</p>
534
Chris Lattner662c8722005-11-12 00:45:07 +0000535<p>LLVM allows an explicit section to be specified for globals. If the target
536supports it, it will emit globals to the section specified.</p>
537
Chris Lattner54611b42005-11-06 08:02:57 +0000538<p>An explicit alignment may be specified for a global. If not present, or if
539the alignment is set to zero, the alignment of the global is set by the target
540to whatever it feels convenient. If an explicit alignment is specified, the
541global is forced to have at least that much alignment. All alignments must be
542a power of 2.</p>
543
Chris Lattner6af02f32004-12-09 16:11:40 +0000544</div>
545
546
547<!-- ======================================================================= -->
548<div class="doc_subsection">
549 <a name="functionstructure">Functions</a>
550</div>
551
552<div class="doc_text">
553
Chris Lattner0132aff2005-05-06 22:57:40 +0000554<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
555type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner662c8722005-11-12 00:45:07 +0000556type, a function name, a (possibly empty) argument list, an optional section,
557an optional alignment, an opening curly brace,
Chris Lattner0132aff2005-05-06 22:57:40 +0000558a list of basic blocks, and a closing curly brace. LLVM function declarations
559are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner54611b42005-11-06 08:02:57 +0000560href="#callingconv">calling convention</a>, a return type, a function name,
561a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000562
563<p>A function definition contains a list of basic blocks, forming the CFG for
564the function. Each basic block may optionally start with a label (giving the
565basic block a symbol table entry), contains a list of instructions, and ends
566with a <a href="#terminators">terminator</a> instruction (such as a branch or
567function return).</p>
568
John Criswell02fdc6f2005-05-12 16:52:32 +0000569<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000570executed on entrance to the function, and it is not allowed to have predecessor
571basic blocks (i.e. there can not be any branches to the entry block of a
572function). Because the block can have no predecessors, it also cannot have any
573<a href="#i_phi">PHI nodes</a>.</p>
574
575<p>LLVM functions are identified by their name and type signature. Hence, two
576functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000577considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000578appropriately.</p>
579
Chris Lattner662c8722005-11-12 00:45:07 +0000580<p>LLVM allows an explicit section to be specified for functions. If the target
581supports it, it will emit functions to the section specified.</p>
582
Chris Lattner54611b42005-11-06 08:02:57 +0000583<p>An explicit alignment may be specified for a function. If not present, or if
584the alignment is set to zero, the alignment of the function is set by the target
585to whatever it feels convenient. If an explicit alignment is specified, the
586function is forced to have at least that much alignment. All alignments must be
587a power of 2.</p>
588
Chris Lattner6af02f32004-12-09 16:11:40 +0000589</div>
590
Chris Lattner91c15c42006-01-23 23:23:47 +0000591<!-- ======================================================================= -->
592<div class="doc_subsection">
593 <a name="moduleasm">Module-Level Inline Assembly</a></li>
594</div>
595
596<div class="doc_text">
597<p>
598Modules may contain "module-level inline asm" blocks, which corresponds to the
599GCC "file scope inline asm" blocks. These blocks are internally concatenated by
600LLVM and treated as a single unit, but may be separated in the .ll file if
601desired. The syntax is very simple:
602</p>
603
604<div class="doc_code"><pre>
Chris Lattnera1280ad2006-01-24 00:37:20 +0000605 module asm "inline asm code goes here"
606 module asm "more can go here"
Chris Lattner91c15c42006-01-23 23:23:47 +0000607</pre></div>
608
609<p>The strings can contain any character by escaping non-printable characters.
610 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
611 for the number.
612</p>
613
614<p>
615 The inline asm code is simply printed to the machine code .s file when
616 assembly code is generated.
617</p>
618</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000619
620
Chris Lattner2f7c9632001-06-06 20:29:01 +0000621<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000622<div class="doc_section"> <a name="typesystem">Type System</a> </div>
623<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000624
Misha Brukman76307852003-11-08 01:05:38 +0000625<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000626
Misha Brukman76307852003-11-08 01:05:38 +0000627<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000628intermediate representation. Being typed enables a number of
629optimizations to be performed on the IR directly, without having to do
630extra analyses on the side before the transformation. A strong type
631system makes it easier to read the generated code and enables novel
632analyses and transformations that are not feasible to perform on normal
633three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000634
635</div>
636
Chris Lattner2f7c9632001-06-06 20:29:01 +0000637<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000638<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000639<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000640<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000641system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000642
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000643<table class="layout">
644 <tr class="layout">
645 <td class="left">
646 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000647 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000648 <tr><th>Type</th><th>Description</th></tr>
649 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000650 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
651 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
652 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
653 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
654 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000655 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000656 </tbody>
657 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000658 </td>
659 <td class="right">
660 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000661 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000662 <tr><th>Type</th><th>Description</th></tr>
663 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000664 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
665 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
666 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
667 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
668 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000669 </tbody>
670 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000671 </td>
672 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000673</table>
Misha Brukman76307852003-11-08 01:05:38 +0000674</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000675
Chris Lattner2f7c9632001-06-06 20:29:01 +0000676<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000677<div class="doc_subsubsection"> <a name="t_classifications">Type
678Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000679<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000680<p>These different primitive types fall into a few useful
681classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000682
683<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000684 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000685 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000686 <tr>
687 <td><a name="t_signed">signed</a></td>
688 <td><tt>sbyte, short, int, long, float, double</tt></td>
689 </tr>
690 <tr>
691 <td><a name="t_unsigned">unsigned</a></td>
692 <td><tt>ubyte, ushort, uint, ulong</tt></td>
693 </tr>
694 <tr>
695 <td><a name="t_integer">integer</a></td>
696 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
697 </tr>
698 <tr>
699 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000700 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
701 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000702 </tr>
703 <tr>
704 <td><a name="t_floating">floating point</a></td>
705 <td><tt>float, double</tt></td>
706 </tr>
707 <tr>
708 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000709 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
710 float, double, <a href="#t_pointer">pointer</a>,
711 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000712 </tr>
713 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000714</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000715
Chris Lattner48b383b02003-11-25 01:02:51 +0000716<p>The <a href="#t_firstclass">first class</a> types are perhaps the
717most important. Values of these types are the only ones which can be
718produced by instructions, passed as arguments, or used as operands to
719instructions. This means that all structures and arrays must be
720manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000721</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000722
Chris Lattner2f7c9632001-06-06 20:29:01 +0000723<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000724<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000725
Misha Brukman76307852003-11-08 01:05:38 +0000726<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000727
Chris Lattner48b383b02003-11-25 01:02:51 +0000728<p>The real power in LLVM comes from the derived types in the system.
729This is what allows a programmer to represent arrays, functions,
730pointers, and other useful types. Note that these derived types may be
731recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000732
Misha Brukman76307852003-11-08 01:05:38 +0000733</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000734
Chris Lattner2f7c9632001-06-06 20:29:01 +0000735<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000736<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000737
Misha Brukman76307852003-11-08 01:05:38 +0000738<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000739
Chris Lattner2f7c9632001-06-06 20:29:01 +0000740<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000741
Misha Brukman76307852003-11-08 01:05:38 +0000742<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000743sequentially in memory. The array type requires a size (number of
744elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000745
Chris Lattner590645f2002-04-14 06:13:44 +0000746<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000747
748<pre>
749 [&lt;# elements&gt; x &lt;elementtype&gt;]
750</pre>
751
John Criswell02fdc6f2005-05-12 16:52:32 +0000752<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000753be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000754
Chris Lattner590645f2002-04-14 06:13:44 +0000755<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000756<table class="layout">
757 <tr class="layout">
758 <td class="left">
759 <tt>[40 x int ]</tt><br/>
760 <tt>[41 x int ]</tt><br/>
761 <tt>[40 x uint]</tt><br/>
762 </td>
763 <td class="left">
764 Array of 40 integer values.<br/>
765 Array of 41 integer values.<br/>
766 Array of 40 unsigned integer values.<br/>
767 </td>
768 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000769</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000770<p>Here are some examples of multidimensional arrays:</p>
771<table class="layout">
772 <tr class="layout">
773 <td class="left">
774 <tt>[3 x [4 x int]]</tt><br/>
775 <tt>[12 x [10 x float]]</tt><br/>
776 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
777 </td>
778 <td class="left">
John Criswell4a3327e2005-05-13 22:25:59 +0000779 3x4 array of integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000780 12x10 array of single precision floating point values.<br/>
781 2x3x4 array of unsigned integer values.<br/>
782 </td>
783 </tr>
784</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000785
John Criswell4c0cf7f2005-10-24 16:17:18 +0000786<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
787length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000788LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
789As a special case, however, zero length arrays are recognized to be variable
790length. This allows implementation of 'pascal style arrays' with the LLVM
791type "{ int, [0 x float]}", for example.</p>
792
Misha Brukman76307852003-11-08 01:05:38 +0000793</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000794
Chris Lattner2f7c9632001-06-06 20:29:01 +0000795<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000796<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000797<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000798<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000799<p>The function type can be thought of as a function signature. It
800consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000801Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000802(which are structures of pointers to functions), for indirect function
803calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000804<p>
805The return type of a function type cannot be an aggregate type.
806</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000807<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000808<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +0000809<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +0000810specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000811which indicates that the function takes a variable number of arguments.
812Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000813 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000814<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000815<table class="layout">
816 <tr class="layout">
817 <td class="left">
818 <tt>int (int)</tt> <br/>
819 <tt>float (int, int *) *</tt><br/>
820 <tt>int (sbyte *, ...)</tt><br/>
821 </td>
822 <td class="left">
823 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
824 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000825 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000826 returning <tt>float</tt>.<br/>
827 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
828 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
829 the signature for <tt>printf</tt> in LLVM.<br/>
830 </td>
831 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000832</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000833
Misha Brukman76307852003-11-08 01:05:38 +0000834</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000835<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000836<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000837<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000838<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000839<p>The structure type is used to represent a collection of data members
840together in memory. The packing of the field types is defined to match
841the ABI of the underlying processor. The elements of a structure may
842be any type that has a size.</p>
843<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
844and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
845field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
846instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000847<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000848<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000849<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000850<table class="layout">
851 <tr class="layout">
852 <td class="left">
853 <tt>{ int, int, int }</tt><br/>
854 <tt>{ float, int (int) * }</tt><br/>
855 </td>
856 <td class="left">
857 a triple of three <tt>int</tt> values<br/>
858 A pair, where the first element is a <tt>float</tt> and the second element
859 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
860 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
861 </td>
862 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000863</table>
Misha Brukman76307852003-11-08 01:05:38 +0000864</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000865
Chris Lattner2f7c9632001-06-06 20:29:01 +0000866<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000867<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000868<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000869<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000870<p>As in many languages, the pointer type represents a pointer or
871reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000872<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000873<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +0000874<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000875<table class="layout">
876 <tr class="layout">
877 <td class="left">
878 <tt>[4x int]*</tt><br/>
879 <tt>int (int *) *</tt><br/>
880 </td>
881 <td class="left">
882 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
883 four <tt>int</tt> values<br/>
884 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattner16fb0032005-02-19 02:22:14 +0000885 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000886 <tt>int</tt>.<br/>
887 </td>
888 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000889</table>
Misha Brukman76307852003-11-08 01:05:38 +0000890</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000891
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000892<!-- _______________________________________________________________________ -->
893<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000894<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +0000895
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000896<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000897
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000898<p>A packed type is a simple derived type that represents a vector
899of elements. Packed types are used when multiple primitive data
900are operated in parallel using a single instruction (SIMD).
901A packed type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +0000902elements) and an underlying primitive data type. Vectors must have a power
903of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000904considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000905
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000906<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000907
908<pre>
909 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
910</pre>
911
John Criswell4a3327e2005-05-13 22:25:59 +0000912<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000913be any integral or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +0000914
Chris Lattnerc8cb6952004-08-12 19:12:28 +0000915<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +0000916
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000917<table class="layout">
918 <tr class="layout">
919 <td class="left">
920 <tt>&lt;4 x int&gt;</tt><br/>
921 <tt>&lt;8 x float&gt;</tt><br/>
922 <tt>&lt;2 x uint&gt;</tt><br/>
923 </td>
924 <td class="left">
925 Packed vector of 4 integer values.<br/>
926 Packed vector of 8 floating-point values.<br/>
927 Packed vector of 2 unsigned integer values.<br/>
928 </td>
929 </tr>
930</table>
Misha Brukman76307852003-11-08 01:05:38 +0000931</div>
932
Chris Lattner37b6b092005-04-25 17:34:15 +0000933<!-- _______________________________________________________________________ -->
934<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
935<div class="doc_text">
936
937<h5>Overview:</h5>
938
939<p>Opaque types are used to represent unknown types in the system. This
940corresponds (for example) to the C notion of a foward declared structure type.
941In LLVM, opaque types can eventually be resolved to any type (not just a
942structure type).</p>
943
944<h5>Syntax:</h5>
945
946<pre>
947 opaque
948</pre>
949
950<h5>Examples:</h5>
951
952<table class="layout">
953 <tr class="layout">
954 <td class="left">
955 <tt>opaque</tt>
956 </td>
957 <td class="left">
958 An opaque type.<br/>
959 </td>
960 </tr>
961</table>
962</div>
963
964
Chris Lattner74d3f822004-12-09 17:30:23 +0000965<!-- *********************************************************************** -->
966<div class="doc_section"> <a name="constants">Constants</a> </div>
967<!-- *********************************************************************** -->
968
969<div class="doc_text">
970
971<p>LLVM has several different basic types of constants. This section describes
972them all and their syntax.</p>
973
974</div>
975
976<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +0000977<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000978
979<div class="doc_text">
980
981<dl>
982 <dt><b>Boolean constants</b></dt>
983
984 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
985 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
986 </dd>
987
988 <dt><b>Integer constants</b></dt>
989
Reid Spencer8f08d802004-12-09 18:02:53 +0000990 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattner74d3f822004-12-09 17:30:23 +0000991 href="#t_integer">integer</a> type. Negative numbers may be used with signed
992 integer types.
993 </dd>
994
995 <dt><b>Floating point constants</b></dt>
996
997 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
998 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +0000999 notation (see below). Floating point constants must have a <a
1000 href="#t_floating">floating point</a> type. </dd>
1001
1002 <dt><b>Null pointer constants</b></dt>
1003
John Criswelldfe6a862004-12-10 15:51:16 +00001004 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001005 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1006
1007</dl>
1008
John Criswelldfe6a862004-12-10 15:51:16 +00001009<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001010of floating point constants. For example, the form '<tt>double
10110x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
10124.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001013(and the only time that they are generated by the disassembler) is when a
1014floating point constant must be emitted but it cannot be represented as a
1015decimal floating point number. For example, NaN's, infinities, and other
1016special values are represented in their IEEE hexadecimal format so that
1017assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001018
1019</div>
1020
1021<!-- ======================================================================= -->
1022<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1023</div>
1024
1025<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +00001026<p>Aggregate constants arise from aggregation of simple constants
1027and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001028
1029<dl>
1030 <dt><b>Structure constants</b></dt>
1031
1032 <dd>Structure constants are represented with notation similar to structure
1033 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner455fc8c2005-03-07 22:13:59 +00001034 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
1035 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
1036 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001037 types of elements must match those specified by the type.
1038 </dd>
1039
1040 <dt><b>Array constants</b></dt>
1041
1042 <dd>Array constants are represented with notation similar to array type
1043 definitions (a comma separated list of elements, surrounded by square brackets
John Criswelldfe6a862004-12-10 15:51:16 +00001044 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001045 constants must have <a href="#t_array">array type</a>, and the number and
1046 types of elements must match those specified by the type.
1047 </dd>
1048
1049 <dt><b>Packed constants</b></dt>
1050
1051 <dd>Packed constants are represented with notation similar to packed type
1052 definitions (a comma separated list of elements, surrounded by
John Criswelldfe6a862004-12-10 15:51:16 +00001053 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattner74d3f822004-12-09 17:30:23 +00001054 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1055 href="#t_packed">packed type</a>, and the number and types of elements must
1056 match those specified by the type.
1057 </dd>
1058
1059 <dt><b>Zero initialization</b></dt>
1060
1061 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1062 value to zero of <em>any</em> type, including scalar and aggregate types.
1063 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001064 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001065 initializers.
1066 </dd>
1067</dl>
1068
1069</div>
1070
1071<!-- ======================================================================= -->
1072<div class="doc_subsection">
1073 <a name="globalconstants">Global Variable and Function Addresses</a>
1074</div>
1075
1076<div class="doc_text">
1077
1078<p>The addresses of <a href="#globalvars">global variables</a> and <a
1079href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001080constants. These constants are explicitly referenced when the <a
1081href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001082href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1083file:</p>
1084
1085<pre>
1086 %X = global int 17
1087 %Y = global int 42
1088 %Z = global [2 x int*] [ int* %X, int* %Y ]
1089</pre>
1090
1091</div>
1092
1093<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001094<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001095<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001096 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001097 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001098 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001099
Reid Spencer641f5c92004-12-09 18:13:12 +00001100 <p>Undefined values indicate to the compiler that the program is well defined
1101 no matter what value is used, giving the compiler more freedom to optimize.
1102 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001103</div>
1104
1105<!-- ======================================================================= -->
1106<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1107</div>
1108
1109<div class="doc_text">
1110
1111<p>Constant expressions are used to allow expressions involving other constants
1112to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001113href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001114that does not have side effects (e.g. load and call are not supported). The
1115following is the syntax for constant expressions:</p>
1116
1117<dl>
1118 <dt><b><tt>cast ( CST to TYPE )</tt></b></dt>
1119
1120 <dd>Cast a constant to another type.</dd>
1121
1122 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1123
1124 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1125 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1126 instruction, the index list may have zero or more indexes, which are required
1127 to make sense for the type of "CSTPTR".</dd>
1128
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001129 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1130
1131 <dd>Perform the <a href="#i_select">select operation</a> on
1132 constants.
1133
1134 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1135
1136 <dd>Perform the <a href="#i_extractelement">extractelement
1137 operation</a> on constants.
1138
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001139 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1140
1141 <dd>Perform the <a href="#i_insertelement">insertelement
1142 operation</a> on constants.
1143
Chris Lattner74d3f822004-12-09 17:30:23 +00001144 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1145
Reid Spencer641f5c92004-12-09 18:13:12 +00001146 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1147 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001148 binary</a> operations. The constraints on operands are the same as those for
1149 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001150 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001151</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001152</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001153
Chris Lattner2f7c9632001-06-06 20:29:01 +00001154<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00001155<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1156<!-- *********************************************************************** -->
1157
1158<!-- ======================================================================= -->
1159<div class="doc_subsection">
1160<a name="inlineasm">Inline Assembler Expressions</a>
1161</div>
1162
1163<div class="doc_text">
1164
1165<p>
1166LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1167Module-Level Inline Assembly</a>) through the use of a special value. This
1168value represents the inline assembler as a string (containing the instructions
1169to emit), a list of operand constraints (stored as a string), and a flag that
1170indicates whether or not the inline asm expression has side effects. An example
1171inline assembler expression is:
1172</p>
1173
1174<pre>
1175 int(int) asm "bswap $0", "=r,r"
1176</pre>
1177
1178<p>
1179Inline assembler expressions may <b>only</b> be used as the callee operand of
1180a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1181</p>
1182
1183<pre>
1184 %X = call int asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(int %Y)
1185</pre>
1186
1187<p>
1188Inline asms with side effects not visible in the constraint list must be marked
1189as having side effects. This is done through the use of the
1190'<tt>sideeffect</tt>' keyword, like so:
1191</p>
1192
1193<pre>
1194 call void asm sideeffect "eieio", ""()
1195</pre>
1196
1197<p>TODO: The format of the asm and constraints string still need to be
1198documented here. Constraints on what can be done (e.g. duplication, moving, etc
1199need to be documented).
1200</p>
1201
1202</div>
1203
1204<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001205<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1206<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001207
Misha Brukman76307852003-11-08 01:05:38 +00001208<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001209
Chris Lattner48b383b02003-11-25 01:02:51 +00001210<p>The LLVM instruction set consists of several different
1211classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001212instructions</a>, <a href="#binaryops">binary instructions</a>,
1213<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001214 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1215instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001216
Misha Brukman76307852003-11-08 01:05:38 +00001217</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001218
Chris Lattner2f7c9632001-06-06 20:29:01 +00001219<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001220<div class="doc_subsection"> <a name="terminators">Terminator
1221Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001222
Misha Brukman76307852003-11-08 01:05:38 +00001223<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001224
Chris Lattner48b383b02003-11-25 01:02:51 +00001225<p>As mentioned <a href="#functionstructure">previously</a>, every
1226basic block in a program ends with a "Terminator" instruction, which
1227indicates which block should be executed after the current block is
1228finished. These terminator instructions typically yield a '<tt>void</tt>'
1229value: they produce control flow, not values (the one exception being
1230the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001231<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001232 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1233instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001234the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1235 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1236 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001237
Misha Brukman76307852003-11-08 01:05:38 +00001238</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001239
Chris Lattner2f7c9632001-06-06 20:29:01 +00001240<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001241<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1242Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001243<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001244<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001245<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 +00001246 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001247</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001248<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001249<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001250value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001251<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001252returns a value and then causes control flow, and one that just causes
1253control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001254<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001255<p>The '<tt>ret</tt>' instruction may return any '<a
1256 href="#t_firstclass">first class</a>' type. Notice that a function is
1257not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1258instruction inside of the function that returns a value that does not
1259match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001260<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001261<p>When the '<tt>ret</tt>' instruction is executed, control flow
1262returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001263 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001264the instruction after the call. If the caller was an "<a
1265 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001266at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001267returns a value, that value shall set the call or invoke instruction's
1268return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001269<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001270<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001271 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001272</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001273</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001274<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001275<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001276<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001277<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001278<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 +00001279</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001280<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001281<p>The '<tt>br</tt>' instruction is used to cause control flow to
1282transfer to a different basic block in the current function. There are
1283two forms of this instruction, corresponding to a conditional branch
1284and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001285<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001286<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1287single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1288unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1289value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001290<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001291<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1292argument is evaluated. If the value is <tt>true</tt>, control flows
1293to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1294control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001295<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001296<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
1297 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 +00001298</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001299<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001300<div class="doc_subsubsection">
1301 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1302</div>
1303
Misha Brukman76307852003-11-08 01:05:38 +00001304<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001305<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001306
1307<pre>
1308 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1309</pre>
1310
Chris Lattner2f7c9632001-06-06 20:29:01 +00001311<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001312
1313<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1314several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001315instruction, allowing a branch to occur to one of many possible
1316destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001317
1318
Chris Lattner2f7c9632001-06-06 20:29:01 +00001319<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001320
1321<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1322comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1323an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1324table is not allowed to contain duplicate constant entries.</p>
1325
Chris Lattner2f7c9632001-06-06 20:29:01 +00001326<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001327
Chris Lattner48b383b02003-11-25 01:02:51 +00001328<p>The <tt>switch</tt> instruction specifies a table of values and
1329destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001330table is searched for the given value. If the value is found, control flow is
1331transfered to the corresponding destination; otherwise, control flow is
1332transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001333
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001334<h5>Implementation:</h5>
1335
1336<p>Depending on properties of the target machine and the particular
1337<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001338ways. For example, it could be generated as a series of chained conditional
1339branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001340
1341<h5>Example:</h5>
1342
1343<pre>
1344 <i>; Emulate a conditional br instruction</i>
1345 %Val = <a href="#i_cast">cast</a> bool %value to int
1346 switch int %Val, label %truedest [int 0, label %falsedest ]
1347
1348 <i>; Emulate an unconditional br instruction</i>
1349 switch uint 0, label %dest [ ]
1350
1351 <i>; Implement a jump table:</i>
1352 switch uint %val, label %otherwise [ uint 0, label %onzero
1353 uint 1, label %onone
1354 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001355</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001356</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001357
Chris Lattner2f7c9632001-06-06 20:29:01 +00001358<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001359<div class="doc_subsubsection">
1360 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1361</div>
1362
Misha Brukman76307852003-11-08 01:05:38 +00001363<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001364
Chris Lattner2f7c9632001-06-06 20:29:01 +00001365<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001366
1367<pre>
1368 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
1369 to label &lt;normal label&gt; except label &lt;exception label&gt;
1370</pre>
1371
Chris Lattnera8292f32002-05-06 22:08:29 +00001372<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001373
1374<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1375function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001376'<tt>normal</tt>' label or the
1377'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001378"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1379"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001380href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1381continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001382
Chris Lattner2f7c9632001-06-06 20:29:01 +00001383<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001384
Misha Brukman76307852003-11-08 01:05:38 +00001385<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001386
Chris Lattner2f7c9632001-06-06 20:29:01 +00001387<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001388 <li>
John Criswell4a3327e2005-05-13 22:25:59 +00001389 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001390 convention</a> the call should use. If none is specified, the call defaults
1391 to using C calling conventions.
1392 </li>
1393 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1394 function value being invoked. In most cases, this is a direct function
1395 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1396 an arbitrary pointer to function value.
1397 </li>
1398
1399 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1400 function to be invoked. </li>
1401
1402 <li>'<tt>function args</tt>': argument list whose types match the function
1403 signature argument types. If the function signature indicates the function
1404 accepts a variable number of arguments, the extra arguments can be
1405 specified. </li>
1406
1407 <li>'<tt>normal label</tt>': the label reached when the called function
1408 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1409
1410 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1411 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1412
Chris Lattner2f7c9632001-06-06 20:29:01 +00001413</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001414
Chris Lattner2f7c9632001-06-06 20:29:01 +00001415<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001416
Misha Brukman76307852003-11-08 01:05:38 +00001417<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001418href="#i_call">call</a></tt>' instruction in most regards. The primary
1419difference is that it establishes an association with a label, which is used by
1420the runtime library to unwind the stack.</p>
1421
1422<p>This instruction is used in languages with destructors to ensure that proper
1423cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1424exception. Additionally, this is important for implementation of
1425'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1426
Chris Lattner2f7c9632001-06-06 20:29:01 +00001427<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001428<pre>
1429 %retval = invoke int %Test(int 15) to label %Continue
1430 except label %TestCleanup <i>; {int}:retval set</i>
1431 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
1432 except label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001433</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001434</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001435
1436
Chris Lattner5ed60612003-09-03 00:41:47 +00001437<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001438
Chris Lattner48b383b02003-11-25 01:02:51 +00001439<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1440Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001441
Misha Brukman76307852003-11-08 01:05:38 +00001442<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001443
Chris Lattner5ed60612003-09-03 00:41:47 +00001444<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001445<pre>
1446 unwind
1447</pre>
1448
Chris Lattner5ed60612003-09-03 00:41:47 +00001449<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001450
1451<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1452at the first callee in the dynamic call stack which used an <a
1453href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1454primarily used to implement exception handling.</p>
1455
Chris Lattner5ed60612003-09-03 00:41:47 +00001456<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001457
1458<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1459immediately halt. The dynamic call stack is then searched for the first <a
1460href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1461execution continues at the "exceptional" destination block specified by the
1462<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1463dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001464</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001465
1466<!-- _______________________________________________________________________ -->
1467
1468<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1469Instruction</a> </div>
1470
1471<div class="doc_text">
1472
1473<h5>Syntax:</h5>
1474<pre>
1475 unreachable
1476</pre>
1477
1478<h5>Overview:</h5>
1479
1480<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1481instruction is used to inform the optimizer that a particular portion of the
1482code is not reachable. This can be used to indicate that the code after a
1483no-return function cannot be reached, and other facts.</p>
1484
1485<h5>Semantics:</h5>
1486
1487<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1488</div>
1489
1490
1491
Chris Lattner2f7c9632001-06-06 20:29:01 +00001492<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001493<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001494<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001495<p>Binary operators are used to do most of the computation in a
1496program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001497produce a single value. The operands might represent
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001498multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1499The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001500necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001501<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001502</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001503<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001504<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1505Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001506<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001507<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001508<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 +00001509</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001510<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001511<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001512<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001513<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001514 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1515 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1516Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001517<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001518<p>The value produced is the integer or floating point sum of the two
1519operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001520<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001521<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001522</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001523</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001524<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001525<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1526Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001527<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001528<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001529<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 +00001530</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001531<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001532<p>The '<tt>sub</tt>' instruction returns the difference of its two
1533operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001534<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1535instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001536<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001537<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001538 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001539values.
1540This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1541Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001542<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001543<p>The value produced is the integer or floating point difference of
1544the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001545<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001546<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001547 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1548</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001549</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001550<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001551<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1552Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001553<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001554<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001555<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 +00001556</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001557<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001558<p>The '<tt>mul</tt>' instruction returns the product of its two
1559operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001560<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001561<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001562 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001563values.
1564This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1565Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001566<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001567<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001568two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001569<p>There is no signed vs unsigned multiplication. The appropriate
1570action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001571<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001572<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001573</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001574</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001575<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001576<div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>'
1577Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001578<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001579<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001580<pre> &lt;result&gt; = div &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1581</pre>
1582<h5>Overview:</h5>
1583<p>The '<tt>div</tt>' instruction returns the quotient of its two
1584operands.</p>
1585<h5>Arguments:</h5>
1586<p>The two arguments to the '<tt>div</tt>' instruction must be either <a
1587 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001588values.
1589This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1590Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001591<h5>Semantics:</h5>
1592<p>The value produced is the integer or floating point quotient of the
1593two operands.</p>
1594<h5>Example:</h5>
1595<pre> &lt;result&gt; = div int 4, %var <i>; yields {int}:result = 4 / %var</i>
1596</pre>
1597</div>
1598<!-- _______________________________________________________________________ -->
1599<div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>'
1600Instruction</a> </div>
1601<div class="doc_text">
1602<h5>Syntax:</h5>
1603<pre> &lt;result&gt; = rem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1604</pre>
1605<h5>Overview:</h5>
1606<p>The '<tt>rem</tt>' instruction returns the remainder from the
1607division of its two operands.</p>
1608<h5>Arguments:</h5>
1609<p>The two arguments to the '<tt>rem</tt>' instruction must be either <a
1610 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001611values.
1612This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1613Both arguments must have identical types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001614<h5>Semantics:</h5>
1615<p>This returns the <i>remainder</i> of a division (where the result
1616has the same sign as the divisor), not the <i>modulus</i> (where the
1617result has the same sign as the dividend) of a value. For more
John Criswell4c0cf7f2005-10-24 16:17:18 +00001618information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001619 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1620Math Forum</a>.</p>
1621<h5>Example:</h5>
1622<pre> &lt;result&gt; = rem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1623</pre>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00001624
Chris Lattner48b383b02003-11-25 01:02:51 +00001625</div>
1626<!-- _______________________________________________________________________ -->
1627<div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>'
1628Instructions</a> </div>
1629<div class="doc_text">
1630<h5>Syntax:</h5>
1631<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 +00001632 &lt;result&gt; = setne &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1633 &lt;result&gt; = setlt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1634 &lt;result&gt; = setgt &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1635 &lt;result&gt; = setle &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1636 &lt;result&gt; = setge &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
1637</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001638<h5>Overview:</h5>
1639<p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean
1640value based on a comparison of their two operands.</p>
1641<h5>Arguments:</h5>
1642<p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must
1643be of <a href="#t_firstclass">first class</a> type (it is not possible
1644to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>'
1645or '<tt>void</tt>' values, etc...). Both arguments must have identical
1646types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001647<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001648<p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1649value if both operands are equal.<br>
1650The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1651value if both operands are unequal.<br>
1652The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1653value if the first operand is less than the second operand.<br>
1654The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1655value if the first operand is greater than the second operand.<br>
1656The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1657value if the first operand is less than or equal to the second operand.<br>
1658The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>'
1659value if the first operand is greater than or equal to the second
1660operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001661<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001662<pre> &lt;result&gt; = seteq int 4, 5 <i>; yields {bool}:result = false</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001663 &lt;result&gt; = setne float 4, 5 <i>; yields {bool}:result = true</i>
1664 &lt;result&gt; = setlt uint 4, 5 <i>; yields {bool}:result = true</i>
1665 &lt;result&gt; = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i>
1666 &lt;result&gt; = setle sbyte 4, 5 <i>; yields {bool}:result = true</i>
1667 &lt;result&gt; = setge sbyte 4, 5 <i>; yields {bool}:result = false</i>
1668</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001669</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00001670
Chris Lattner2f7c9632001-06-06 20:29:01 +00001671<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001672<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1673Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001674<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001675<p>Bitwise binary operators are used to do various forms of
1676bit-twiddling in a program. They are generally very efficient
John Criswelldfe6a862004-12-10 15:51:16 +00001677instructions and can commonly be strength reduced from other
Chris Lattner48b383b02003-11-25 01:02:51 +00001678instructions. They require two operands, execute an operation on them,
1679and produce a single value. The resulting value of the bitwise binary
1680operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001681</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001682<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001683<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1684Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001685<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001686<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001687<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 +00001688</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001689<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001690<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1691its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001692<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001693<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001694 href="#t_integral">integral</a> values. Both arguments must have
1695identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001696<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001697<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001698<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001699<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001700<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001701 <tbody>
1702 <tr>
1703 <td>In0</td>
1704 <td>In1</td>
1705 <td>Out</td>
1706 </tr>
1707 <tr>
1708 <td>0</td>
1709 <td>0</td>
1710 <td>0</td>
1711 </tr>
1712 <tr>
1713 <td>0</td>
1714 <td>1</td>
1715 <td>0</td>
1716 </tr>
1717 <tr>
1718 <td>1</td>
1719 <td>0</td>
1720 <td>0</td>
1721 </tr>
1722 <tr>
1723 <td>1</td>
1724 <td>1</td>
1725 <td>1</td>
1726 </tr>
1727 </tbody>
1728</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001729</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001730<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001731<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001732 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1733 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1734</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001735</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001736<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001737<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001738<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001739<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001740<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 +00001741</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001742<h5>Overview:</h5>
1743<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1744or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001745<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001746<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001747 href="#t_integral">integral</a> values. Both arguments must have
1748identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001749<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001750<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001751<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001752<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001753<table border="1" cellspacing="0" cellpadding="4">
1754 <tbody>
1755 <tr>
1756 <td>In0</td>
1757 <td>In1</td>
1758 <td>Out</td>
1759 </tr>
1760 <tr>
1761 <td>0</td>
1762 <td>0</td>
1763 <td>0</td>
1764 </tr>
1765 <tr>
1766 <td>0</td>
1767 <td>1</td>
1768 <td>1</td>
1769 </tr>
1770 <tr>
1771 <td>1</td>
1772 <td>0</td>
1773 <td>1</td>
1774 </tr>
1775 <tr>
1776 <td>1</td>
1777 <td>1</td>
1778 <td>1</td>
1779 </tr>
1780 </tbody>
1781</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001782</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001783<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001784<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001785 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
1786 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
1787</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001788</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001789<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001790<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
1791Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001792<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001793<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001794<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 +00001795</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001796<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001797<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
1798or of its two operands. The <tt>xor</tt> is used to implement the
1799"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001800<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001801<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001802 href="#t_integral">integral</a> values. Both arguments must have
1803identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001804<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001805<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001806<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001807<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001808<table border="1" cellspacing="0" cellpadding="4">
1809 <tbody>
1810 <tr>
1811 <td>In0</td>
1812 <td>In1</td>
1813 <td>Out</td>
1814 </tr>
1815 <tr>
1816 <td>0</td>
1817 <td>0</td>
1818 <td>0</td>
1819 </tr>
1820 <tr>
1821 <td>0</td>
1822 <td>1</td>
1823 <td>1</td>
1824 </tr>
1825 <tr>
1826 <td>1</td>
1827 <td>0</td>
1828 <td>1</td>
1829 </tr>
1830 <tr>
1831 <td>1</td>
1832 <td>1</td>
1833 <td>0</td>
1834 </tr>
1835 </tbody>
1836</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001837</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00001838<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001839<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001840<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001841 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
1842 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00001843 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001844</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001845</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001846<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001847<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1848Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001849<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001850<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001851<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 +00001852</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001853<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001854<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1855the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001856<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001857<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001858 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1859type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001860<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001861<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001862<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001863<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 +00001864 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
1865 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
1866</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001867</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001868<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001869<div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>'
1870Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001871<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001872<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001873<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 +00001874</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001875<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001876<p>The '<tt>shr</tt>' instruction returns the first operand shifted to
1877the right a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001878<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001879<p>The first argument to the '<tt>shr</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001880 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
1881type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001882<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001883<p>If the first argument is a <a href="#t_signed">signed</a> type, the
1884most significant bit is duplicated in the newly free'd bit positions.
1885If the first argument is unsigned, zero bits shall fill the empty
1886positions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001887<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001888<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 +00001889 &lt;result&gt; = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001890 &lt;result&gt; = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
Chris Lattner33426d92003-06-18 21:30:51 +00001891 &lt;result&gt; = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
1892 &lt;result&gt; = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001893</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001894</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001895
Chris Lattner2f7c9632001-06-06 20:29:01 +00001896<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00001897<div class="doc_subsection">
1898 <a name="memoryops">Memory Access Operations</a>
1899</div>
1900
Misha Brukman76307852003-11-08 01:05:38 +00001901<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001902
Chris Lattner48b383b02003-11-25 01:02:51 +00001903<p>A key design point of an SSA-based representation is how it
1904represents memory. In LLVM, no memory locations are in SSA form, which
1905makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00001906allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001907
Misha Brukman76307852003-11-08 01:05:38 +00001908</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001909
Chris Lattner2f7c9632001-06-06 20:29:01 +00001910<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001911<div class="doc_subsubsection">
1912 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
1913</div>
1914
Misha Brukman76307852003-11-08 01:05:38 +00001915<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001916
Chris Lattner2f7c9632001-06-06 20:29:01 +00001917<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001918
1919<pre>
1920 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001921</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001922
Chris Lattner2f7c9632001-06-06 20:29:01 +00001923<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001924
Chris Lattner48b383b02003-11-25 01:02:51 +00001925<p>The '<tt>malloc</tt>' instruction allocates memory from the system
1926heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001927
Chris Lattner2f7c9632001-06-06 20:29:01 +00001928<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001929
1930<p>The '<tt>malloc</tt>' instruction allocates
1931<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00001932bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00001933appropriate type to the program. If "NumElements" is specified, it is the
1934number of elements allocated. If an alignment is specified, the value result
1935of the allocation is guaranteed to be aligned to at least that boundary. If
1936not specified, or if zero, the target can choose to align the allocation on any
1937convenient boundary.</p>
1938
Misha Brukman76307852003-11-08 01:05:38 +00001939<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001940
Chris Lattner2f7c9632001-06-06 20:29:01 +00001941<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001942
Chris Lattner48b383b02003-11-25 01:02:51 +00001943<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
1944a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001945
Chris Lattner54611b42005-11-06 08:02:57 +00001946<h5>Example:</h5>
1947
1948<pre>
1949 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
1950
1951 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001952 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
1953 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner54611b42005-11-06 08:02:57 +00001954 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
1955 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001956</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001957</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001958
Chris Lattner2f7c9632001-06-06 20:29:01 +00001959<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001960<div class="doc_subsubsection">
1961 <a name="i_free">'<tt>free</tt>' Instruction</a>
1962</div>
1963
Misha Brukman76307852003-11-08 01:05:38 +00001964<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00001965
Chris Lattner2f7c9632001-06-06 20:29:01 +00001966<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001967
1968<pre>
1969 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001970</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00001971
Chris Lattner2f7c9632001-06-06 20:29:01 +00001972<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001973
Chris Lattner48b383b02003-11-25 01:02:51 +00001974<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00001975memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001976
Chris Lattner2f7c9632001-06-06 20:29:01 +00001977<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001978
Chris Lattner48b383b02003-11-25 01:02:51 +00001979<p>'<tt>value</tt>' shall be a pointer value that points to a value
1980that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
1981instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001982
Chris Lattner2f7c9632001-06-06 20:29:01 +00001983<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001984
John Criswelldfe6a862004-12-10 15:51:16 +00001985<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00001986after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00001987
Chris Lattner2f7c9632001-06-06 20:29:01 +00001988<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00001989
1990<pre>
1991 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001992 free [4 x ubyte]* %array
1993</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001994</div>
Chris Lattner54611b42005-11-06 08:02:57 +00001995
Chris Lattner2f7c9632001-06-06 20:29:01 +00001996<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00001997<div class="doc_subsubsection">
1998 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
1999</div>
2000
Misha Brukman76307852003-11-08 01:05:38 +00002001<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002002
Chris Lattner2f7c9632001-06-06 20:29:01 +00002003<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002004
2005<pre>
2006 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002007</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002008
Chris Lattner2f7c9632001-06-06 20:29:01 +00002009<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002010
Chris Lattner48b383b02003-11-25 01:02:51 +00002011<p>The '<tt>alloca</tt>' instruction allocates memory on the current
2012stack frame of the procedure that is live until the current function
2013returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002014
Chris Lattner2f7c9632001-06-06 20:29:01 +00002015<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002016
John Criswelldfe6a862004-12-10 15:51:16 +00002017<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002018bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002019appropriate type to the program. If "NumElements" is specified, it is the
2020number of elements allocated. If an alignment is specified, the value result
2021of the allocation is guaranteed to be aligned to at least that boundary. If
2022not specified, or if zero, the target can choose to align the allocation on any
2023convenient boundary.</p>
2024
Misha Brukman76307852003-11-08 01:05:38 +00002025<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002026
Chris Lattner2f7c9632001-06-06 20:29:01 +00002027<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002028
John Criswell4a3327e2005-05-13 22:25:59 +00002029<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00002030memory is automatically released when the function returns. The '<tt>alloca</tt>'
2031instruction is commonly used to represent automatic variables that must
2032have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00002033 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00002034instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002035
Chris Lattner2f7c9632001-06-06 20:29:01 +00002036<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002037
2038<pre>
2039 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002040 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002041 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
2042 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002043</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002044</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002045
Chris Lattner2f7c9632001-06-06 20:29:01 +00002046<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002047<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2048Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002049<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002050<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002051<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 +00002052<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002053<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002054<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002055<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00002056address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00002057 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00002058marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00002059the number or order of execution of this <tt>load</tt> with other
2060volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2061instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00002062<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002063<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002064<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002065<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2066 <a
2067 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002068 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2069</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002070</div>
Chris Lattner095735d2002-05-06 03:03:22 +00002071<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002072<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2073Instruction</a> </div>
Chris Lattner095735d2002-05-06 03:03:22 +00002074<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002075<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 +00002076 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 +00002077</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002078<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002079<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002080<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002081<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell4c0cf7f2005-10-24 16:17:18 +00002082to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002083operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00002084operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00002085optimizer is not allowed to modify the number or order of execution of
2086this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2087 href="#i_store">store</a></tt> instructions.</p>
2088<h5>Semantics:</h5>
2089<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2090at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002091<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002092<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2093 <a
2094 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002095 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2096</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002097<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00002098<div class="doc_subsubsection">
2099 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2100</div>
2101
Misha Brukman76307852003-11-08 01:05:38 +00002102<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00002103<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002104<pre>
2105 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2106</pre>
2107
Chris Lattner590645f2002-04-14 06:13:44 +00002108<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002109
2110<p>
2111The '<tt>getelementptr</tt>' instruction is used to get the address of a
2112subelement of an aggregate data structure.</p>
2113
Chris Lattner590645f2002-04-14 06:13:44 +00002114<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002115
2116<p>This instruction takes a list of integer constants that indicate what
2117elements of the aggregate object to index to. The actual types of the arguments
2118provided depend on the type of the first pointer argument. The
2119'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002120levels of a structure or to a specific index in an array. When indexing into a
2121structure, only <tt>uint</tt>
John Criswell4a3327e2005-05-13 22:25:59 +00002122integer constants are allowed. When indexing into an array or pointer,
Chris Lattner33fd7022004-04-05 01:30:49 +00002123<tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p>
2124
Chris Lattner48b383b02003-11-25 01:02:51 +00002125<p>For example, let's consider a C code fragment and how it gets
2126compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002127
2128<pre>
2129 struct RT {
2130 char A;
2131 int B[10][20];
2132 char C;
2133 };
2134 struct ST {
2135 int X;
2136 double Y;
2137 struct RT Z;
2138 };
2139
2140 int *foo(struct ST *s) {
2141 return &amp;s[1].Z.B[5][13];
2142 }
2143</pre>
2144
Misha Brukman76307852003-11-08 01:05:38 +00002145<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002146
2147<pre>
2148 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2149 %ST = type { int, double, %RT }
2150
Brian Gaeke317ef962004-07-02 21:08:14 +00002151 implementation
2152
2153 int* %foo(%ST* %s) {
2154 entry:
2155 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00002156 ret int* %reg
2157 }
2158</pre>
2159
Chris Lattner590645f2002-04-14 06:13:44 +00002160<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002161
2162<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002163on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Chris Lattner10ee9652004-06-03 22:57:15 +00002164and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>,
2165<tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a>
Chris Lattner33fd7022004-04-05 01:30:49 +00002166types require <tt>uint</tt> <b>constants</b>.</p>
2167
Misha Brukman76307852003-11-08 01:05:38 +00002168<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00002169type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2170}</tt>' type, a structure. The second index indexes into the third element of
2171the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2172sbyte }</tt>' type, another structure. The third index indexes into the second
2173element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2174array. The two dimensions of the array are subscripted into, yielding an
John Criswell88190562005-05-16 16:17:45 +00002175'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattner33fd7022004-04-05 01:30:49 +00002176to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2177
Chris Lattner48b383b02003-11-25 01:02:51 +00002178<p>Note that it is perfectly legal to index partially through a
2179structure, returning a pointer to an inner element. Because of this,
2180the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002181
2182<pre>
Chris Lattner455fc8c2005-03-07 22:13:59 +00002183 int* %foo(%ST* %s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002184 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2185 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2186 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2187 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2188 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2189 ret int* %t5
2190 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002191</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002192
2193<p>Note that it is undefined to access an array out of bounds: array and
2194pointer indexes must always be within the defined bounds of the array type.
2195The one exception for this rules is zero length arrays. These arrays are
2196defined to be accessible as variable length arrays, which requires access
2197beyond the zero'th element.</p>
2198
Chris Lattner590645f2002-04-14 06:13:44 +00002199<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002200
Chris Lattner33fd7022004-04-05 01:30:49 +00002201<pre>
2202 <i>; yields [12 x ubyte]*:aptr</i>
2203 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2204</pre>
2205
2206</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002207<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002208<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002209<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +00002210<p>The instructions in this category are the "miscellaneous"
Chris Lattner48b383b02003-11-25 01:02:51 +00002211instructions, which defy better classification.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002212</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002213<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002214<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
2215Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002216<div class="doc_text">
Chris Lattner70de6632001-07-09 00:26:23 +00002217<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002218<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
Chris Lattner70de6632001-07-09 00:26:23 +00002219<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002220<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
2221the SSA graph representing the function.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002222<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002223<p>The type of the incoming values are specified with the first type
2224field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
2225as arguments, with one pair for each predecessor basic block of the
2226current block. Only values of <a href="#t_firstclass">first class</a>
2227type may be used as the value arguments to the PHI node. Only labels
2228may be used as the label arguments.</p>
2229<p>There must be no non-phi instructions between the start of a basic
2230block and the PHI instructions: i.e. PHI instructions must be first in
2231a basic block.</p>
Chris Lattner70de6632001-07-09 00:26:23 +00002232<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002233<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
2234value specified by the parameter, depending on which basic block we
2235came from in the last <a href="#terminators">terminator</a> instruction.</p>
Chris Lattnera8292f32002-05-06 22:08:29 +00002236<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002237<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 +00002238</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002239
Chris Lattnera8292f32002-05-06 22:08:29 +00002240<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002241<div class="doc_subsubsection">
2242 <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a>
2243</div>
2244
Misha Brukman76307852003-11-08 01:05:38 +00002245<div class="doc_text">
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002246
Chris Lattnera8292f32002-05-06 22:08:29 +00002247<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002248
2249<pre>
2250 &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 +00002251</pre>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002252
Chris Lattnera8292f32002-05-06 22:08:29 +00002253<h5>Overview:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002254
2255<p>
2256The '<tt>cast</tt>' instruction is used as the primitive means to convert
2257integers to floating point, change data type sizes, and break type safety (by
2258casting pointers).
2259</p>
2260
2261
Chris Lattnera8292f32002-05-06 22:08:29 +00002262<h5>Arguments:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002263
2264<p>
2265The '<tt>cast</tt>' instruction takes a value to cast, which must be a first
2266class value, and a type to cast it to, which must also be a <a
2267href="#t_firstclass">first class</a> type.
2268</p>
2269
Chris Lattnera8292f32002-05-06 22:08:29 +00002270<h5>Semantics:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002271
2272<p>
2273This instruction follows the C rules for explicit casts when determining how the
2274data being cast must change to fit in its new container.
2275</p>
2276
2277<p>
2278When casting to bool, any value that would be considered true in the context of
2279a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values,
2280all else are '<tt>false</tt>'.
2281</p>
2282
2283<p>
2284When extending an integral value from a type of one signness to another (for
2285example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the
2286<b>source</b> value is signed, and zero-extended if the source value is
2287unsigned. <tt>bool</tt> values are always zero extended into either zero or
2288one.
2289</p>
2290
Chris Lattner70de6632001-07-09 00:26:23 +00002291<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002292
2293<pre>
2294 %X = cast int 257 to ubyte <i>; yields ubyte:1</i>
Chris Lattnerd8f8ede2002-06-25 18:03:17 +00002295 %Y = cast int 123 to bool <i>; yields bool:true</i>
Chris Lattner70de6632001-07-09 00:26:23 +00002296</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002297</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002298
2299<!-- _______________________________________________________________________ -->
2300<div class="doc_subsubsection">
2301 <a name="i_select">'<tt>select</tt>' Instruction</a>
2302</div>
2303
2304<div class="doc_text">
2305
2306<h5>Syntax:</h5>
2307
2308<pre>
2309 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
2310</pre>
2311
2312<h5>Overview:</h5>
2313
2314<p>
2315The '<tt>select</tt>' instruction is used to choose one value based on a
2316condition, without branching.
2317</p>
2318
2319
2320<h5>Arguments:</h5>
2321
2322<p>
2323The '<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.
2324</p>
2325
2326<h5>Semantics:</h5>
2327
2328<p>
2329If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00002330value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002331</p>
2332
2333<h5>Example:</h5>
2334
2335<pre>
2336 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
2337</pre>
2338</div>
2339
Robert Bocchino820bc75b2006-02-17 21:18:08 +00002340<!-- _______________________________________________________________________ -->
2341<div class="doc_subsubsection"> <a name="i_vset">'<tt>vset</tt>'
2342Instruction</a> </div>
2343<div class="doc_text">
2344<h5>Syntax:</h5>
2345<pre>&lt;result&gt; = vset &lt;op&gt;, &lt;n x &lt;ty&gt;&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields &lt;n x bool&gt;</i>
2346</pre>
2347
2348<h5>Overview:</h5>
2349
2350<p>The '<tt>vset</tt>' instruction returns a vector of boolean
2351values representing, at each position, the result of the comparison
2352between the values at that position in the two operands.</p>
2353
2354<h5>Arguments:</h5>
2355
2356<p>The arguments to a '<tt>vset</tt>' instruction are a comparison
2357operation and two value arguments. The value arguments must be of <a
2358href="#t_packed">packed</a> type, and they must have identical types.
2359For value arguments of integral element type, the operation argument
2360must be one of <tt>eq</tt>, <tt>ne</tt>, <tt>lt</tt>, <tt>gt</tt>,
2361<tt>le</tt>, <tt>ge</tt>, <tt>ult</tt>, <tt>ugt</tt>, <tt>ule</tt>,
2362<tt>uge</tt>, <tt>true</tt>, and <tt>false</tt>. For value arguments
2363of floating point element type, the operation argument must be one of
2364<tt>eq</tt>, <tt>ne</tt>, <tt>lt</tt>, <tt>gt</tt>, <tt>le</tt>,
2365<tt>ge</tt>, <tt>oeq</tt>, <tt>one</tt>, <tt>olt</tt>, <tt>ogt</tt>,
2366<tt>ole</tt>, <tt>oge</tt>, <tt>ueq</tt>, <tt>une</tt>, <tt>ult</tt>,
2367<tt>ugt</tt>, <tt>ule</tt>, <tt>uge</tt>, <tt>o</tt>, <tt>u</tt>,
2368<tt>true</tt>, and <tt>false</tt>. The result is a packed
2369<tt>bool</tt> value with the same length as each operand.</p>
2370
2371<h5>Semantics:</h5>
2372
2373<p>The following table shows the semantics of '<tt>vset</tt>' for
2374integral value arguments. For each position of the result, the
2375comparison is done on the corresponding positions of the two value
2376arguments. Note that the signedness of the comparison depends on the
2377comparison opcode and <i>not</i> on the signedness of the value
2378operands. E.g., <tt>vset lt <4 x unsigned> %x, %y</tt> does an
2379elementwise <i>signed</i> comparison of <tt>%x</tt> and
2380<tt>%y</tt>.</p>
2381
2382<table border="1" cellspacing="0" cellpadding="4">
2383 <tbody>
2384 <tr><th>Operation</th><th>Result is true iff</th><th>Comparison is</th></tr>
2385 <tr><td><tt>eq</tt></td><td>var1 == var2</td><td>--</td></tr>
2386 <tr><td><tt>ne</tt></td><td>var1 != var2</td><td>--</td></tr>
2387 <tr><td><tt>lt</tt></td><td>var1 &lt; var2</td><td>signed</td></tr>
2388 <tr><td><tt>gt</tt></td><td>var1 &gt; var2</td><td>signed</td></tr>
2389 <tr><td><tt>le</tt></td><td>var1 &lt;= var2</td><td>signed</td></tr>
2390 <tr><td><tt>ge</tt></td><td>var1 &gt;= var2</td><td>signed</td></tr>
2391 <tr><td><tt>ult</tt></td><td>var1 &lt; var2</td><td>unsigned</td></tr>
2392 <tr><td><tt>ugt</tt></td><td>var1 &gt; var2</td><td>unsigned</td></tr>
2393 <tr><td><tt>ule</tt></td><td>var1 &lt;= var2</td><td>unsigned</td></tr>
2394 <tr><td><tt>uge</tt></td><td>var1 &gt;= var2</td><td>unsigned</td></tr>
2395 <tr><td><tt>true</tt></td><td>always</td><td>--</td></tr>
2396 <tr><td><tt>false</tt></td><td>never</td><td>--</td></tr>
2397 </tbody>
2398</table>
2399
2400<p>The following table shows the semantics of '<tt>vset</tt>' for
2401floating point types. If either operand is a floating point Not a
2402Number (NaN) value, the operation is unordered, and the value in the
2403first column below is produced at that position. Otherwise, the
2404operation is ordered, and the value in the second column is
2405produced.</p>
2406
2407<table border="1" cellspacing="0" cellpadding="4">
2408 <tbody>
2409 <tr><th>Operation</th><th>If unordered<th>Otherwise true iff</th></tr>
2410 <tr><td><tt>eq</tt></td><td>undefined</td><td>var1 == var2</td></tr>
2411 <tr><td><tt>ne</tt></td><td>undefined</td><td>var1 != var2</td></tr>
2412 <tr><td><tt>lt</tt></td><td>undefined</td><td>var1 &lt; var2</td></tr>
2413 <tr><td><tt>gt</tt></td><td>undefined</td><td>var1 &gt; var2</td></tr>
2414 <tr><td><tt>le</tt></td><td>undefined</td><td>var1 &lt;= var2</td></tr>
2415 <tr><td><tt>ge</tt></td><td>undefined</td><td>var1 &gt;= var2</td></tr>
2416 <tr><td><tt>oeq</tt></td><td>false</td><td>var1 == var2</td></tr>
2417 <tr><td><tt>one</tt></td><td>false</td><td>var1 != var2</td></tr>
2418 <tr><td><tt>olt</tt></td><td>false</td><td>var1 &lt; var2</td></tr>
2419 <tr><td><tt>ogt</tt></td><td>false</td><td>var1 &gt; var2</td></tr>
2420 <tr><td><tt>ole</tt></td><td>false</td><td>var1 &lt;= var2</td></tr>
2421 <tr><td><tt>oge</tt></td><td>false</td><td>var1 &gt;= var2</td></tr>
2422 <tr><td><tt>ueq</tt></td><td>true</td><td>var1 == var2</td></tr>
2423 <tr><td><tt>une</tt></td><td>true</td><td>var1 != var2</td></tr>
2424 <tr><td><tt>ult</tt></td><td>true</td><td>var1 &lt; var2</td></tr>
2425 <tr><td><tt>ugt</tt></td><td>true</td><td>var1 &gt; var2</td></tr>
2426 <tr><td><tt>ule</tt></td><td>true</td><td>var1 &lt;= var2</td></tr>
2427 <tr><td><tt>uge</tt></td><td>true</td><td>var1 &gt;= var2</td></tr>
2428 <tr><td><tt>o</tt></td><td>false</td><td>always</td></tr>
2429 <tr><td><tt>u</tt></td><td>true</td><td>never</td></tr>
2430 <tr><td><tt>true</tt></td><td>true</td><td>always</td></tr>
2431 <tr><td><tt>false</tt></td><td>false</td><td>never</td></tr>
2432 </tbody>
2433</table>
2434
2435<h5>Example:</h5>
2436<pre> &lt;result&gt; = vset eq &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, false</i>
2437 &lt;result&gt; = vset ne &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, true</i>
2438 &lt;result&gt; = vset lt &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2439 &lt;result&gt; = vset gt &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
2440 &lt;result&gt; = vset le &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = true, false</i>
2441 &lt;result&gt; = vset ge &lt;2 x int&gt; &lt;int 0, int 1&gt;, &lt;int 1, int 0&gt; <i>; yields {&lt;2 x bool&gt;}:result = false, true</i>
2442</pre>
2443</div>
2444
2445<!-- _______________________________________________________________________ -->
2446<div class="doc_subsubsection">
2447 <a name="i_vselect">'<tt>vselect</tt>' Instruction</a>
2448</div>
2449
2450<div class="doc_text">
2451
2452<h5>Syntax:</h5>
2453
2454<pre>
2455 &lt;result&gt; = vselect &lt;n x bool&gt; &lt;cond&gt;, &lt;n x &lt;ty&gt;&gt; &lt;val1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;val2&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2456</pre>
2457
2458<h5>Overview:</h5>
2459
2460<p>
2461The '<tt>vselect</tt>' instruction chooses one value at each position
2462of a vector based on a condition.
2463</p>
2464
2465
2466<h5>Arguments:</h5>
2467
2468<p>
2469The '<tt>vselect</tt>' instruction requires a <a
2470href="#t_packed">packed</a> <tt>bool</tt> value indicating the
2471condition at each vector position, and two values of the same packed
2472type. All three operands must have the same length. The type of the
2473result is the same as the type of the two value operands.</p>
2474
2475<h5>Semantics:</h5>
2476
2477<p>
2478At each position where the <tt>bool</tt> vector is true, that position
2479of the result gets its value from the first value argument; otherwise,
2480it gets its value from the second value argument.
2481</p>
2482
2483<h5>Example:</h5>
2484
2485<pre>
2486 %X = vselect bool &lt;2 x bool&gt; &lt;bool true, bool false&gt;, &lt;2 x ubyte&gt; &lt;ubyte 17, ubyte 17&gt;,
2487 &lt;2 x ubyte&gt; &lt;ubyte 42, ubyte 42&gt; <i>; yields &lt;2 x ubyte&gt;:17, 42</i>
2488</pre>
2489</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002490
Robert Bocchinob5f210f2006-01-05 17:37:02 +00002491<!-- _______________________________________________________________________ -->
2492<div class="doc_subsubsection">
2493 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2494</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002495
Robert Bocchinob5f210f2006-01-05 17:37:02 +00002496<div class="doc_text">
2497
2498<h5>Syntax:</h5>
2499
2500<pre>
2501 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, uint &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
2502</pre>
2503
2504<h5>Overview:</h5>
2505
2506<p>
2507The '<tt>extractelement</tt>' instruction extracts a single scalar
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00002508element from a packed vector at a specified index.
Robert Bocchinob5f210f2006-01-05 17:37:02 +00002509</p>
2510
2511
2512<h5>Arguments:</h5>
2513
2514<p>
2515The first operand of an '<tt>extractelement</tt>' instruction is a
2516value of <a href="#t_packed">packed</a> type. The second operand is
2517an index indicating the position from which to extract the element.
2518The index may be a variable.</p>
2519
2520<h5>Semantics:</h5>
2521
2522<p>
2523The result is a scalar of the same type as the element type of
2524<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2525<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2526results are undefined.
2527</p>
2528
2529<h5>Example:</h5>
2530
2531<pre>
2532 %result = extractelement &lt;4 x int&gt; %vec, uint 0 <i>; yields int</i>
2533</pre>
2534</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002535
2536
Chris Lattner70de6632001-07-09 00:26:23 +00002537<!-- _______________________________________________________________________ -->
Chris Lattnere23c1392005-05-06 05:47:36 +00002538<div class="doc_subsubsection">
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00002539 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2540</div>
2541
2542<div class="doc_text">
2543
2544<h5>Syntax:</h5>
2545
2546<pre>
2547 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, uint &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2548</pre>
2549
2550<h5>Overview:</h5>
2551
2552<p>
2553The '<tt>insertelement</tt>' instruction inserts a scalar
2554element into a packed vector at a specified index.
2555</p>
2556
2557
2558<h5>Arguments:</h5>
2559
2560<p>
2561The first operand of an '<tt>insertelement</tt>' instruction is a
2562value of <a href="#t_packed">packed</a> type. The second operand is a
2563scalar value whose type must equal the element type of the first
2564operand. The third operand is an index indicating the position at
2565which to insert the value. The index may be a variable.</p>
2566
2567<h5>Semantics:</h5>
2568
2569<p>
2570The result is a packed vector of the same type as <tt>val</tt>. Its
2571element values are those of <tt>val</tt> except at position
2572<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2573exceeds the length of <tt>val</tt>, the results are undefined.
2574</p>
2575
2576<h5>Example:</h5>
2577
2578<pre>
2579 %result = insertelement &lt;4 x int&gt; %vec, int 1, uint 0 <i>; yields &lt;4 x int&gt;</i>
2580</pre>
2581</div>
2582
2583
2584<!-- _______________________________________________________________________ -->
2585<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00002586 <a name="i_call">'<tt>call</tt>' Instruction</a>
2587</div>
2588
Misha Brukman76307852003-11-08 01:05:38 +00002589<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00002590
Chris Lattner2f7c9632001-06-06 20:29:01 +00002591<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002592<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00002593 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattnere23c1392005-05-06 05:47:36 +00002594</pre>
2595
Chris Lattner2f7c9632001-06-06 20:29:01 +00002596<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002597
Misha Brukman76307852003-11-08 01:05:38 +00002598<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002599
Chris Lattner2f7c9632001-06-06 20:29:01 +00002600<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002601
Misha Brukman76307852003-11-08 01:05:38 +00002602<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002603
Chris Lattnera8292f32002-05-06 22:08:29 +00002604<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00002605 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002606 <p>The optional "tail" marker indicates whether the callee function accesses
2607 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00002608 function call is eligible for tail call optimization. Note that calls may
2609 be marked "tail" even if they do not occur before a <a
2610 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00002611 </li>
2612 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002613 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
2614 convention</a> the call should use. If none is specified, the call defaults
2615 to using C calling conventions.
2616 </li>
2617 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00002618 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
2619 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00002620 signature. This type can be omitted if the function is not varargs and
2621 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002622 </li>
2623 <li>
2624 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
2625 be invoked. In most cases, this is a direct function invocation, but
2626 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00002627 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002628 </li>
2629 <li>
2630 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00002631 function signature argument types. All arguments must be of
2632 <a href="#t_firstclass">first class</a> type. If the function signature
2633 indicates the function accepts a variable number of arguments, the extra
2634 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002635 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00002636</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00002637
Chris Lattner2f7c9632001-06-06 20:29:01 +00002638<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002639
Chris Lattner48b383b02003-11-25 01:02:51 +00002640<p>The '<tt>call</tt>' instruction is used to cause control flow to
2641transfer to a specified function, with its incoming arguments bound to
2642the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
2643instruction in the called function, control flow continues with the
2644instruction after the function call, and the return value of the
2645function is bound to the result argument. This is a simpler case of
2646the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00002647
Chris Lattner2f7c9632001-06-06 20:29:01 +00002648<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00002649
2650<pre>
2651 %retval = call int %test(int %argc)
2652 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
2653 %X = tail call int %foo()
Chris Lattner0132aff2005-05-06 22:57:40 +00002654 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00002655</pre>
2656
Misha Brukman76307852003-11-08 01:05:38 +00002657</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002658
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002659<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00002660<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00002661 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002662</div>
2663
Misha Brukman76307852003-11-08 01:05:38 +00002664<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00002665
Chris Lattner26ca62e2003-10-18 05:51:36 +00002666<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002667
2668<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002669 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00002670</pre>
2671
Chris Lattner26ca62e2003-10-18 05:51:36 +00002672<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002673
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002674<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00002675the "variable argument" area of a function call. It is used to implement the
2676<tt>va_arg</tt> macro in C.</p>
2677
Chris Lattner26ca62e2003-10-18 05:51:36 +00002678<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002679
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002680<p>This instruction takes a <tt>va_list*</tt> value and the type of
2681the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00002682increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002683actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002684
Chris Lattner26ca62e2003-10-18 05:51:36 +00002685<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002686
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002687<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
2688type from the specified <tt>va_list</tt> and causes the
2689<tt>va_list</tt> to point to the next argument. For more information,
2690see the variable argument handling <a href="#int_varargs">Intrinsic
2691Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002692
2693<p>It is legal for this instruction to be called in a function which does not
2694take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00002695function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002696
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002697<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00002698href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00002699argument.</p>
2700
Chris Lattner26ca62e2003-10-18 05:51:36 +00002701<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00002702
2703<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
2704
Misha Brukman76307852003-11-08 01:05:38 +00002705</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002706
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002707<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002708<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
2709<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00002710
Misha Brukman76307852003-11-08 01:05:38 +00002711<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00002712
2713<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswell88190562005-05-16 16:17:45 +00002714well known names and semantics and are required to follow certain
Chris Lattnerfee11462004-02-12 17:01:32 +00002715restrictions. Overall, these instructions represent an extension mechanism for
2716the LLVM language that does not require changing all of the transformations in
2717LLVM to add to the language (or the bytecode reader/writer, the parser,
2718etc...).</p>
2719
John Criswell88190562005-05-16 16:17:45 +00002720<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
2721prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00002722this. Intrinsic functions must always be external functions: you cannot define
2723the body of intrinsic functions. Intrinsic functions may only be used in call
2724or invoke instructions: it is illegal to take the address of an intrinsic
2725function. Additionally, because intrinsic functions are part of the LLVM
2726language, it is required that they all be documented here if any are added.</p>
2727
2728
John Criswell88190562005-05-16 16:17:45 +00002729<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner90391c12005-05-11 03:35:57 +00002730href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00002731</p>
2732
Misha Brukman76307852003-11-08 01:05:38 +00002733</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002734
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002735<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00002736<div class="doc_subsection">
2737 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
2738</div>
2739
Misha Brukman76307852003-11-08 01:05:38 +00002740<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002741
Misha Brukman76307852003-11-08 01:05:38 +00002742<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00002743 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00002744intrinsic functions. These functions are related to the similarly
2745named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002746
Chris Lattner48b383b02003-11-25 01:02:51 +00002747<p>All of these functions operate on arguments that use a
2748target-specific value type "<tt>va_list</tt>". The LLVM assembly
2749language reference manual does not define what this type is, so all
2750transformations should be prepared to handle intrinsics with any type
2751used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002752
Misha Brukman76307852003-11-08 01:05:38 +00002753<p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00002754instruction and the variable argument handling intrinsic functions are
2755used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002756
Chris Lattnerfee11462004-02-12 17:01:32 +00002757<pre>
2758int %test(int %X, ...) {
2759 ; Initialize variable argument processing
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002760 %ap = alloca sbyte*
2761 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002762
2763 ; Read a single integer argument
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002764 %tmp = va_arg sbyte** %ap, int
Chris Lattnerfee11462004-02-12 17:01:32 +00002765
2766 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002767 %aq = alloca sbyte*
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002768 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002769 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattnerfee11462004-02-12 17:01:32 +00002770
2771 ; Stop processing of arguments.
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002772 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00002773 ret int %tmp
2774}
2775</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002776</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002777
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002778<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002779<div class="doc_subsubsection">
2780 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
2781</div>
2782
2783
Misha Brukman76307852003-11-08 01:05:38 +00002784<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002785<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002786<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002787<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002788<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
2789<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
2790href="#i_va_arg">va_arg</a></tt>.</p>
2791
2792<h5>Arguments:</h5>
2793
2794<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
2795
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002796<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002797
2798<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
2799macro available in C. In a target-dependent way, it initializes the
2800<tt>va_list</tt> element the argument points to, so that the next call to
2801<tt>va_arg</tt> will produce the first variable argument passed to the function.
2802Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
2803last argument of the function, the compiler can figure that out.</p>
2804
Misha Brukman76307852003-11-08 01:05:38 +00002805</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002806
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002807<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002808<div class="doc_subsubsection">
2809 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
2810</div>
2811
Misha Brukman76307852003-11-08 01:05:38 +00002812<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002813<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002814<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002815<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002816<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
2817which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
2818or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002819<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002820<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002821<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002822<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002823macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
2824Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
2825 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
2826with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002827</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002828
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002829<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00002830<div class="doc_subsubsection">
2831 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
2832</div>
2833
Misha Brukman76307852003-11-08 01:05:38 +00002834<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002835
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002836<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002837
2838<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002839 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002840 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002841</pre>
2842
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002843<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002844
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002845<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
2846the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002847
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002848<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002849
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002850<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00002851The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002852
Chris Lattner757528b0b2004-05-23 21:06:01 +00002853
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00002854<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00002855
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00002856<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
2857available in C. In a target-dependent way, it copies the source
2858<tt>va_list</tt> element into the destination list. This intrinsic is necessary
2859because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00002860arbitrarily complex and require memory allocation, for example.</p>
2861
Misha Brukman76307852003-11-08 01:05:38 +00002862</div>
Chris Lattner941515c2004-01-06 05:31:32 +00002863
Chris Lattnerfee11462004-02-12 17:01:32 +00002864<!-- ======================================================================= -->
2865<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00002866 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
2867</div>
2868
2869<div class="doc_text">
2870
2871<p>
2872LLVM support for <a href="GarbageCollection.html">Accurate Garbage
2873Collection</a> requires the implementation and generation of these intrinsics.
2874These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
2875stack</a>, as well as garbage collector implementations that require <a
2876href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
2877Front-ends for type-safe garbage collected languages should generate these
2878intrinsics to make use of the LLVM garbage collectors. For more details, see <a
2879href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
2880</p>
2881</div>
2882
2883<!-- _______________________________________________________________________ -->
2884<div class="doc_subsubsection">
2885 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
2886</div>
2887
2888<div class="doc_text">
2889
2890<h5>Syntax:</h5>
2891
2892<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002893 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002894</pre>
2895
2896<h5>Overview:</h5>
2897
John Criswelldfe6a862004-12-10 15:51:16 +00002898<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00002899the code generator, and allows some metadata to be associated with it.</p>
2900
2901<h5>Arguments:</h5>
2902
2903<p>The first argument specifies the address of a stack object that contains the
2904root pointer. The second pointer (which must be either a constant or a global
2905value address) contains the meta-data to be associated with the root.</p>
2906
2907<h5>Semantics:</h5>
2908
2909<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
2910location. At compile-time, the code generator generates information to allow
2911the runtime to find the pointer at GC safe points.
2912</p>
2913
2914</div>
2915
2916
2917<!-- _______________________________________________________________________ -->
2918<div class="doc_subsubsection">
2919 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
2920</div>
2921
2922<div class="doc_text">
2923
2924<h5>Syntax:</h5>
2925
2926<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002927 declare sbyte* %llvm.gcread(sbyte** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002928</pre>
2929
2930<h5>Overview:</h5>
2931
2932<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
2933locations, allowing garbage collector implementations that require read
2934barriers.</p>
2935
2936<h5>Arguments:</h5>
2937
2938<p>The argument is the address to read from, which should be an address
2939allocated from the garbage collector.</p>
2940
2941<h5>Semantics:</h5>
2942
2943<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
2944instruction, but may be replaced with substantially more complex code by the
2945garbage collector runtime, as needed.</p>
2946
2947</div>
2948
2949
2950<!-- _______________________________________________________________________ -->
2951<div class="doc_subsubsection">
2952 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
2953</div>
2954
2955<div class="doc_text">
2956
2957<h5>Syntax:</h5>
2958
2959<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00002960 declare void %llvm.gcwrite(sbyte* %P1, sbyte** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00002961</pre>
2962
2963<h5>Overview:</h5>
2964
2965<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
2966locations, allowing garbage collector implementations that require write
2967barriers (such as generational or reference counting collectors).</p>
2968
2969<h5>Arguments:</h5>
2970
2971<p>The first argument is the reference to store, and the second is the heap
2972location to store to.</p>
2973
2974<h5>Semantics:</h5>
2975
2976<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
2977instruction, but may be replaced with substantially more complex code by the
2978garbage collector runtime, as needed.</p>
2979
2980</div>
2981
2982
2983
2984<!-- ======================================================================= -->
2985<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00002986 <a name="int_codegen">Code Generator Intrinsics</a>
2987</div>
2988
2989<div class="doc_text">
2990<p>
2991These intrinsics are provided by LLVM to expose special features that may only
2992be implemented with code generator support.
2993</p>
2994
2995</div>
2996
2997<!-- _______________________________________________________________________ -->
2998<div class="doc_subsubsection">
2999 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
3000</div>
3001
3002<div class="doc_text">
3003
3004<h5>Syntax:</h5>
3005<pre>
Chris Lattnerb3d430e2006-01-13 01:20:27 +00003006 declare sbyte *%llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003007</pre>
3008
3009<h5>Overview:</h5>
3010
3011<p>
3012The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value
3013indicating the return address of the current function or one of its callers.
3014</p>
3015
3016<h5>Arguments:</h5>
3017
3018<p>
3019The argument to this intrinsic indicates which function to return the address
3020for. Zero indicates the calling function, one indicates its caller, etc. The
3021argument is <b>required</b> to be a constant integer value.
3022</p>
3023
3024<h5>Semantics:</h5>
3025
3026<p>
3027The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3028the return address of the specified call frame, or zero if it cannot be
3029identified. The value returned by this intrinsic is likely to be incorrect or 0
3030for arguments other than zero, so it should only be used for debugging purposes.
3031</p>
3032
3033<p>
3034Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003035aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003036source-language caller.
3037</p>
3038</div>
3039
3040
3041<!-- _______________________________________________________________________ -->
3042<div class="doc_subsubsection">
3043 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
3044</div>
3045
3046<div class="doc_text">
3047
3048<h5>Syntax:</h5>
3049<pre>
Chris Lattnerb3d430e2006-01-13 01:20:27 +00003050 declare sbyte *%llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003051</pre>
3052
3053<h5>Overview:</h5>
3054
3055<p>
3056The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame
3057pointer value for the specified stack frame.
3058</p>
3059
3060<h5>Arguments:</h5>
3061
3062<p>
3063The argument to this intrinsic indicates which function to return the frame
3064pointer for. Zero indicates the calling function, one indicates its caller,
3065etc. The argument is <b>required</b> to be a constant integer value.
3066</p>
3067
3068<h5>Semantics:</h5>
3069
3070<p>
3071The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3072the frame address of the specified call frame, or zero if it cannot be
3073identified. The value returned by this intrinsic is likely to be incorrect or 0
3074for arguments other than zero, so it should only be used for debugging purposes.
3075</p>
3076
3077<p>
3078Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003079aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003080source-language caller.
3081</p>
3082</div>
3083
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003084<!-- _______________________________________________________________________ -->
3085<div class="doc_subsubsection">
Chris Lattner2f0f0012006-01-13 02:03:13 +00003086 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
3087</div>
3088
3089<div class="doc_text">
3090
3091<h5>Syntax:</h5>
3092<pre>
3093 declare sbyte *%llvm.stacksave()
3094</pre>
3095
3096<h5>Overview:</h5>
3097
3098<p>
3099The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
3100the function stack, for use with <a href="#i_stackrestore">
3101<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
3102features like scoped automatic variable sized arrays in C99.
3103</p>
3104
3105<h5>Semantics:</h5>
3106
3107<p>
3108This intrinsic returns a opaque pointer value that can be passed to <a
3109href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
3110<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
3111<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
3112state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
3113practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
3114that were allocated after the <tt>llvm.stacksave</tt> was executed.
3115</p>
3116
3117</div>
3118
3119<!-- _______________________________________________________________________ -->
3120<div class="doc_subsubsection">
3121 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
3122</div>
3123
3124<div class="doc_text">
3125
3126<h5>Syntax:</h5>
3127<pre>
3128 declare void %llvm.stackrestore(sbyte* %ptr)
3129</pre>
3130
3131<h5>Overview:</h5>
3132
3133<p>
3134The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
3135the function stack to the state it was in when the corresponding <a
3136href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
3137useful for implementing language features like scoped automatic variable sized
3138arrays in C99.
3139</p>
3140
3141<h5>Semantics:</h5>
3142
3143<p>
3144See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
3145</p>
3146
3147</div>
3148
3149
3150<!-- _______________________________________________________________________ -->
3151<div class="doc_subsubsection">
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003152 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
3153</div>
3154
3155<div class="doc_text">
3156
3157<h5>Syntax:</h5>
3158<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003159 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
3160 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003161</pre>
3162
3163<h5>Overview:</h5>
3164
3165
3166<p>
3167The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00003168a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
3169no
3170effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00003171characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003172</p>
3173
3174<h5>Arguments:</h5>
3175
3176<p>
3177<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
3178determining if the fetch should be for a read (0) or write (1), and
3179<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00003180locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003181<tt>locality</tt> arguments must be constant integers.
3182</p>
3183
3184<h5>Semantics:</h5>
3185
3186<p>
3187This intrinsic does not modify the behavior of the program. In particular,
3188prefetches cannot trap and do not produce a value. On targets that support this
3189intrinsic, the prefetch can provide hints to the processor cache for better
3190performance.
3191</p>
3192
3193</div>
3194
Andrew Lenharthb4427912005-03-28 20:05:49 +00003195<!-- _______________________________________________________________________ -->
3196<div class="doc_subsubsection">
3197 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
3198</div>
3199
3200<div class="doc_text">
3201
3202<h5>Syntax:</h5>
3203<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003204 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00003205</pre>
3206
3207<h5>Overview:</h5>
3208
3209
3210<p>
John Criswell88190562005-05-16 16:17:45 +00003211The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
3212(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00003213code to simulators and other tools. The method is target specific, but it is
3214expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00003215The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnere64d41d2005-11-15 06:07:55 +00003216after optimizations. It is possible that the presence of a marker will inhibit
Andrew Lenharthb4427912005-03-28 20:05:49 +00003217optimizations. The intended use is to be inserted after optmizations to allow
John Criswell88190562005-05-16 16:17:45 +00003218correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00003219</p>
3220
3221<h5>Arguments:</h5>
3222
3223<p>
3224<tt>id</tt> is a numerical id identifying the marker.
3225</p>
3226
3227<h5>Semantics:</h5>
3228
3229<p>
3230This intrinsic does not modify the behavior of the program. Backends that do not
3231support this intrinisic may ignore it.
3232</p>
3233
3234</div>
3235
Andrew Lenharth01aa5632005-11-11 16:47:30 +00003236<!-- _______________________________________________________________________ -->
3237<div class="doc_subsubsection">
3238 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
3239</div>
3240
3241<div class="doc_text">
3242
3243<h5>Syntax:</h5>
3244<pre>
3245 declare ulong %llvm.readcyclecounter( )
3246</pre>
3247
3248<h5>Overview:</h5>
3249
3250
3251<p>
3252The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
3253counter register (or similar low latency, high accuracy clocks) on those targets
3254that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
3255As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
3256should only be used for small timings.
3257</p>
3258
3259<h5>Semantics:</h5>
3260
3261<p>
3262When directly supported, reading the cycle counter should not modify any memory.
3263Implementations are allowed to either return a application specific value or a
3264system wide value. On backends without support, this is lowered to a constant 0.
3265</p>
3266
3267</div>
3268
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003269
John Criswellaa1c3c12004-04-09 16:43:20 +00003270<!-- ======================================================================= -->
3271<div class="doc_subsection">
3272 <a name="int_os">Operating System Intrinsics</a>
3273</div>
3274
3275<div class="doc_text">
3276<p>
3277These intrinsics are provided by LLVM to support the implementation of
3278operating system level code.
3279</p>
3280
3281</div>
John Criswella4501222004-04-12 15:02:16 +00003282
John Criswell508b93c2004-04-09 15:23:37 +00003283<!-- _______________________________________________________________________ -->
3284<div class="doc_subsubsection">
3285 <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a>
3286</div>
3287
3288<div class="doc_text">
3289
3290<h5>Syntax:</h5>
3291<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003292 declare &lt;integer type&gt; %llvm.readport (&lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00003293</pre>
3294
3295<h5>Overview:</h5>
3296
3297<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00003298The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware
3299I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00003300</p>
3301
3302<h5>Arguments:</h5>
3303
3304<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00003305The argument to this intrinsic indicates the hardware I/O address from which
3306to read the data. The address is in the hardware I/O address namespace (as
3307opposed to being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00003308</p>
3309
3310<h5>Semantics:</h5>
3311
3312<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00003313The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port
3314specified by <i>address</i> and returns the value. The address and return
3315value must be integers, but the size is dependent upon the platform upon which
3316the program is code generated. For example, on x86, the address must be an
Misha Brukman36c6bc12005-04-22 18:02:52 +00003317unsigned 16-bit value, and the return value must be 8, 16, or 32 bits.
John Criswell508b93c2004-04-09 15:23:37 +00003318</p>
3319
3320</div>
3321
3322<!-- _______________________________________________________________________ -->
3323<div class="doc_subsubsection">
3324 <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a>
3325</div>
3326
3327<div class="doc_text">
3328
3329<h5>Syntax:</h5>
3330<pre>
Chris Lattner74d3f822004-12-09 17:30:23 +00003331 call void (&lt;integer type&gt;, &lt;integer type&gt;)*
3332 %llvm.writeport (&lt;integer type&gt; &lt;value&gt;,
3333 &lt;integer type&gt; &lt;address&gt;)
John Criswell508b93c2004-04-09 15:23:37 +00003334</pre>
3335
3336<h5>Overview:</h5>
3337
3338<p>
John Criswellaa1c3c12004-04-09 16:43:20 +00003339The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware
3340I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00003341</p>
3342
3343<h5>Arguments:</h5>
3344
3345<p>
John Criswell7a576472004-04-12 16:33:19 +00003346The first argument is the value to write to the I/O port.
John Criswell508b93c2004-04-09 15:23:37 +00003347</p>
3348
3349<p>
John Criswell7a576472004-04-12 16:33:19 +00003350The second argument indicates the hardware I/O address to which data should be
3351written. The address is in the hardware I/O address namespace (as opposed to
3352being a memory location for memory mapped I/O).
John Criswell508b93c2004-04-09 15:23:37 +00003353</p>
3354
3355<h5>Semantics:</h5>
3356
3357<p>
3358The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port
3359specified by <i>address</i>. The address and value must be integers, but the
3360size is dependent upon the platform upon which the program is code generated.
Misha Brukman36c6bc12005-04-22 18:02:52 +00003361For example, on x86, the address must be an unsigned 16-bit value, and the
John Criswellaa1c3c12004-04-09 16:43:20 +00003362value written must be 8, 16, or 32 bits in length.
John Criswell508b93c2004-04-09 15:23:37 +00003363</p>
3364
3365</div>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003366
John Criswella4501222004-04-12 15:02:16 +00003367<!-- _______________________________________________________________________ -->
3368<div class="doc_subsubsection">
3369 <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a>
3370</div>
3371
3372<div class="doc_text">
3373
3374<h5>Syntax:</h5>
3375<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003376 declare &lt;result&gt; %llvm.readio (&lt;ty&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00003377</pre>
3378
3379<h5>Overview:</h5>
3380
3381<p>
3382The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
3383address.
3384</p>
3385
3386<h5>Arguments:</h5>
3387
3388<p>
John Criswell7a576472004-04-12 16:33:19 +00003389The argument to this intrinsic is a pointer indicating the memory address from
3390which to read the data. The data must be a
3391<a href="#t_firstclass">first class</a> type.
John Criswella4501222004-04-12 15:02:16 +00003392</p>
3393
3394<h5>Semantics:</h5>
3395
3396<p>
3397The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O
John Criswell7a576472004-04-12 16:33:19 +00003398location specified by <i>pointer</i> and returns the value. The argument must
3399be a pointer, and the return value must be a
3400<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00003401may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00003402may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00003403</p>
3404
3405<p>
John Criswell7a576472004-04-12 16:33:19 +00003406This intrinsic enforces an in-order memory model for llvm.readio and
3407llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3408scheduled processors may execute loads and stores out of order, re-ordering at
3409run time accesses to memory mapped I/O registers. Using these intrinsics
3410ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00003411</p>
3412
3413</div>
3414
3415<!-- _______________________________________________________________________ -->
3416<div class="doc_subsubsection">
3417 <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a>
3418</div>
3419
3420<div class="doc_text">
3421
3422<h5>Syntax:</h5>
3423<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003424 declare void %llvm.writeio (&lt;ty1&gt; &lt;value&gt;, &lt;ty2&gt; * &lt;pointer&gt;)
John Criswella4501222004-04-12 15:02:16 +00003425</pre>
3426
3427<h5>Overview:</h5>
3428
3429<p>
3430The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory
3431mapped I/O address.
3432</p>
3433
3434<h5>Arguments:</h5>
3435
3436<p>
John Criswell7a576472004-04-12 16:33:19 +00003437The first argument is the value to write to the memory mapped I/O location.
3438The second argument is a pointer indicating the memory address to which the
3439data should be written.
John Criswella4501222004-04-12 15:02:16 +00003440</p>
3441
3442<h5>Semantics:</h5>
3443
3444<p>
3445The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped
John Criswell7a576472004-04-12 16:33:19 +00003446I/O address specified by <i>pointer</i>. The value must be a
3447<a href="#t_firstclass">first class</a> type. However, certain architectures
Misha Brukman36c6bc12005-04-22 18:02:52 +00003448may not support I/O on all first class types. For example, 32-bit processors
John Criswell7a576472004-04-12 16:33:19 +00003449may only support I/O on data types that are 32 bits or less.
John Criswella4501222004-04-12 15:02:16 +00003450</p>
3451
3452<p>
John Criswell7a576472004-04-12 16:33:19 +00003453This intrinsic enforces an in-order memory model for llvm.readio and
3454llvm.writeio calls on machines that use dynamic scheduling. Dynamically
3455scheduled processors may execute loads and stores out of order, re-ordering at
3456run time accesses to memory mapped I/O registers. Using these intrinsics
3457ensures that accesses to memory mapped I/O registers occur in program order.
John Criswella4501222004-04-12 15:02:16 +00003458</p>
3459
3460</div>
3461
Chris Lattner3649c3a2004-02-14 04:08:35 +00003462<!-- ======================================================================= -->
3463<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00003464 <a name="int_libc">Standard C Library Intrinsics</a>
3465</div>
3466
3467<div class="doc_text">
3468<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003469LLVM provides intrinsics for a few important standard C library functions.
3470These intrinsics allow source-language front-ends to pass information about the
3471alignment of the pointer arguments to the code generator, providing opportunity
3472for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00003473</p>
3474
3475</div>
3476
3477<!-- _______________________________________________________________________ -->
3478<div class="doc_subsubsection">
3479 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
3480</div>
3481
3482<div class="doc_text">
3483
3484<h5>Syntax:</h5>
3485<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003486 declare void %llvm.memcpy.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3487 uint &lt;len&gt;, uint &lt;align&gt;)
3488 declare void %llvm.memcpy.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3489 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00003490</pre>
3491
3492<h5>Overview:</h5>
3493
3494<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003495The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00003496location to the destination location.
3497</p>
3498
3499<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003500Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
3501intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00003502</p>
3503
3504<h5>Arguments:</h5>
3505
3506<p>
3507The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00003508the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00003509specifying the number of bytes to copy, and the fourth argument is the alignment
3510of the source and destination locations.
3511</p>
3512
Chris Lattner4c67c482004-02-12 21:18:15 +00003513<p>
3514If the call to this intrinisic has an alignment value that is not 0 or 1, then
3515the caller guarantees that the size of the copy is a multiple of the alignment
3516and that both the source and destination pointers are aligned to that boundary.
3517</p>
3518
Chris Lattnerfee11462004-02-12 17:01:32 +00003519<h5>Semantics:</h5>
3520
3521<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003522The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00003523location to the destination location, which are not allowed to overlap. It
3524copies "len" bytes of memory over. If the argument is known to be aligned to
3525some boundary, this can be specified as the fourth argument, otherwise it should
3526be set to 0 or 1.
3527</p>
3528</div>
3529
3530
Chris Lattnerf30152e2004-02-12 18:10:10 +00003531<!-- _______________________________________________________________________ -->
3532<div class="doc_subsubsection">
3533 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
3534</div>
3535
3536<div class="doc_text">
3537
3538<h5>Syntax:</h5>
3539<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003540 declare void %llvm.memmove.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3541 uint &lt;len&gt;, uint &lt;align&gt;)
3542 declare void %llvm.memmove.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
3543 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00003544</pre>
3545
3546<h5>Overview:</h5>
3547
3548<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003549The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
3550location to the destination location. It is similar to the
3551'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00003552</p>
3553
3554<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003555Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
3556intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00003557</p>
3558
3559<h5>Arguments:</h5>
3560
3561<p>
3562The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00003563the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00003564specifying the number of bytes to copy, and the fourth argument is the alignment
3565of the source and destination locations.
3566</p>
3567
Chris Lattner4c67c482004-02-12 21:18:15 +00003568<p>
3569If the call to this intrinisic has an alignment value that is not 0 or 1, then
3570the caller guarantees that the size of the copy is a multiple of the alignment
3571and that both the source and destination pointers are aligned to that boundary.
3572</p>
3573
Chris Lattnerf30152e2004-02-12 18:10:10 +00003574<h5>Semantics:</h5>
3575
3576<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003577The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00003578location to the destination location, which may overlap. It
3579copies "len" bytes of memory over. If the argument is known to be aligned to
3580some boundary, this can be specified as the fourth argument, otherwise it should
3581be set to 0 or 1.
3582</p>
3583</div>
3584
Chris Lattner941515c2004-01-06 05:31:32 +00003585
Chris Lattner3649c3a2004-02-14 04:08:35 +00003586<!-- _______________________________________________________________________ -->
3587<div class="doc_subsubsection">
Chris Lattner0c8b2592006-03-03 00:07:20 +00003588 <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003589</div>
3590
3591<div class="doc_text">
3592
3593<h5>Syntax:</h5>
3594<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003595 declare void %llvm.memset.i32(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3596 uint &lt;len&gt;, uint &lt;align&gt;)
3597 declare void %llvm.memset.i64(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
3598 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003599</pre>
3600
3601<h5>Overview:</h5>
3602
3603<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003604The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00003605byte value.
3606</p>
3607
3608<p>
3609Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
3610does not return a value, and takes an extra alignment argument.
3611</p>
3612
3613<h5>Arguments:</h5>
3614
3615<p>
3616The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00003617byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00003618argument specifying the number of bytes to fill, and the fourth argument is the
3619known alignment of destination location.
3620</p>
3621
3622<p>
3623If the call to this intrinisic has an alignment value that is not 0 or 1, then
3624the caller guarantees that the size of the copy is a multiple of the alignment
3625and that the destination pointer is aligned to that boundary.
3626</p>
3627
3628<h5>Semantics:</h5>
3629
3630<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00003631The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
3632the
Chris Lattner3649c3a2004-02-14 04:08:35 +00003633destination location. If the argument is known to be aligned to some boundary,
3634this can be specified as the fourth argument, otherwise it should be set to 0 or
36351.
3636</p>
3637</div>
3638
3639
Chris Lattner3b4f4372004-06-11 02:28:03 +00003640<!-- _______________________________________________________________________ -->
3641<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003642 <a name="i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a>
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003643</div>
3644
3645<div class="doc_text">
3646
3647<h5>Syntax:</h5>
3648<pre>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003649 declare bool %llvm.isunordered.f32(float Val1, float Val2)
3650 declare bool %llvm.isunordered.f64(double Val1, double Val2)
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003651</pre>
3652
3653<h5>Overview:</h5>
3654
3655<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003656The '<tt>llvm.isunordered</tt>' intrinsics return true if either or both of the
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00003657specified floating point values is a NAN.
3658</p>
3659
3660<h5>Arguments:</h5>
3661
3662<p>
3663The arguments are floating point numbers of the same type.
3664</p>
3665
3666<h5>Semantics:</h5>
3667
3668<p>
3669If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
3670false.
3671</p>
3672</div>
3673
3674
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003675<!-- _______________________________________________________________________ -->
3676<div class="doc_subsubsection">
Chris Lattner069b5bd2006-01-16 22:38:59 +00003677 <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003678</div>
3679
3680<div class="doc_text">
3681
3682<h5>Syntax:</h5>
3683<pre>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003684 declare double %llvm.sqrt.f32(float Val)
3685 declare double %llvm.sqrt.f64(double Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003686</pre>
3687
3688<h5>Overview:</h5>
3689
3690<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003691The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattner8a8f2e52005-07-21 01:29:16 +00003692returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
3693<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
3694negative numbers (which allows for better optimization).
3695</p>
3696
3697<h5>Arguments:</h5>
3698
3699<p>
3700The argument and return value are floating point numbers of the same type.
3701</p>
3702
3703<h5>Semantics:</h5>
3704
3705<p>
3706This function returns the sqrt of the specified operand if it is a positive
3707floating point number.
3708</p>
3709</div>
3710
Andrew Lenharth1d463522005-05-03 18:01:48 +00003711<!-- ======================================================================= -->
3712<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00003713 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00003714</div>
3715
3716<div class="doc_text">
3717<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00003718LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003719These allow efficient code generation for some algorithms.
3720</p>
3721
3722</div>
3723
3724<!-- _______________________________________________________________________ -->
3725<div class="doc_subsubsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00003726 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
3727</div>
3728
3729<div class="doc_text">
3730
3731<h5>Syntax:</h5>
3732<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003733 declare ushort %llvm.bswap.i16(ushort &lt;id&gt;)
3734 declare uint %llvm.bswap.i32(uint &lt;id&gt;)
3735 declare ulong %llvm.bswap.i64(ulong &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00003736</pre>
3737
3738<h5>Overview:</h5>
3739
3740<p>
3741The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
374264 bit quantity. These are useful for performing operations on data that is not
3743in the target's native byte order.
3744</p>
3745
3746<h5>Semantics:</h5>
3747
3748<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003749The <tt>llvm.bswap.16</tt> intrinsic returns a ushort value that has the high and low
3750byte of the input ushort swapped. Similarly, the <tt>llvm.bswap.i32</tt> intrinsic
Nate Begeman0f223bb2006-01-13 23:26:38 +00003751returns a uint value that has the four bytes of the input uint swapped, so that
3752if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its
Chris Lattner069b5bd2006-01-16 22:38:59 +00003753bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt> intrinsic extends this concept
Nate Begeman0f223bb2006-01-13 23:26:38 +00003754to 64 bits.
3755</p>
3756
3757</div>
3758
3759<!-- _______________________________________________________________________ -->
3760<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003761 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00003762</div>
3763
3764<div class="doc_text">
3765
3766<h5>Syntax:</h5>
3767<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003768 declare ubyte %llvm.ctpop.i8 (ubyte &lt;src&gt;)
3769 declare ushort %llvm.ctpop.i16(ushort &lt;src&gt;)
3770 declare uint %llvm.ctpop.i32(uint &lt;src&gt;)
3771 declare ulong %llvm.ctpop.i64(ulong &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00003772</pre>
3773
3774<h5>Overview:</h5>
3775
3776<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003777The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
3778value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003779</p>
3780
3781<h5>Arguments:</h5>
3782
3783<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003784The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00003785unsigned integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003786</p>
3787
3788<h5>Semantics:</h5>
3789
3790<p>
3791The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
3792</p>
3793</div>
3794
3795<!-- _______________________________________________________________________ -->
3796<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00003797 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00003798</div>
3799
3800<div class="doc_text">
3801
3802<h5>Syntax:</h5>
3803<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003804 declare ubyte %llvm.ctlz.i8 (ubyte &lt;src&gt;)
3805 declare ushort %llvm.ctlz.i16(ushort &lt;src&gt;)
3806 declare uint %llvm.ctlz.i32(uint &lt;src&gt;)
3807 declare ulong %llvm.ctlz.i64(ulong &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00003808</pre>
3809
3810<h5>Overview:</h5>
3811
3812<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003813The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
3814leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003815</p>
3816
3817<h5>Arguments:</h5>
3818
3819<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00003820The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00003821unsigned integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003822</p>
3823
3824<h5>Semantics:</h5>
3825
3826<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003827The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
3828in a variable. If the src == 0 then the result is the size in bits of the type
3829of src. For example, <tt>llvm.cttz(int 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00003830</p>
3831</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00003832
3833
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003834
3835<!-- _______________________________________________________________________ -->
3836<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00003837 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003838</div>
3839
3840<div class="doc_text">
3841
3842<h5>Syntax:</h5>
3843<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00003844 declare ubyte %llvm.cttz.i8 (ubyte &lt;src&gt;)
3845 declare ushort %llvm.cttz.i16(ushort &lt;src&gt;)
3846 declare uint %llvm.cttz.i32(uint &lt;src&gt;)
3847 declare ulong %llvm.cttz.i64(ulong &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003848</pre>
3849
3850<h5>Overview:</h5>
3851
3852<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00003853The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
3854trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003855</p>
3856
3857<h5>Arguments:</h5>
3858
3859<p>
3860The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00003861unsigned integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00003862</p>
3863
3864<h5>Semantics:</h5>
3865
3866<p>
3867The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
3868in a variable. If the src == 0 then the result is the size in bits of the type
3869of src. For example, <tt>llvm.cttz(2) = 1</tt>.
3870</p>
3871</div>
3872
Chris Lattner941515c2004-01-06 05:31:32 +00003873<!-- ======================================================================= -->
3874<div class="doc_subsection">
3875 <a name="int_debugger">Debugger Intrinsics</a>
3876</div>
3877
3878<div class="doc_text">
3879<p>
3880The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
3881are described in the <a
3882href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
3883Debugging</a> document.
3884</p>
3885</div>
3886
3887
Chris Lattner2f7c9632001-06-06 20:29:01 +00003888<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00003889<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00003890<address>
3891 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
3892 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
3893 <a href="http://validator.w3.org/check/referer"><img
3894 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
3895
3896 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
3897 <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br>
3898 Last modified: $Date$
3899</address>
Misha Brukman76307852003-11-08 01:05:38 +00003900</body>
3901</html>