blob: e7fc5396a8a91d0c5da9d1fe7946f9498622c51f [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-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 Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
Reid Spencerca86e162006-12-31 07:07:53 +000027 <li><a href="#paramattrs">Parameter Attributes</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000028 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000029 </ol>
30 </li>
Chris Lattner00950542001-06-06 20:29:01 +000031 <li><a href="#typesystem">Type System</a>
32 <ol>
Robert Bocchino7b81c752006-02-17 21:18:08 +000033 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner261efe92003-11-25 01:02:51 +000034 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000035 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000036 </ol>
37 </li>
Chris Lattner00950542001-06-06 20:29:01 +000038 <li><a href="#t_derived">Derived Types</a>
39 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000040 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000041 <li><a href="#t_function">Function Type</a></li>
42 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000043 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth75e10682006-12-08 17:13:00 +000044 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Chris Lattnera58561b2004-08-12 19:12:28 +000045 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000046 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000047 </ol>
48 </li>
49 </ol>
50 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000051 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000052 <ol>
53 <li><a href="#simpleconstants">Simple Constants</a>
54 <li><a href="#aggregateconstants">Aggregate Constants</a>
55 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
56 <li><a href="#undefvalues">Undefined Values</a>
57 <li><a href="#constantexprs">Constant Expressions</a>
58 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000059 </li>
Chris Lattnere87d6532006-01-25 23:47:57 +000060 <li><a href="#othervalues">Other Values</a>
61 <ol>
62 <li><a href="#inlineasm">Inline Assembler Expressions</a>
63 </ol>
64 </li>
Chris Lattner00950542001-06-06 20:29:01 +000065 <li><a href="#instref">Instruction Reference</a>
66 <ol>
67 <li><a href="#terminators">Terminator Instructions</a>
68 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000069 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
70 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000071 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
72 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000073 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000074 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000075 </ol>
76 </li>
Chris Lattner00950542001-06-06 20:29:01 +000077 <li><a href="#binaryops">Binary Operations</a>
78 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000079 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
80 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
81 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer1628cec2006-10-26 06:15:43 +000082 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
83 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
84 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer0a783f72006-11-02 01:53:59 +000085 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
86 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
87 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000088 </ol>
89 </li>
Chris Lattner00950542001-06-06 20:29:01 +000090 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
91 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000092 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000093 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000094 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
95 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
Reid Spencer3822ff52006-11-08 06:47:33 +000096 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
97 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000098 </ol>
99 </li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000100 <li><a href="#vectorops">Vector Operations</a>
101 <ol>
102 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
103 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
104 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000105 </ol>
106 </li>
Chris Lattner884a9702006-08-15 00:45:58 +0000107 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner00950542001-06-06 20:29:01 +0000108 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000109 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
110 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
111 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +0000112 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
113 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
114 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000115 </ol>
116 </li>
Reid Spencer2fd21e62006-11-08 01:18:52 +0000117 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000118 <ol>
119 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
120 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
121 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
122 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
123 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencerd4448792006-11-09 23:03:26 +0000124 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
125 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
126 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
127 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencer72679252006-11-11 21:00:47 +0000128 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
129 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5c0ef472006-11-11 23:08:07 +0000130 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000131 </ol>
Chris Lattner00950542001-06-06 20:29:01 +0000132 <li><a href="#otherops">Other Operations</a>
133 <ol>
Reid Spencerf3a70a62006-11-18 21:50:54 +0000134 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
135 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000136 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000137 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000138 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattnerfb6977d2006-01-13 23:26:01 +0000139 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000140 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000141 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000142 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000143 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000144 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000145 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000146 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
147 <ol>
148 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
149 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
150 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
151 </ol>
152 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000153 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
154 <ol>
155 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
156 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
157 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
158 </ol>
159 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000160 <li><a href="#int_codegen">Code Generator Intrinsics</a>
161 <ol>
162 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
163 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner57e1f392006-01-13 02:03:13 +0000164 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
165 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +0000166 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +0000167 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth51b8d542005-11-11 16:47:30 +0000168 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000169 </ol>
170 </li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000171 <li><a href="#int_libc">Standard C Library Intrinsics</a>
172 <ol>
Chris Lattner5b310c32006-03-03 00:07:20 +0000173 <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
174 <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
175 <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
Chris Lattnerec6cb612006-01-16 22:38:59 +0000176 <li><a href="#i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
Chris Lattnerf4d252d2006-09-08 06:34:02 +0000177 <li><a href="#i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000178 </ol>
179 </li>
Nate Begeman7e36c472006-01-13 23:26:38 +0000180 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000181 <ol>
Nate Begeman7e36c472006-01-13 23:26:38 +0000182 <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattner8a886be2006-01-16 22:34:14 +0000183 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
184 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
185 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000186 </ol>
187 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000188 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000189 </ol>
190 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000191</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000192
193<div class="doc_author">
194 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
195 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000196</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000197
Chris Lattner00950542001-06-06 20:29:01 +0000198<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000199<div class="doc_section"> <a name="abstract">Abstract </a></div>
200<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000201
Misha Brukman9d0919f2003-11-08 01:05:38 +0000202<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000203<p>This document is a reference manual for the LLVM assembly language.
204LLVM is an SSA based representation that provides type safety,
205low-level operations, flexibility, and the capability of representing
206'all' high-level languages cleanly. It is the common code
207representation used throughout all phases of the LLVM compilation
208strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000209</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000210
Chris Lattner00950542001-06-06 20:29:01 +0000211<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000212<div class="doc_section"> <a name="introduction">Introduction</a> </div>
213<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000214
Misha Brukman9d0919f2003-11-08 01:05:38 +0000215<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000216
Chris Lattner261efe92003-11-25 01:02:51 +0000217<p>The LLVM code representation is designed to be used in three
218different forms: as an in-memory compiler IR, as an on-disk bytecode
219representation (suitable for fast loading by a Just-In-Time compiler),
220and as a human readable assembly language representation. This allows
221LLVM to provide a powerful intermediate representation for efficient
222compiler transformations and analysis, while providing a natural means
223to debug and visualize the transformations. The three different forms
224of LLVM are all equivalent. This document describes the human readable
225representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000226
John Criswellc1f786c2005-05-13 22:25:59 +0000227<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000228while being expressive, typed, and extensible at the same time. It
229aims to be a "universal IR" of sorts, by being at a low enough level
230that high-level ideas may be cleanly mapped to it (similar to how
231microprocessors are "universal IR's", allowing many source languages to
232be mapped to them). By providing type information, LLVM can be used as
233the target of optimizations: for example, through pointer analysis, it
234can be proven that a C automatic variable is never accessed outside of
235the current function... allowing it to be promoted to a simple SSA
236value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000237
Misha Brukman9d0919f2003-11-08 01:05:38 +0000238</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000239
Chris Lattner00950542001-06-06 20:29:01 +0000240<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000241<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000242
Misha Brukman9d0919f2003-11-08 01:05:38 +0000243<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000244
Chris Lattner261efe92003-11-25 01:02:51 +0000245<p>It is important to note that this document describes 'well formed'
246LLVM assembly language. There is a difference between what the parser
247accepts and what is considered 'well formed'. For example, the
248following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000249
250<pre>
Reid Spencerca86e162006-12-31 07:07:53 +0000251 %x = <a href="#i_add">add</a> i32 1, %x
Chris Lattnerd7923912004-05-23 21:06:01 +0000252</pre>
253
Chris Lattner261efe92003-11-25 01:02:51 +0000254<p>...because the definition of <tt>%x</tt> does not dominate all of
255its uses. The LLVM infrastructure provides a verification pass that may
256be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000257automatically run by the parser after parsing input assembly and by
Chris Lattner261efe92003-11-25 01:02:51 +0000258the optimizer before it outputs bytecode. The violations pointed out
259by the verifier pass indicate bugs in transformation passes or input to
260the parser.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000261
Chris Lattner261efe92003-11-25 01:02:51 +0000262<!-- Describe the typesetting conventions here. --> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000263
Chris Lattner00950542001-06-06 20:29:01 +0000264<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000265<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000266<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000267
Misha Brukman9d0919f2003-11-08 01:05:38 +0000268<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000269
Chris Lattner261efe92003-11-25 01:02:51 +0000270<p>LLVM uses three different forms of identifiers, for different
271purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000272
Chris Lattner00950542001-06-06 20:29:01 +0000273<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000274 <li>Named values are represented as a string of characters with a '%' prefix.
275 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
276 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
277 Identifiers which require other characters in their names can be surrounded
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000278 with quotes. In this way, anything except a <tt>&quot;</tt> character can be used
Chris Lattnere5d947b2004-12-09 16:36:40 +0000279 in a name.</li>
280
281 <li>Unnamed values are represented as an unsigned numeric value with a '%'
282 prefix. For example, %12, %2, %44.</li>
283
Reid Spencercc16dc32004-12-09 18:02:53 +0000284 <li>Constants, which are described in a <a href="#constants">section about
285 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000286</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000287
288<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
289don't need to worry about name clashes with reserved words, and the set of
290reserved words may be expanded in the future without penalty. Additionally,
291unnamed identifiers allow a compiler to quickly come up with a temporary
292variable without having to avoid symbol table conflicts.</p>
293
Chris Lattner261efe92003-11-25 01:02:51 +0000294<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5c0ef472006-11-11 23:08:07 +0000295languages. There are keywords for different opcodes
296('<tt><a href="#i_add">add</a></tt>',
297 '<tt><a href="#i_bitcast">bitcast</a></tt>',
298 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerca86e162006-12-31 07:07:53 +0000299href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnere5d947b2004-12-09 16:36:40 +0000300and others. These reserved words cannot conflict with variable names, because
301none of them start with a '%' character.</p>
302
303<p>Here is an example of LLVM code to multiply the integer variable
304'<tt>%X</tt>' by 8:</p>
305
Misha Brukman9d0919f2003-11-08 01:05:38 +0000306<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000307
308<pre>
Reid Spencerca86e162006-12-31 07:07:53 +0000309 %result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnere5d947b2004-12-09 16:36:40 +0000310</pre>
311
Misha Brukman9d0919f2003-11-08 01:05:38 +0000312<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000313
314<pre>
Reid Spencerca86e162006-12-31 07:07:53 +0000315 %result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnere5d947b2004-12-09 16:36:40 +0000316</pre>
317
Misha Brukman9d0919f2003-11-08 01:05:38 +0000318<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000319
320<pre>
Reid Spencerca86e162006-12-31 07:07:53 +0000321 <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
322 <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
323 %result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnere5d947b2004-12-09 16:36:40 +0000324</pre>
325
Chris Lattner261efe92003-11-25 01:02:51 +0000326<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
327important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000328
Chris Lattner00950542001-06-06 20:29:01 +0000329<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000330
331 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
332 line.</li>
333
334 <li>Unnamed temporaries are created when the result of a computation is not
335 assigned to a named value.</li>
336
Misha Brukman9d0919f2003-11-08 01:05:38 +0000337 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000338
Misha Brukman9d0919f2003-11-08 01:05:38 +0000339</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000340
John Criswelle4c57cc2005-05-12 16:52:32 +0000341<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000342demonstrating instructions, we will follow an instruction with a comment that
343defines the type and name of value produced. Comments are shown in italic
344text.</p>
345
Misha Brukman9d0919f2003-11-08 01:05:38 +0000346</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000347
348<!-- *********************************************************************** -->
349<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
350<!-- *********************************************************************** -->
351
352<!-- ======================================================================= -->
353<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
354</div>
355
356<div class="doc_text">
357
358<p>LLVM programs are composed of "Module"s, each of which is a
359translation unit of the input programs. Each module consists of
360functions, global variables, and symbol table entries. Modules may be
361combined together with the LLVM linker, which merges function (and
362global variable) definitions, resolves forward declarations, and merges
363symbol table entries. Here is an example of the "hello world" module:</p>
364
365<pre><i>; Declare the string constant as a global constant...</i>
366<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
Reid Spencerca86e162006-12-31 07:07:53 +0000367 href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000368
369<i>; External declaration of the puts function</i>
Reid Spencerca86e162006-12-31 07:07:53 +0000370<a href="#functionstructure">declare</a> i32 %puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000371
Chris Lattner81c01f02006-06-13 03:05:47 +0000372<i>; Global variable / Function body section separator</i>
373implementation
374
Chris Lattnerfa730212004-12-09 16:11:40 +0000375<i>; Definition of main function</i>
Reid Spencerca86e162006-12-31 07:07:53 +0000376define i32 %main() { <i>; i32()* </i>
377 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000378 %cast210 = <a
Reid Spencerca86e162006-12-31 07:07:53 +0000379 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* %.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000380
381 <i>; Call puts function to write out the string to stdout...</i>
382 <a
Reid Spencerca86e162006-12-31 07:07:53 +0000383 href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000384 <a
Reid Spencerca86e162006-12-31 07:07:53 +0000385 href="#i_ret">ret</a> i32 0<br>}<br></pre>
Chris Lattnerfa730212004-12-09 16:11:40 +0000386
387<p>This example is made up of a <a href="#globalvars">global variable</a>
388named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
389function, and a <a href="#functionstructure">function definition</a>
390for "<tt>main</tt>".</p>
391
Chris Lattnere5d947b2004-12-09 16:36:40 +0000392<p>In general, a module is made up of a list of global values,
393where both functions and global variables are global values. Global values are
394represented by a pointer to a memory location (in this case, a pointer to an
395array of char, and a pointer to a function), and have one of the following <a
396href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000397
Chris Lattner81c01f02006-06-13 03:05:47 +0000398<p>Due to a limitation in the current LLVM assembly parser (it is limited by
399one-token lookahead), modules are split into two pieces by the "implementation"
400keyword. Global variable prototypes and definitions must occur before the
401keyword, and function definitions must occur after it. Function prototypes may
402occur either before or after it. In the future, the implementation keyword may
403become a noop, if the parser gets smarter.</p>
404
Chris Lattnere5d947b2004-12-09 16:36:40 +0000405</div>
406
407<!-- ======================================================================= -->
408<div class="doc_subsection">
409 <a name="linkage">Linkage Types</a>
410</div>
411
412<div class="doc_text">
413
414<p>
415All Global Variables and Functions have one of the following types of linkage:
416</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000417
418<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000419
Chris Lattnerfa730212004-12-09 16:11:40 +0000420 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000421
422 <dd>Global values with internal linkage are only directly accessible by
423 objects in the current module. In particular, linking code into a module with
424 an internal global value may cause the internal to be renamed as necessary to
425 avoid collisions. Because the symbol is internal to the module, all
426 references can be updated. This corresponds to the notion of the
Chris Lattner4887bd82007-01-14 06:51:48 +0000427 '<tt>static</tt>' keyword in C.
Chris Lattnerfa730212004-12-09 16:11:40 +0000428 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000429
Chris Lattnerfa730212004-12-09 16:11:40 +0000430 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000431
Chris Lattner4887bd82007-01-14 06:51:48 +0000432 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
433 the same name when linkage occurs. This is typically used to implement
434 inline functions, templates, or other code which must be generated in each
435 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
436 allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000437 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000438
Chris Lattnerfa730212004-12-09 16:11:40 +0000439 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000440
441 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
442 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattner4887bd82007-01-14 06:51:48 +0000443 used for globals that may be emitted in multiple translation units, but that
444 are not guaranteed to be emitted into every translation unit that uses them.
445 One example of this are common globals in C, such as "<tt>int X;</tt>" at
446 global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000447 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000448
Chris Lattnerfa730212004-12-09 16:11:40 +0000449 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000450
451 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
452 pointer to array type. When two global variables with appending linkage are
453 linked together, the two global arrays are appended together. This is the
454 LLVM, typesafe, equivalent of having the system linker append together
455 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000456 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000457
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000458 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
459 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
460 until linked, if not linked, the symbol becomes null instead of being an
461 undefined reference.
462 </dd>
463</dl>
464
Chris Lattnerfa730212004-12-09 16:11:40 +0000465 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000466
467 <dd>If none of the above identifiers are used, the global is externally
468 visible, meaning that it participates in linkage and can be used to resolve
469 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000470 </dd>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000471
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000472 <p>
473 The next two types of linkage are targeted for Microsoft Windows platform
474 only. They are designed to support importing (exporting) symbols from (to)
475 DLLs.
476 </p>
477
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000478 <dl>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000479 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
480
481 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
482 or variable via a global pointer to a pointer that is set up by the DLL
483 exporting the symbol. On Microsoft Windows targets, the pointer name is
484 formed by combining <code>_imp__</code> and the function or variable name.
485 </dd>
486
487 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
488
489 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
490 pointer to a pointer in a DLL, so that it can be referenced with the
491 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
492 name is formed by combining <code>_imp__</code> and the function or variable
493 name.
494 </dd>
495
Chris Lattnerfa730212004-12-09 16:11:40 +0000496</dl>
497
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000498<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattnerfa730212004-12-09 16:11:40 +0000499variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
500variable and was linked with this one, one of the two would be renamed,
501preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
502external (i.e., lacking any linkage declarations), they are accessible
Reid Spencerac8d2762007-01-05 00:59:10 +0000503outside of the current module.</p>
504<p>It is illegal for a function <i>declaration</i>
505to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000506or <tt>extern_weak</tt>.</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000507
Chris Lattnerfa730212004-12-09 16:11:40 +0000508</div>
509
510<!-- ======================================================================= -->
511<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000512 <a name="callingconv">Calling Conventions</a>
513</div>
514
515<div class="doc_text">
516
517<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
518and <a href="#i_invoke">invokes</a> can all have an optional calling convention
519specified for the call. The calling convention of any pair of dynamic
520caller/callee must match, or the behavior of the program is undefined. The
521following calling conventions are supported by LLVM, and more may be added in
522the future:</p>
523
524<dl>
525 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
526
527 <dd>This calling convention (the default if no other calling convention is
528 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000529 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencerc28d2bc2006-12-31 21:30:18 +0000530 prototype and implemented declaration of the function (as does normal C).
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000531 </dd>
532
Chris Lattner5710ce92006-05-19 21:15:36 +0000533 <dt><b>"<tt>csretcc</tt>" - The C struct return calling convention</b>:</dt>
534
535 <dd>This calling convention matches the target C calling conventions, except
536 that functions with this convention are required to take a pointer as their
537 first argument, and the return type of the function must be void. This is
538 used for C functions that return aggregates by-value. In this case, the
539 function has been transformed to take a pointer to the struct as the first
540 argument to the function. For targets where the ABI specifies specific
541 behavior for structure-return calls, the calling convention can be used to
542 distinguish between struct return functions and other functions that take a
543 pointer to a struct as the first argument.
544 </dd>
545
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000546 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
547
548 <dd>This calling convention attempts to make calls as fast as possible
549 (e.g. by passing things in registers). This calling convention allows the
550 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000551 without having to conform to an externally specified ABI. Implementations of
552 this convention should allow arbitrary tail call optimization to be supported.
553 This calling convention does not support varargs and requires the prototype of
554 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000555 </dd>
556
557 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
558
559 <dd>This calling convention attempts to make code in the caller as efficient
560 as possible under the assumption that the call is not commonly executed. As
561 such, these calls often preserve all registers so that the call does not break
562 any live ranges in the caller side. This calling convention does not support
563 varargs and requires the prototype of all callees to exactly match the
564 prototype of the function definition.
565 </dd>
566
Chris Lattnercfe6b372005-05-07 01:46:40 +0000567 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000568
569 <dd>Any calling convention may be specified by number, allowing
570 target-specific calling conventions to be used. Target specific calling
571 conventions start at 64.
572 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000573</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000574
575<p>More calling conventions can be added/defined on an as-needed basis, to
576support pascal conventions or any other well-known target-independent
577convention.</p>
578
579</div>
580
581<!-- ======================================================================= -->
582<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000583 <a name="globalvars">Global Variables</a>
584</div>
585
586<div class="doc_text">
587
Chris Lattner3689a342005-02-12 19:30:21 +0000588<p>Global variables define regions of memory allocated at compilation time
Chris Lattner88f6c462005-11-12 00:45:07 +0000589instead of run-time. Global variables may optionally be initialized, may have
590an explicit section to be placed in, and may
Chris Lattner2cbdc452005-11-06 08:02:57 +0000591have an optional explicit alignment specified. A
John Criswell0ec250c2005-10-24 16:17:18 +0000592variable may be defined as a global "constant," which indicates that the
Chris Lattner3689a342005-02-12 19:30:21 +0000593contents of the variable will <b>never</b> be modified (enabling better
594optimization, allowing the global data to be placed in the read-only section of
595an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000596cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000597
598<p>
599LLVM explicitly allows <em>declarations</em> of global variables to be marked
600constant, even if the final definition of the global is not. This capability
601can be used to enable slightly better optimization of the program, but requires
602the language definition to guarantee that optimizations based on the
603'constantness' are valid for the translation units that do not include the
604definition.
605</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000606
607<p>As SSA values, global variables define pointer values that are in
608scope (i.e. they dominate) all basic blocks in the program. Global
609variables always define a pointer to their "content" type because they
610describe a region of memory, and all memory objects in LLVM are
611accessed through pointers.</p>
612
Chris Lattner88f6c462005-11-12 00:45:07 +0000613<p>LLVM allows an explicit section to be specified for globals. If the target
614supports it, it will emit globals to the section specified.</p>
615
Chris Lattner2cbdc452005-11-06 08:02:57 +0000616<p>An explicit alignment may be specified for a global. If not present, or if
617the alignment is set to zero, the alignment of the global is set by the target
618to whatever it feels convenient. If an explicit alignment is specified, the
619global is forced to have at least that much alignment. All alignments must be
620a power of 2.</p>
621
Chris Lattner68027ea2007-01-14 00:27:09 +0000622<p>For example, the following defines a global with an initializer, section,
623 and alignment:</p>
624
625<pre>
626 %G = constant float 1.0, section "foo", align 4
627</pre>
628
Chris Lattnerfa730212004-12-09 16:11:40 +0000629</div>
630
631
632<!-- ======================================================================= -->
633<div class="doc_subsection">
634 <a name="functionstructure">Functions</a>
635</div>
636
637<div class="doc_text">
638
Reid Spencerca86e162006-12-31 07:07:53 +0000639<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
640an optional <a href="#linkage">linkage type</a>, an optional
641<a href="#callingconv">calling convention</a>, a return type, an optional
642<a href="#paramattrs">parameter attribute</a> for the return type, a function
643name, a (possibly empty) argument list (each with optional
Reid Spencer92f82302006-12-31 07:18:34 +0000644<a href="#paramattrs">parameter attributes</a>), an optional section, an
645optional alignment, an opening curly brace, a list of basic blocks, and a
646closing curly brace. LLVM function declarations
647consist of the "<tt>declare</tt>" keyword, an optional <a
Reid Spencerca86e162006-12-31 07:07:53 +0000648 href="#callingconv">calling convention</a>, a return type, an optional
649<a href="#paramattrs">parameter attribute</a> for the return type, a function
650name, a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000651
652<p>A function definition contains a list of basic blocks, forming the CFG for
653the function. Each basic block may optionally start with a label (giving the
654basic block a symbol table entry), contains a list of instructions, and ends
655with a <a href="#terminators">terminator</a> instruction (such as a branch or
656function return).</p>
657
John Criswelle4c57cc2005-05-12 16:52:32 +0000658<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000659executed on entrance to the function, and it is not allowed to have predecessor
660basic blocks (i.e. there can not be any branches to the entry block of a
661function). Because the block can have no predecessors, it also cannot have any
662<a href="#i_phi">PHI nodes</a>.</p>
663
664<p>LLVM functions are identified by their name and type signature. Hence, two
665functions with the same name but different parameter lists or return values are
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000666considered different functions, and LLVM will resolve references to each
Chris Lattnerfa730212004-12-09 16:11:40 +0000667appropriately.</p>
668
Chris Lattner88f6c462005-11-12 00:45:07 +0000669<p>LLVM allows an explicit section to be specified for functions. If the target
670supports it, it will emit functions to the section specified.</p>
671
Chris Lattner2cbdc452005-11-06 08:02:57 +0000672<p>An explicit alignment may be specified for a function. If not present, or if
673the alignment is set to zero, the alignment of the function is set by the target
674to whatever it feels convenient. If an explicit alignment is specified, the
675function is forced to have at least that much alignment. All alignments must be
676a power of 2.</p>
677
Chris Lattnerfa730212004-12-09 16:11:40 +0000678</div>
679
Chris Lattner4e9aba72006-01-23 23:23:47 +0000680<!-- ======================================================================= -->
Reid Spencerca86e162006-12-31 07:07:53 +0000681<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
682<div class="doc_text">
683 <p>The return type and each parameter of a function type may have a set of
684 <i>parameter attributes</i> associated with them. Parameter attributes are
685 used to communicate additional information about the result or parameters of
686 a function. Parameter attributes are considered to be part of the function
687 type so two functions types that differ only by the parameter attributes
688 are different function types.</p>
689
Reid Spencer92f82302006-12-31 07:18:34 +0000690 <p>Parameter attributes consist of an at sign (@) followed by either a single
Reid Spencerca86e162006-12-31 07:07:53 +0000691 keyword or a comma separate list of keywords enclosed in parentheses. For
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000692 example:</p><pre>
Reid Spencerca86e162006-12-31 07:07:53 +0000693 %someFunc = i16 @zext (i8 @(sext) %someParam)
Reid Spencer92f82302006-12-31 07:18:34 +0000694 %someFunc = i16 @zext (i8 @zext %someParam)</pre>
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000695 <p>Note that the two function types above are unique because the parameter has
696 a different attribute (@sext in the first one, @zext in the second).</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000697
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000698 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000699 <dl>
700 <dt><tt>@zext</tt></dt>
701 <dd>This indicates that the parameter should be zero extended just before
702 a call to this function.</dd>
703 <dt><tt>@sext</tt></dt>
704 <dd>This indicates that the parameter should be sign extended just before
705 a call to this function.</dd>
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000706 </dl>
Reid Spencerca86e162006-12-31 07:07:53 +0000707
708 <p>The current motivation for parameter attributes is to enable the sign and
709 zero extend information necessary for the C calling convention to be passed
710 from the front end to LLVM. The <tt>@zext</tt> and <tt>@sext</tt> attributes
711 are used by the code generator to perform the required extension. However,
712 parameter attributes are an orthogonal feature to calling conventions and
713 may be used for other purposes in the future.</p>
714</div>
715
716<!-- ======================================================================= -->
Chris Lattner4e9aba72006-01-23 23:23:47 +0000717<div class="doc_subsection">
Chris Lattner1eeeb0c2006-04-08 04:40:53 +0000718 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner4e9aba72006-01-23 23:23:47 +0000719</div>
720
721<div class="doc_text">
722<p>
723Modules may contain "module-level inline asm" blocks, which corresponds to the
724GCC "file scope inline asm" blocks. These blocks are internally concatenated by
725LLVM and treated as a single unit, but may be separated in the .ll file if
726desired. The syntax is very simple:
727</p>
728
729<div class="doc_code"><pre>
Chris Lattner52599e12006-01-24 00:37:20 +0000730 module asm "inline asm code goes here"
731 module asm "more can go here"
Chris Lattner4e9aba72006-01-23 23:23:47 +0000732</pre></div>
733
734<p>The strings can contain any character by escaping non-printable characters.
735 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
736 for the number.
737</p>
738
739<p>
740 The inline asm code is simply printed to the machine code .s file when
741 assembly code is generated.
742</p>
743</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000744
745
Chris Lattner00950542001-06-06 20:29:01 +0000746<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000747<div class="doc_section"> <a name="typesystem">Type System</a> </div>
748<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000749
Misha Brukman9d0919f2003-11-08 01:05:38 +0000750<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000751
Misha Brukman9d0919f2003-11-08 01:05:38 +0000752<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000753intermediate representation. Being typed enables a number of
754optimizations to be performed on the IR directly, without having to do
755extra analyses on the side before the transformation. A strong type
756system makes it easier to read the generated code and enables novel
757analyses and transformations that are not feasible to perform on normal
758three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000759
760</div>
761
Chris Lattner00950542001-06-06 20:29:01 +0000762<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000763<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000764<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000765<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000766system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000767
Reid Spencerd3f876c2004-11-01 08:19:36 +0000768<table class="layout">
769 <tr class="layout">
770 <td class="left">
771 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000772 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000773 <tr><th>Type</th><th>Description</th></tr>
774 <tr><td><tt>void</tt></td><td>No value</td></tr>
Reid Spencerca86e162006-12-31 07:07:53 +0000775 <tr><td><tt>i8</tt></td><td>Signless 8-bit value</td></tr>
776 <tr><td><tt>i32</tt></td><td>Signless 32-bit value</td></tr>
Misha Brukmancfa87bc2005-04-22 18:02:52 +0000777 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000778 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000779 </tbody>
780 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000781 </td>
782 <td class="right">
783 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000784 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000785 <tr><th>Type</th><th>Description</th></tr>
Reid Spencerc78f3372007-01-12 03:35:51 +0000786 <tr><td><tt>i1</tt></td><td>True or False value</td></tr>
Reid Spencerca86e162006-12-31 07:07:53 +0000787 <tr><td><tt>i16</tt></td><td>Signless 16-bit value</td></tr>
788 <tr><td><tt>i64</tt></td><td>Signless 64-bit value</td></tr>
789 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000790 </tbody>
791 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000792 </td>
793 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000794</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000795</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000796
Chris Lattner00950542001-06-06 20:29:01 +0000797<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000798<div class="doc_subsubsection"> <a name="t_classifications">Type
799Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000800<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000801<p>These different primitive types fall into a few useful
802classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000803
804<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000805 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000806 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000807 <tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000808 <td><a name="t_integer">integer</a></td>
Reid Spencerca86e162006-12-31 07:07:53 +0000809 <td><tt>i8, i16, i32, i64</tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000810 </tr>
811 <tr>
812 <td><a name="t_integral">integral</a></td>
Reid Spencerc78f3372007-01-12 03:35:51 +0000813 <td><tt>i1, i8, i16, i32, i64</tt>
Misha Brukmanc24b7582004-08-12 20:16:08 +0000814 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000815 </tr>
816 <tr>
817 <td><a name="t_floating">floating point</a></td>
818 <td><tt>float, double</tt></td>
819 </tr>
820 <tr>
821 <td><a name="t_firstclass">first class</a></td>
Reid Spencerc78f3372007-01-12 03:35:51 +0000822 <td><tt>i1, i8, i16, i32, i64, float, double, <br/>
Reid Spencerca86e162006-12-31 07:07:53 +0000823 <a href="#t_pointer">pointer</a>,<a href="#t_packed">packed</a></tt>
824 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000825 </tr>
826 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000827</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000828
Chris Lattner261efe92003-11-25 01:02:51 +0000829<p>The <a href="#t_firstclass">first class</a> types are perhaps the
830most important. Values of these types are the only ones which can be
831produced by instructions, passed as arguments, or used as operands to
832instructions. This means that all structures and arrays must be
833manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000834</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000835
Chris Lattner00950542001-06-06 20:29:01 +0000836<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000837<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000838
Misha Brukman9d0919f2003-11-08 01:05:38 +0000839<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000840
Chris Lattner261efe92003-11-25 01:02:51 +0000841<p>The real power in LLVM comes from the derived types in the system.
842This is what allows a programmer to represent arrays, functions,
843pointers, and other useful types. Note that these derived types may be
844recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000845
Misha Brukman9d0919f2003-11-08 01:05:38 +0000846</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000847
Chris Lattner00950542001-06-06 20:29:01 +0000848<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000849<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000850
Misha Brukman9d0919f2003-11-08 01:05:38 +0000851<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +0000852
Chris Lattner00950542001-06-06 20:29:01 +0000853<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000854
Misha Brukman9d0919f2003-11-08 01:05:38 +0000855<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +0000856sequentially in memory. The array type requires a size (number of
857elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000858
Chris Lattner7faa8832002-04-14 06:13:44 +0000859<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000860
861<pre>
862 [&lt;# elements&gt; x &lt;elementtype&gt;]
863</pre>
864
John Criswelle4c57cc2005-05-12 16:52:32 +0000865<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +0000866be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +0000867
Chris Lattner7faa8832002-04-14 06:13:44 +0000868<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000869<table class="layout">
870 <tr class="layout">
871 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +0000872 <tt>[40 x i32 ]</tt><br/>
873 <tt>[41 x i32 ]</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +0000874 <tt>[40 x i8]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000875 </td>
876 <td class="left">
Reid Spencera5173382007-01-04 16:43:23 +0000877 Array of 40 32-bit integer values.<br/>
878 Array of 41 32-bit integer values.<br/>
879 Array of 40 8-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000880 </td>
881 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000882</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000883<p>Here are some examples of multidimensional arrays:</p>
884<table class="layout">
885 <tr class="layout">
886 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +0000887 <tt>[3 x [4 x i32]]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000888 <tt>[12 x [10 x float]]</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +0000889 <tt>[2 x [3 x [4 x i16]]]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000890 </td>
891 <td class="left">
Reid Spencera5173382007-01-04 16:43:23 +0000892 3x4 array of 32-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000893 12x10 array of single precision floating point values.<br/>
Reid Spencera5173382007-01-04 16:43:23 +0000894 2x3x4 array of 16-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000895 </td>
896 </tr>
897</table>
Chris Lattnere67a9512005-06-24 17:22:57 +0000898
John Criswell0ec250c2005-10-24 16:17:18 +0000899<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
900length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +0000901LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
902As a special case, however, zero length arrays are recognized to be variable
903length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerca86e162006-12-31 07:07:53 +0000904type "{ i32, [0 x float]}", for example.</p>
Chris Lattnere67a9512005-06-24 17:22:57 +0000905
Misha Brukman9d0919f2003-11-08 01:05:38 +0000906</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000907
Chris Lattner00950542001-06-06 20:29:01 +0000908<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000909<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000910<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000911<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000912<p>The function type can be thought of as a function signature. It
913consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +0000914Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +0000915(which are structures of pointers to functions), for indirect function
916calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +0000917<p>
918The return type of a function type cannot be an aggregate type.
919</p>
Chris Lattner00950542001-06-06 20:29:01 +0000920<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000921<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell0ec250c2005-10-24 16:17:18 +0000922<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +0000923specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +0000924which indicates that the function takes a variable number of arguments.
925Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +0000926 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000927<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000928<table class="layout">
929 <tr class="layout">
Reid Spencer92f82302006-12-31 07:18:34 +0000930 <td class="left"><tt>i32 (i32)</tt></td>
931 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000932 </td>
Reid Spencer92f82302006-12-31 07:18:34 +0000933 </tr><tr class="layout">
Reid Spencerf17a0b72006-12-31 07:20:23 +0000934 <td class="left"><tt>float&nbsp;(i16&nbsp;@sext,&nbsp;i32&nbsp;*)&nbsp;*
935 </tt></td>
Reid Spencer92f82302006-12-31 07:18:34 +0000936 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
937 an <tt>i16</tt> that should be sign extended and a
Reid Spencerca86e162006-12-31 07:07:53 +0000938 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer92f82302006-12-31 07:18:34 +0000939 <tt>float</tt>.
940 </td>
941 </tr><tr class="layout">
942 <td class="left"><tt>i32 (i8*, ...)</tt></td>
943 <td class="left">A vararg function that takes at least one
Reid Spencera5173382007-01-04 16:43:23 +0000944 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer92f82302006-12-31 07:18:34 +0000945 which returns an integer. This is the signature for <tt>printf</tt> in
946 LLVM.
Reid Spencerd3f876c2004-11-01 08:19:36 +0000947 </td>
948 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000949</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000950
Misha Brukman9d0919f2003-11-08 01:05:38 +0000951</div>
Chris Lattner00950542001-06-06 20:29:01 +0000952<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000953<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000954<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +0000955<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000956<p>The structure type is used to represent a collection of data members
957together in memory. The packing of the field types is defined to match
958the ABI of the underlying processor. The elements of a structure may
959be any type that has a size.</p>
960<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
961and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
962field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
963instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +0000964<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +0000965<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +0000966<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000967<table class="layout">
968 <tr class="layout">
969 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +0000970 <tt>{ i32, i32, i32 }</tt><br/>
971 <tt>{ float, i32 (i32) * }</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000972 </td>
973 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +0000974 a triple of three <tt>i32</tt> values<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000975 A pair, where the first element is a <tt>float</tt> and the second element
976 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
Reid Spencerca86e162006-12-31 07:07:53 +0000977 that takes an <tt>i32</tt>, returning an <tt>i32</tt>.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000978 </td>
979 </tr>
Chris Lattner00950542001-06-06 20:29:01 +0000980</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000981</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000982
Chris Lattner00950542001-06-06 20:29:01 +0000983<!-- _______________________________________________________________________ -->
Andrew Lenharth75e10682006-12-08 17:13:00 +0000984<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
985</div>
986<div class="doc_text">
987<h5>Overview:</h5>
988<p>The packed structure type is used to represent a collection of data members
989together in memory. There is no padding between fields. Further, the alignment
990of a packed structure is 1 byte. The elements of a packed structure may
991be any type that has a size.</p>
992<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
993and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
994field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
995instruction.</p>
996<h5>Syntax:</h5>
997<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
998<h5>Examples:</h5>
999<table class="layout">
1000 <tr class="layout">
1001 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001002 <tt> &lt; { i32, i32, i32 } &gt; </tt><br/>
1003 <tt> &lt; { float, i32 (i32) * } &gt; </tt><br/>
Andrew Lenharth75e10682006-12-08 17:13:00 +00001004 </td>
1005 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001006 a triple of three <tt>i32</tt> values<br/>
Andrew Lenharth75e10682006-12-08 17:13:00 +00001007 A pair, where the first element is a <tt>float</tt> and the second element
1008 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
Reid Spencerca86e162006-12-31 07:07:53 +00001009 that takes an <tt>i32</tt>, returning an <tt>i32</tt>.<br/>
Andrew Lenharth75e10682006-12-08 17:13:00 +00001010 </td>
1011 </tr>
1012</table>
1013</div>
1014
1015<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001016<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001017<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001018<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001019<p>As in many languages, the pointer type represents a pointer or
1020reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001021<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001022<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001023<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001024<table class="layout">
1025 <tr class="layout">
1026 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001027 <tt>[4x i32]*</tt><br/>
1028 <tt>i32 (i32 *) *</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001029 </td>
1030 <td class="left">
1031 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
Reid Spencerca86e162006-12-31 07:07:53 +00001032 four <tt>i32</tt> values<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001033 A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerca86e162006-12-31 07:07:53 +00001034 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
1035 <tt>i32</tt>.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001036 </td>
1037 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001038</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001039</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001040
Chris Lattnera58561b2004-08-12 19:12:28 +00001041<!-- _______________________________________________________________________ -->
1042<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001043<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +00001044
Chris Lattnera58561b2004-08-12 19:12:28 +00001045<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001046
Chris Lattnera58561b2004-08-12 19:12:28 +00001047<p>A packed type is a simple derived type that represents a vector
1048of elements. Packed types are used when multiple primitive data
1049are operated in parallel using a single instruction (SIMD).
1050A packed type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +00001051elements) and an underlying primitive data type. Vectors must have a power
1052of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnera58561b2004-08-12 19:12:28 +00001053considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001054
Chris Lattnera58561b2004-08-12 19:12:28 +00001055<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001056
1057<pre>
1058 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1059</pre>
1060
John Criswellc1f786c2005-05-13 22:25:59 +00001061<p>The number of elements is a constant integer value; elementtype may
Chris Lattnera58561b2004-08-12 19:12:28 +00001062be any integral or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001063
Chris Lattnera58561b2004-08-12 19:12:28 +00001064<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001065
Reid Spencerd3f876c2004-11-01 08:19:36 +00001066<table class="layout">
1067 <tr class="layout">
1068 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001069 <tt>&lt;4 x i32&gt;</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001070 <tt>&lt;8 x float&gt;</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +00001071 <tt>&lt;2 x i64&gt;</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001072 </td>
1073 <td class="left">
Reid Spencera5173382007-01-04 16:43:23 +00001074 Packed vector of 4 32-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001075 Packed vector of 8 floating-point values.<br/>
Reid Spencera5173382007-01-04 16:43:23 +00001076 Packed vector of 2 64-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001077 </td>
1078 </tr>
1079</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001080</div>
1081
Chris Lattner69c11bb2005-04-25 17:34:15 +00001082<!-- _______________________________________________________________________ -->
1083<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1084<div class="doc_text">
1085
1086<h5>Overview:</h5>
1087
1088<p>Opaque types are used to represent unknown types in the system. This
1089corresponds (for example) to the C notion of a foward declared structure type.
1090In LLVM, opaque types can eventually be resolved to any type (not just a
1091structure type).</p>
1092
1093<h5>Syntax:</h5>
1094
1095<pre>
1096 opaque
1097</pre>
1098
1099<h5>Examples:</h5>
1100
1101<table class="layout">
1102 <tr class="layout">
1103 <td class="left">
1104 <tt>opaque</tt>
1105 </td>
1106 <td class="left">
1107 An opaque type.<br/>
1108 </td>
1109 </tr>
1110</table>
1111</div>
1112
1113
Chris Lattnerc3f59762004-12-09 17:30:23 +00001114<!-- *********************************************************************** -->
1115<div class="doc_section"> <a name="constants">Constants</a> </div>
1116<!-- *********************************************************************** -->
1117
1118<div class="doc_text">
1119
1120<p>LLVM has several different basic types of constants. This section describes
1121them all and their syntax.</p>
1122
1123</div>
1124
1125<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +00001126<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001127
1128<div class="doc_text">
1129
1130<dl>
1131 <dt><b>Boolean constants</b></dt>
1132
1133 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencerc78f3372007-01-12 03:35:51 +00001134 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattnerc3f59762004-12-09 17:30:23 +00001135 </dd>
1136
1137 <dt><b>Integer constants</b></dt>
1138
Reid Spencercc16dc32004-12-09 18:02:53 +00001139 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencera5173382007-01-04 16:43:23 +00001140 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattnerc3f59762004-12-09 17:30:23 +00001141 integer types.
1142 </dd>
1143
1144 <dt><b>Floating point constants</b></dt>
1145
1146 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1147 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +00001148 notation (see below). Floating point constants must have a <a
1149 href="#t_floating">floating point</a> type. </dd>
1150
1151 <dt><b>Null pointer constants</b></dt>
1152
John Criswell9e2485c2004-12-10 15:51:16 +00001153 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +00001154 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1155
1156</dl>
1157
John Criswell9e2485c2004-12-10 15:51:16 +00001158<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +00001159of floating point constants. For example, the form '<tt>double
11600x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
11614.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +00001162(and the only time that they are generated by the disassembler) is when a
1163floating point constant must be emitted but it cannot be represented as a
1164decimal floating point number. For example, NaN's, infinities, and other
1165special values are represented in their IEEE hexadecimal format so that
1166assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001167
1168</div>
1169
1170<!-- ======================================================================= -->
1171<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1172</div>
1173
1174<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001175<p>Aggregate constants arise from aggregation of simple constants
1176and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001177
1178<dl>
1179 <dt><b>Structure constants</b></dt>
1180
1181 <dd>Structure constants are represented with notation similar to structure
1182 type definitions (a comma separated list of elements, surrounded by braces
Reid Spencerca86e162006-12-31 07:07:53 +00001183 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* %G }</tt>",
1184 where "<tt>%G</tt>" is declared as "<tt>%G = external global i32</tt>". Structure constants
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001185 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +00001186 types of elements must match those specified by the type.
1187 </dd>
1188
1189 <dt><b>Array constants</b></dt>
1190
1191 <dd>Array constants are represented with notation similar to array type
1192 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerca86e162006-12-31 07:07:53 +00001193 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +00001194 constants must have <a href="#t_array">array type</a>, and the number and
1195 types of elements must match those specified by the type.
1196 </dd>
1197
1198 <dt><b>Packed constants</b></dt>
1199
1200 <dd>Packed constants are represented with notation similar to packed type
1201 definitions (a comma separated list of elements, surrounded by
Reid Spencerca86e162006-12-31 07:07:53 +00001202 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
1203 i32 11, i32 74, i32 100 &gt;</tt>". Packed constants must have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001204 href="#t_packed">packed type</a>, and the number and types of elements must
1205 match those specified by the type.
1206 </dd>
1207
1208 <dt><b>Zero initialization</b></dt>
1209
1210 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1211 value to zero of <em>any</em> type, including scalar and aggregate types.
1212 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001213 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001214 initializers.
1215 </dd>
1216</dl>
1217
1218</div>
1219
1220<!-- ======================================================================= -->
1221<div class="doc_subsection">
1222 <a name="globalconstants">Global Variable and Function Addresses</a>
1223</div>
1224
1225<div class="doc_text">
1226
1227<p>The addresses of <a href="#globalvars">global variables</a> and <a
1228href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001229constants. These constants are explicitly referenced when the <a
1230href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001231href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1232file:</p>
1233
1234<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00001235 %X = global i32 17
1236 %Y = global i32 42
1237 %Z = global [2 x i32*] [ i32* %X, i32* %Y ]
Chris Lattnerc3f59762004-12-09 17:30:23 +00001238</pre>
1239
1240</div>
1241
1242<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001243<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001244<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001245 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001246 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001247 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001248
Reid Spencer2dc45b82004-12-09 18:13:12 +00001249 <p>Undefined values indicate to the compiler that the program is well defined
1250 no matter what value is used, giving the compiler more freedom to optimize.
1251 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001252</div>
1253
1254<!-- ======================================================================= -->
1255<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1256</div>
1257
1258<div class="doc_text">
1259
1260<p>Constant expressions are used to allow expressions involving other constants
1261to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001262href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001263that does not have side effects (e.g. load and call are not supported). The
1264following is the syntax for constant expressions:</p>
1265
1266<dl>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001267 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1268 <dd>Truncate a constant to another type. The bit size of CST must be larger
1269 than the bit size of TYPE. Both types must be integral.</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001270
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001271 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1272 <dd>Zero extend a constant to another type. The bit size of CST must be
1273 smaller or equal to the bit size of TYPE. Both types must be integral.</dd>
1274
1275 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1276 <dd>Sign extend a constant to another type. The bit size of CST must be
1277 smaller or equal to the bit size of TYPE. Both types must be integral.</dd>
1278
1279 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1280 <dd>Truncate a floating point constant to another floating point type. The
1281 size of CST must be larger than the size of TYPE. Both types must be
1282 floating point.</dd>
1283
1284 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1285 <dd>Floating point extend a constant to another type. The size of CST must be
1286 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1287
1288 <dt><b><tt>fp2uint ( CST to TYPE )</tt></b></dt>
1289 <dd>Convert a floating point constant to the corresponding unsigned integer
1290 constant. TYPE must be an integer type. CST must be floating point. If the
1291 value won't fit in the integer type, the results are undefined.</dd>
1292
Reid Spencerd4448792006-11-09 23:03:26 +00001293 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001294 <dd>Convert a floating point constant to the corresponding signed integer
1295 constant. TYPE must be an integer type. CST must be floating point. If the
1296 value won't fit in the integer type, the results are undefined.</dd>
1297
Reid Spencerd4448792006-11-09 23:03:26 +00001298 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001299 <dd>Convert an unsigned integer constant to the corresponding floating point
1300 constant. TYPE must be floating point. CST must be of integer type. If the
1301 value won't fit in the floating point type, the results are undefined.</dd>
1302
Reid Spencerd4448792006-11-09 23:03:26 +00001303 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001304 <dd>Convert a signed integer constant to the corresponding floating point
1305 constant. TYPE must be floating point. CST must be of integer type. If the
1306 value won't fit in the floating point type, the results are undefined.</dd>
1307
Reid Spencer5c0ef472006-11-11 23:08:07 +00001308 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1309 <dd>Convert a pointer typed constant to the corresponding integer constant
1310 TYPE must be an integer type. CST must be of pointer type. The CST value is
1311 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1312
1313 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1314 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1315 pointer type. CST must be of integer type. The CST value is zero extended,
1316 truncated, or unchanged to make it fit in a pointer size. This one is
1317 <i>really</i> dangerous!</dd>
1318
1319 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001320 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1321 identical (same number of bits). The conversion is done as if the CST value
1322 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5c0ef472006-11-11 23:08:07 +00001323 with this operator, just the type. This can be used for conversion of
1324 packed types to any other type, as long as they have the same bit width. For
1325 pointers it is only valid to cast to another pointer type.
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001326 </dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001327
1328 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1329
1330 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1331 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1332 instruction, the index list may have zero or more indexes, which are required
1333 to make sense for the type of "CSTPTR".</dd>
1334
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001335 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1336
1337 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer01c42592006-12-04 19:23:19 +00001338 constants.</dd>
1339
1340 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1341 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1342
1343 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1344 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001345
1346 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1347
1348 <dd>Perform the <a href="#i_extractelement">extractelement
1349 operation</a> on constants.
1350
Robert Bocchino05ccd702006-01-15 20:48:27 +00001351 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1352
1353 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer01c42592006-12-04 19:23:19 +00001354 operation</a> on constants.</dd>
Robert Bocchino05ccd702006-01-15 20:48:27 +00001355
Chris Lattnerc1989542006-04-08 00:13:41 +00001356
1357 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1358
1359 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer01c42592006-12-04 19:23:19 +00001360 operation</a> on constants.</dd>
Chris Lattnerc1989542006-04-08 00:13:41 +00001361
Chris Lattnerc3f59762004-12-09 17:30:23 +00001362 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1363
Reid Spencer2dc45b82004-12-09 18:13:12 +00001364 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1365 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001366 binary</a> operations. The constraints on operands are the same as those for
1367 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001368 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001369</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001370</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001371
Chris Lattner00950542001-06-06 20:29:01 +00001372<!-- *********************************************************************** -->
Chris Lattnere87d6532006-01-25 23:47:57 +00001373<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1374<!-- *********************************************************************** -->
1375
1376<!-- ======================================================================= -->
1377<div class="doc_subsection">
1378<a name="inlineasm">Inline Assembler Expressions</a>
1379</div>
1380
1381<div class="doc_text">
1382
1383<p>
1384LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1385Module-Level Inline Assembly</a>) through the use of a special value. This
1386value represents the inline assembler as a string (containing the instructions
1387to emit), a list of operand constraints (stored as a string), and a flag that
1388indicates whether or not the inline asm expression has side effects. An example
1389inline assembler expression is:
1390</p>
1391
1392<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00001393 i32 (i32) asm "bswap $0", "=r,r"
Chris Lattnere87d6532006-01-25 23:47:57 +00001394</pre>
1395
1396<p>
1397Inline assembler expressions may <b>only</b> be used as the callee operand of
1398a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1399</p>
1400
1401<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00001402 %X = call i32 asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattnere87d6532006-01-25 23:47:57 +00001403</pre>
1404
1405<p>
1406Inline asms with side effects not visible in the constraint list must be marked
1407as having side effects. This is done through the use of the
1408'<tt>sideeffect</tt>' keyword, like so:
1409</p>
1410
1411<pre>
1412 call void asm sideeffect "eieio", ""()
1413</pre>
1414
1415<p>TODO: The format of the asm and constraints string still need to be
1416documented here. Constraints on what can be done (e.g. duplication, moving, etc
1417need to be documented).
1418</p>
1419
1420</div>
1421
1422<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001423<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1424<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001425
Misha Brukman9d0919f2003-11-08 01:05:38 +00001426<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001427
Chris Lattner261efe92003-11-25 01:02:51 +00001428<p>The LLVM instruction set consists of several different
1429classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001430instructions</a>, <a href="#binaryops">binary instructions</a>,
1431<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001432 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1433instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001434
Misha Brukman9d0919f2003-11-08 01:05:38 +00001435</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001436
Chris Lattner00950542001-06-06 20:29:01 +00001437<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001438<div class="doc_subsection"> <a name="terminators">Terminator
1439Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001440
Misha Brukman9d0919f2003-11-08 01:05:38 +00001441<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001442
Chris Lattner261efe92003-11-25 01:02:51 +00001443<p>As mentioned <a href="#functionstructure">previously</a>, every
1444basic block in a program ends with a "Terminator" instruction, which
1445indicates which block should be executed after the current block is
1446finished. These terminator instructions typically yield a '<tt>void</tt>'
1447value: they produce control flow, not values (the one exception being
1448the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001449<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001450 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1451instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001452the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1453 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1454 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001455
Misha Brukman9d0919f2003-11-08 01:05:38 +00001456</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001457
Chris Lattner00950542001-06-06 20:29:01 +00001458<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001459<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1460Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001461<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001462<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001463<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001464 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001465</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001466<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001467<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001468value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001469<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001470returns a value and then causes control flow, and one that just causes
1471control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001472<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001473<p>The '<tt>ret</tt>' instruction may return any '<a
1474 href="#t_firstclass">first class</a>' type. Notice that a function is
1475not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1476instruction inside of the function that returns a value that does not
1477match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001478<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001479<p>When the '<tt>ret</tt>' instruction is executed, control flow
1480returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001481 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001482the instruction after the call. If the caller was an "<a
1483 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001484at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001485returns a value, that value shall set the call or invoke instruction's
1486return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001487<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001488<pre> ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001489 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001490</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001491</div>
Chris Lattner00950542001-06-06 20:29:01 +00001492<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001493<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001494<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001495<h5>Syntax:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001496<pre> br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +00001497</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001498<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001499<p>The '<tt>br</tt>' instruction is used to cause control flow to
1500transfer to a different basic block in the current function. There are
1501two forms of this instruction, corresponding to a conditional branch
1502and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001503<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001504<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencerc78f3372007-01-12 03:35:51 +00001505single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Chris Lattner261efe92003-11-25 01:02:51 +00001506unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1507value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001508<h5>Semantics:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001509<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001510argument is evaluated. If the value is <tt>true</tt>, control flows
1511to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1512control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001513<h5>Example:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001514<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq, i32 %a, %b<br> br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Reid Spencerca86e162006-12-31 07:07:53 +00001515 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001516</div>
Chris Lattner00950542001-06-06 20:29:01 +00001517<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001518<div class="doc_subsubsection">
1519 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1520</div>
1521
Misha Brukman9d0919f2003-11-08 01:05:38 +00001522<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001523<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001524
1525<pre>
1526 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1527</pre>
1528
Chris Lattner00950542001-06-06 20:29:01 +00001529<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001530
1531<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1532several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001533instruction, allowing a branch to occur to one of many possible
1534destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001535
1536
Chris Lattner00950542001-06-06 20:29:01 +00001537<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001538
1539<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1540comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1541an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1542table is not allowed to contain duplicate constant entries.</p>
1543
Chris Lattner00950542001-06-06 20:29:01 +00001544<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001545
Chris Lattner261efe92003-11-25 01:02:51 +00001546<p>The <tt>switch</tt> instruction specifies a table of values and
1547destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001548table is searched for the given value. If the value is found, control flow is
1549transfered to the corresponding destination; otherwise, control flow is
1550transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001551
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001552<h5>Implementation:</h5>
1553
1554<p>Depending on properties of the target machine and the particular
1555<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001556ways. For example, it could be generated as a series of chained conditional
1557branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001558
1559<h5>Example:</h5>
1560
1561<pre>
1562 <i>; Emulate a conditional br instruction</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00001563 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerca86e162006-12-31 07:07:53 +00001564 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001565
1566 <i>; Emulate an unconditional br instruction</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001567 switch i32 0, label %dest [ ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001568
1569 <i>; Implement a jump table:</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001570 switch i32 %val, label %otherwise [ i32 0, label %onzero
1571 i32 1, label %onone
1572 i32 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001573</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001574</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001575
Chris Lattner00950542001-06-06 20:29:01 +00001576<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001577<div class="doc_subsubsection">
1578 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1579</div>
1580
Misha Brukman9d0919f2003-11-08 01:05:38 +00001581<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001582
Chris Lattner00950542001-06-06 20:29:01 +00001583<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001584
1585<pre>
1586 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
Chris Lattner76b8a332006-05-14 18:23:06 +00001587 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001588</pre>
1589
Chris Lattner6536cfe2002-05-06 22:08:29 +00001590<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001591
1592<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1593function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001594'<tt>normal</tt>' label or the
1595'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001596"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1597"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001598href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1599continued at the dynamically nearest "exception" label.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001600
Chris Lattner00950542001-06-06 20:29:01 +00001601<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001602
Misha Brukman9d0919f2003-11-08 01:05:38 +00001603<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001604
Chris Lattner00950542001-06-06 20:29:01 +00001605<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001606 <li>
John Criswellc1f786c2005-05-13 22:25:59 +00001607 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001608 convention</a> the call should use. If none is specified, the call defaults
1609 to using C calling conventions.
1610 </li>
1611 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1612 function value being invoked. In most cases, this is a direct function
1613 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1614 an arbitrary pointer to function value.
1615 </li>
1616
1617 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1618 function to be invoked. </li>
1619
1620 <li>'<tt>function args</tt>': argument list whose types match the function
1621 signature argument types. If the function signature indicates the function
1622 accepts a variable number of arguments, the extra arguments can be
1623 specified. </li>
1624
1625 <li>'<tt>normal label</tt>': the label reached when the called function
1626 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1627
1628 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1629 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1630
Chris Lattner00950542001-06-06 20:29:01 +00001631</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001632
Chris Lattner00950542001-06-06 20:29:01 +00001633<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001634
Misha Brukman9d0919f2003-11-08 01:05:38 +00001635<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001636href="#i_call">call</a></tt>' instruction in most regards. The primary
1637difference is that it establishes an association with a label, which is used by
1638the runtime library to unwind the stack.</p>
1639
1640<p>This instruction is used in languages with destructors to ensure that proper
1641cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1642exception. Additionally, this is important for implementation of
1643'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1644
Chris Lattner00950542001-06-06 20:29:01 +00001645<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001646<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00001647 %retval = invoke i32 %Test(i32 15) to label %Continue
1648 unwind label %TestCleanup <i>; {i32}:retval set</i>
1649 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Test(i32 15) to label %Continue
1650 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00001651</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001652</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001653
1654
Chris Lattner27f71f22003-09-03 00:41:47 +00001655<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001656
Chris Lattner261efe92003-11-25 01:02:51 +00001657<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1658Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001659
Misha Brukman9d0919f2003-11-08 01:05:38 +00001660<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001661
Chris Lattner27f71f22003-09-03 00:41:47 +00001662<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001663<pre>
1664 unwind
1665</pre>
1666
Chris Lattner27f71f22003-09-03 00:41:47 +00001667<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001668
1669<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1670at the first callee in the dynamic call stack which used an <a
1671href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1672primarily used to implement exception handling.</p>
1673
Chris Lattner27f71f22003-09-03 00:41:47 +00001674<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001675
1676<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1677immediately halt. The dynamic call stack is then searched for the first <a
1678href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1679execution continues at the "exceptional" destination block specified by the
1680<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1681dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001682</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001683
1684<!-- _______________________________________________________________________ -->
1685
1686<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1687Instruction</a> </div>
1688
1689<div class="doc_text">
1690
1691<h5>Syntax:</h5>
1692<pre>
1693 unreachable
1694</pre>
1695
1696<h5>Overview:</h5>
1697
1698<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1699instruction is used to inform the optimizer that a particular portion of the
1700code is not reachable. This can be used to indicate that the code after a
1701no-return function cannot be reached, and other facts.</p>
1702
1703<h5>Semantics:</h5>
1704
1705<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1706</div>
1707
1708
1709
Chris Lattner00950542001-06-06 20:29:01 +00001710<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001711<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001712<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001713<p>Binary operators are used to do most of the computation in a
1714program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001715produce a single value. The operands might represent
Chris Lattnera58561b2004-08-12 19:12:28 +00001716multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1717The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001718necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001719<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001720</div>
Chris Lattner00950542001-06-06 20:29:01 +00001721<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001722<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1723Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001724<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001725<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001726<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001727</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001728<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001729<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001730<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001731<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001732 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1733 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1734Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001735<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001736<p>The value produced is the integer or floating point sum of the two
1737operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001738<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001739<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001740</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001741</div>
Chris Lattner00950542001-06-06 20:29:01 +00001742<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001743<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1744Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001745<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001746<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001747<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001748</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001749<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001750<p>The '<tt>sub</tt>' instruction returns the difference of its two
1751operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001752<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1753instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001754<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001755<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001756 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001757values.
1758This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1759Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001760<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001761<p>The value produced is the integer or floating point difference of
1762the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001763<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001764<pre> &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
1765 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001766</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001767</div>
Chris Lattner00950542001-06-06 20:29:01 +00001768<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001769<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1770Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001771<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001772<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001773<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001774</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001775<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001776<p>The '<tt>mul</tt>' instruction returns the product of its two
1777operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001778<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001779<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001780 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001781values.
1782This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1783Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001784<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001785<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00001786two operands.</p>
Reid Spencera5173382007-01-04 16:43:23 +00001787<p>Because the operands are the same width, the result of an integer
1788multiplication is the same whether the operands should be deemed unsigned or
1789signed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001790<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001791<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001792</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001793</div>
Chris Lattner00950542001-06-06 20:29:01 +00001794<!-- _______________________________________________________________________ -->
Reid Spencer1628cec2006-10-26 06:15:43 +00001795<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
1796</a></div>
1797<div class="doc_text">
1798<h5>Syntax:</h5>
1799<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1800</pre>
1801<h5>Overview:</h5>
1802<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
1803operands.</p>
1804<h5>Arguments:</h5>
1805<p>The two arguments to the '<tt>udiv</tt>' instruction must be
1806<a href="#t_integer">integer</a> values. Both arguments must have identical
1807types. This instruction can also take <a href="#t_packed">packed</a> versions
1808of the values in which case the elements must be integers.</p>
1809<h5>Semantics:</h5>
1810<p>The value produced is the unsigned integer quotient of the two operands. This
1811instruction always performs an unsigned division operation, regardless of
1812whether the arguments are unsigned or not.</p>
1813<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001814<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00001815</pre>
1816</div>
1817<!-- _______________________________________________________________________ -->
1818<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
1819</a> </div>
1820<div class="doc_text">
1821<h5>Syntax:</h5>
1822<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1823</pre>
1824<h5>Overview:</h5>
1825<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
1826operands.</p>
1827<h5>Arguments:</h5>
1828<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
1829<a href="#t_integer">integer</a> values. Both arguments must have identical
1830types. This instruction can also take <a href="#t_packed">packed</a> versions
1831of the values in which case the elements must be integers.</p>
1832<h5>Semantics:</h5>
1833<p>The value produced is the signed integer quotient of the two operands. This
1834instruction always performs a signed division operation, regardless of whether
1835the arguments are signed or not.</p>
1836<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001837<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00001838</pre>
1839</div>
1840<!-- _______________________________________________________________________ -->
1841<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001842Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001843<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001844<h5>Syntax:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00001845<pre> &lt;result&gt; = fdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner261efe92003-11-25 01:02:51 +00001846</pre>
1847<h5>Overview:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00001848<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner261efe92003-11-25 01:02:51 +00001849operands.</p>
1850<h5>Arguments:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00001851<p>The two arguments to the '<tt>div</tt>' instruction must be
1852<a href="#t_floating">floating point</a> values. Both arguments must have
1853identical types. This instruction can also take <a href="#t_packed">packed</a>
1854versions of the values in which case the elements must be floating point.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001855<h5>Semantics:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00001856<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001857<h5>Example:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00001858<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00001859</pre>
1860</div>
1861<!-- _______________________________________________________________________ -->
Reid Spencer0a783f72006-11-02 01:53:59 +00001862<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
1863</div>
1864<div class="doc_text">
1865<h5>Syntax:</h5>
1866<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1867</pre>
1868<h5>Overview:</h5>
1869<p>The '<tt>urem</tt>' instruction returns the remainder from the
1870unsigned division of its two arguments.</p>
1871<h5>Arguments:</h5>
1872<p>The two arguments to the '<tt>urem</tt>' instruction must be
1873<a href="#t_integer">integer</a> values. Both arguments must have identical
1874types.</p>
1875<h5>Semantics:</h5>
1876<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
1877This instruction always performs an unsigned division to get the remainder,
1878regardless of whether the arguments are unsigned or not.</p>
1879<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001880<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00001881</pre>
1882
1883</div>
1884<!-- _______________________________________________________________________ -->
1885<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001886Instruction</a> </div>
1887<div class="doc_text">
1888<h5>Syntax:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00001889<pre> &lt;result&gt; = srem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner261efe92003-11-25 01:02:51 +00001890</pre>
1891<h5>Overview:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00001892<p>The '<tt>srem</tt>' instruction returns the remainder from the
1893signed division of its two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001894<h5>Arguments:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00001895<p>The two arguments to the '<tt>srem</tt>' instruction must be
1896<a href="#t_integer">integer</a> values. Both arguments must have identical
1897types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001898<h5>Semantics:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00001899<p>This instruction returns the <i>remainder</i> of a division (where the result
Chris Lattner261efe92003-11-25 01:02:51 +00001900has the same sign as the divisor), not the <i>modulus</i> (where the
1901result has the same sign as the dividend) of a value. For more
John Criswell0ec250c2005-10-24 16:17:18 +00001902information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00001903 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1904Math Forum</a>.</p>
1905<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001906<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00001907</pre>
1908
1909</div>
1910<!-- _______________________________________________________________________ -->
1911<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
1912Instruction</a> </div>
1913<div class="doc_text">
1914<h5>Syntax:</h5>
1915<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1916</pre>
1917<h5>Overview:</h5>
1918<p>The '<tt>frem</tt>' instruction returns the remainder from the
1919division of its two operands.</p>
1920<h5>Arguments:</h5>
1921<p>The two arguments to the '<tt>frem</tt>' instruction must be
1922<a href="#t_floating">floating point</a> values. Both arguments must have
1923identical types.</p>
1924<h5>Semantics:</h5>
1925<p>This instruction returns the <i>remainder</i> of a division.</p>
1926<h5>Example:</h5>
1927<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00001928</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001929</div>
Robert Bocchino7b81c752006-02-17 21:18:08 +00001930
Chris Lattner00950542001-06-06 20:29:01 +00001931<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001932<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1933Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001934<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001935<p>Bitwise binary operators are used to do various forms of
1936bit-twiddling in a program. They are generally very efficient
John Criswell9e2485c2004-12-10 15:51:16 +00001937instructions and can commonly be strength reduced from other
Chris Lattner261efe92003-11-25 01:02:51 +00001938instructions. They require two operands, execute an operation on them,
1939and produce a single value. The resulting value of the bitwise binary
1940operators is always the same type as its first operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001941</div>
Chris Lattner00950542001-06-06 20:29:01 +00001942<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001943<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1944Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001945<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001946<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001947<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001948</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001949<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001950<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1951its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001952<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001953<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00001954 href="#t_integral">integral</a> values. Both arguments must have
1955identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001956<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001957<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001958<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001959<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00001960<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001961 <tbody>
1962 <tr>
1963 <td>In0</td>
1964 <td>In1</td>
1965 <td>Out</td>
1966 </tr>
1967 <tr>
1968 <td>0</td>
1969 <td>0</td>
1970 <td>0</td>
1971 </tr>
1972 <tr>
1973 <td>0</td>
1974 <td>1</td>
1975 <td>0</td>
1976 </tr>
1977 <tr>
1978 <td>1</td>
1979 <td>0</td>
1980 <td>0</td>
1981 </tr>
1982 <tr>
1983 <td>1</td>
1984 <td>1</td>
1985 <td>1</td>
1986 </tr>
1987 </tbody>
1988</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001989</div>
Chris Lattner00950542001-06-06 20:29:01 +00001990<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001991<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
1992 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
1993 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner00950542001-06-06 20:29:01 +00001994</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001995</div>
Chris Lattner00950542001-06-06 20:29:01 +00001996<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001997<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001998<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001999<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002000<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002001</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00002002<h5>Overview:</h5>
2003<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2004or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002005<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002006<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00002007 href="#t_integral">integral</a> values. Both arguments must have
2008identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002009<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002010<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002011<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002012<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002013<table border="1" cellspacing="0" cellpadding="4">
2014 <tbody>
2015 <tr>
2016 <td>In0</td>
2017 <td>In1</td>
2018 <td>Out</td>
2019 </tr>
2020 <tr>
2021 <td>0</td>
2022 <td>0</td>
2023 <td>0</td>
2024 </tr>
2025 <tr>
2026 <td>0</td>
2027 <td>1</td>
2028 <td>1</td>
2029 </tr>
2030 <tr>
2031 <td>1</td>
2032 <td>0</td>
2033 <td>1</td>
2034 </tr>
2035 <tr>
2036 <td>1</td>
2037 <td>1</td>
2038 <td>1</td>
2039 </tr>
2040 </tbody>
2041</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002042</div>
Chris Lattner00950542001-06-06 20:29:01 +00002043<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002044<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2045 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2046 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner00950542001-06-06 20:29:01 +00002047</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002048</div>
Chris Lattner00950542001-06-06 20:29:01 +00002049<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002050<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2051Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002052<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002053<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002054<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002055</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002056<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002057<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2058or of its two operands. The <tt>xor</tt> is used to implement the
2059"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002060<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002061<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner261efe92003-11-25 01:02:51 +00002062 href="#t_integral">integral</a> values. Both arguments must have
2063identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002064<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002065<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002066<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002067<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002068<table border="1" cellspacing="0" cellpadding="4">
2069 <tbody>
2070 <tr>
2071 <td>In0</td>
2072 <td>In1</td>
2073 <td>Out</td>
2074 </tr>
2075 <tr>
2076 <td>0</td>
2077 <td>0</td>
2078 <td>0</td>
2079 </tr>
2080 <tr>
2081 <td>0</td>
2082 <td>1</td>
2083 <td>1</td>
2084 </tr>
2085 <tr>
2086 <td>1</td>
2087 <td>0</td>
2088 <td>1</td>
2089 </tr>
2090 <tr>
2091 <td>1</td>
2092 <td>1</td>
2093 <td>0</td>
2094 </tr>
2095 </tbody>
2096</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002097</div>
Chris Lattner261efe92003-11-25 01:02:51 +00002098<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00002099<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002100<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2101 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2102 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2103 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00002104</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002105</div>
Chris Lattner00950542001-06-06 20:29:01 +00002106<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002107<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2108Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002109<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002110<h5>Syntax:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002111<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, i8 &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002112</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002113<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002114<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2115the left a specified number of bits.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002116<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002117<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Reid Spencerca86e162006-12-31 07:07:53 +00002118 href="#t_integer">integer</a> type. The second argument must be an '<tt>i8</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002119type.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002120<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002121<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002122<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002123<pre> &lt;result&gt; = shl i32 4, i8 %var <i>; yields {i32}:result = 4 &lt;&lt; %var</i>
2124 &lt;result&gt; = shl i32 4, i8 2 <i>; yields {i32}:result = 16</i>
2125 &lt;result&gt; = shl i32 1, i8 10 <i>; yields {i32}:result = 1024</i>
Chris Lattner00950542001-06-06 20:29:01 +00002126</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002127</div>
Chris Lattner00950542001-06-06 20:29:01 +00002128<!-- _______________________________________________________________________ -->
Reid Spencer3822ff52006-11-08 06:47:33 +00002129<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002130Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002131<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002132<h5>Syntax:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002133<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, i8 &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002134</pre>
Reid Spencer3822ff52006-11-08 06:47:33 +00002135
Chris Lattner00950542001-06-06 20:29:01 +00002136<h5>Overview:</h5>
Reid Spencer3822ff52006-11-08 06:47:33 +00002137<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
2138operand shifted to the right a specified number of bits.</p>
2139
Chris Lattner00950542001-06-06 20:29:01 +00002140<h5>Arguments:</h5>
Reid Spencer3822ff52006-11-08 06:47:33 +00002141<p>The first argument to the '<tt>lshr</tt>' instruction must be an <a
Reid Spencerca86e162006-12-31 07:07:53 +00002142 href="#t_integer">integer</a> type. The second argument must be an '<tt>i8</tt>' type.</p>
Reid Spencer3822ff52006-11-08 06:47:33 +00002143
Chris Lattner00950542001-06-06 20:29:01 +00002144<h5>Semantics:</h5>
Reid Spencera5173382007-01-04 16:43:23 +00002145<p>This instruction always performs a logical shift right operation. The
2146<tt>var2</tt> most significant bits will be filled with zero bits after the
2147shift.</p>
Reid Spencer3822ff52006-11-08 06:47:33 +00002148
Chris Lattner00950542001-06-06 20:29:01 +00002149<h5>Example:</h5>
Reid Spencer3822ff52006-11-08 06:47:33 +00002150<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002151 &lt;result&gt; = lshr i32 4, i8 1 <i>; yields {i32}:result = 2</i>
2152 &lt;result&gt; = lshr i32 4, i8 2 <i>; yields {i32}:result = 1</i>
2153 &lt;result&gt; = lshr i8 4, i8 3 <i>; yields {i8 }:result = 0</i>
2154 &lt;result&gt; = lshr i8 -2, i8 1 <i>; yields {i8 }:result = 0x7FFFFFFF </i>
Reid Spencer3822ff52006-11-08 06:47:33 +00002155</pre>
2156</div>
2157
2158<!-- ======================================================================= -->
2159<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2160Instruction</a> </div>
2161<div class="doc_text">
2162
2163<h5>Syntax:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002164<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, i8 &lt;var2&gt; <i>; yields {ty}:result</i>
Reid Spencer3822ff52006-11-08 06:47:33 +00002165</pre>
2166
2167<h5>Overview:</h5>
2168<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
2169operand shifted to the right a specified number of bits.</p>
2170
2171<h5>Arguments:</h5>
2172<p>The first argument to the '<tt>ashr</tt>' instruction must be an
2173<a href="#t_integer">integer</a> type. The second argument must be an
Reid Spencerca86e162006-12-31 07:07:53 +00002174'<tt>i8</tt>' type.</p>
Reid Spencer3822ff52006-11-08 06:47:33 +00002175
2176<h5>Semantics:</h5>
2177<p>This instruction always performs an arithmetic shift right operation,
2178regardless of whether the arguments are signed or not. The <tt>var2</tt> most
2179significant bits will be filled with the sign bit of <tt>var1</tt>.</p>
2180
2181<h5>Example:</h5>
2182<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002183 &lt;result&gt; = ashr i32 4, i8 1 <i>; yields {i32}:result = 2</i>
2184 &lt;result&gt; = ashr i32 4, i8 2 <i>; yields {i32}:result = 1</i>
2185 &lt;result&gt; = ashr i8 4, i8 3 <i>; yields {i8}:result = 0</i>
2186 &lt;result&gt; = ashr i8 -2, i8 1 <i>; yields {i8 }:result = -1</i>
Chris Lattner00950542001-06-06 20:29:01 +00002187</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002188</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002189
Chris Lattner00950542001-06-06 20:29:01 +00002190<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002191<div class="doc_subsection">
Chris Lattner3df241e2006-04-08 23:07:04 +00002192 <a name="vectorops">Vector Operations</a>
2193</div>
2194
2195<div class="doc_text">
2196
2197<p>LLVM supports several instructions to represent vector operations in a
2198target-independent manner. This instructions cover the element-access and
2199vector-specific operations needed to process vectors effectively. While LLVM
2200does directly support these vector operations, many sophisticated algorithms
2201will want to use target-specific intrinsics to take full advantage of a specific
2202target.</p>
2203
2204</div>
2205
2206<!-- _______________________________________________________________________ -->
2207<div class="doc_subsubsection">
2208 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2209</div>
2210
2211<div class="doc_text">
2212
2213<h5>Syntax:</h5>
2214
2215<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002216 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002217</pre>
2218
2219<h5>Overview:</h5>
2220
2221<p>
2222The '<tt>extractelement</tt>' instruction extracts a single scalar
2223element from a packed vector at a specified index.
2224</p>
2225
2226
2227<h5>Arguments:</h5>
2228
2229<p>
2230The first operand of an '<tt>extractelement</tt>' instruction is a
2231value of <a href="#t_packed">packed</a> type. The second operand is
2232an index indicating the position from which to extract the element.
2233The index may be a variable.</p>
2234
2235<h5>Semantics:</h5>
2236
2237<p>
2238The result is a scalar of the same type as the element type of
2239<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2240<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2241results are undefined.
2242</p>
2243
2244<h5>Example:</h5>
2245
2246<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002247 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002248</pre>
2249</div>
2250
2251
2252<!-- _______________________________________________________________________ -->
2253<div class="doc_subsubsection">
2254 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2255</div>
2256
2257<div class="doc_text">
2258
2259<h5>Syntax:</h5>
2260
2261<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002262 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, i32 &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002263</pre>
2264
2265<h5>Overview:</h5>
2266
2267<p>
2268The '<tt>insertelement</tt>' instruction inserts a scalar
2269element into a packed vector at a specified index.
2270</p>
2271
2272
2273<h5>Arguments:</h5>
2274
2275<p>
2276The first operand of an '<tt>insertelement</tt>' instruction is a
2277value of <a href="#t_packed">packed</a> type. The second operand is a
2278scalar value whose type must equal the element type of the first
2279operand. The third operand is an index indicating the position at
2280which to insert the value. The index may be a variable.</p>
2281
2282<h5>Semantics:</h5>
2283
2284<p>
2285The result is a packed vector of the same type as <tt>val</tt>. Its
2286element values are those of <tt>val</tt> except at position
2287<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2288exceeds the length of <tt>val</tt>, the results are undefined.
2289</p>
2290
2291<h5>Example:</h5>
2292
2293<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002294 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002295</pre>
2296</div>
2297
2298<!-- _______________________________________________________________________ -->
2299<div class="doc_subsubsection">
2300 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2301</div>
2302
2303<div class="doc_text">
2304
2305<h5>Syntax:</h5>
2306
2307<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002308 &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;n x i32&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002309</pre>
2310
2311<h5>Overview:</h5>
2312
2313<p>
2314The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2315from two input vectors, returning a vector of the same type.
2316</p>
2317
2318<h5>Arguments:</h5>
2319
2320<p>
2321The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2322with types that match each other and types that match the result of the
2323instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerca86e162006-12-31 07:07:53 +00002324of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattner3df241e2006-04-08 23:07:04 +00002325</p>
2326
2327<p>
2328The shuffle mask operand is required to be a constant vector with either
2329constant integer or undef values.
2330</p>
2331
2332<h5>Semantics:</h5>
2333
2334<p>
2335The elements of the two input vectors are numbered from left to right across
2336both of the vectors. The shuffle mask operand specifies, for each element of
2337the result vector, which element of the two input registers the result element
2338gets. The element selector may be undef (meaning "don't care") and the second
2339operand may be undef if performing a shuffle from only one vector.
2340</p>
2341
2342<h5>Example:</h5>
2343
2344<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002345 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
2346 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
2347 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2348 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
Chris Lattner3df241e2006-04-08 23:07:04 +00002349</pre>
2350</div>
2351
Tanya Lattner09474292006-04-14 19:24:33 +00002352
Chris Lattner3df241e2006-04-08 23:07:04 +00002353<!-- ======================================================================= -->
2354<div class="doc_subsection">
Chris Lattner884a9702006-08-15 00:45:58 +00002355 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002356</div>
2357
Misha Brukman9d0919f2003-11-08 01:05:38 +00002358<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002359
Chris Lattner261efe92003-11-25 01:02:51 +00002360<p>A key design point of an SSA-based representation is how it
2361represents memory. In LLVM, no memory locations are in SSA form, which
2362makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00002363allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002364
Misha Brukman9d0919f2003-11-08 01:05:38 +00002365</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002366
Chris Lattner00950542001-06-06 20:29:01 +00002367<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002368<div class="doc_subsubsection">
2369 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2370</div>
2371
Misha Brukman9d0919f2003-11-08 01:05:38 +00002372<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002373
Chris Lattner00950542001-06-06 20:29:01 +00002374<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002375
2376<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002377 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002378</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002379
Chris Lattner00950542001-06-06 20:29:01 +00002380<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002381
Chris Lattner261efe92003-11-25 01:02:51 +00002382<p>The '<tt>malloc</tt>' instruction allocates memory from the system
2383heap and returns a pointer to it.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002384
Chris Lattner00950542001-06-06 20:29:01 +00002385<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002386
2387<p>The '<tt>malloc</tt>' instruction allocates
2388<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00002389bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002390appropriate type to the program. If "NumElements" is specified, it is the
2391number of elements allocated. If an alignment is specified, the value result
2392of the allocation is guaranteed to be aligned to at least that boundary. If
2393not specified, or if zero, the target can choose to align the allocation on any
2394convenient boundary.</p>
2395
Misha Brukman9d0919f2003-11-08 01:05:38 +00002396<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002397
Chris Lattner00950542001-06-06 20:29:01 +00002398<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002399
Chris Lattner261efe92003-11-25 01:02:51 +00002400<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2401a pointer is returned.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002402
Chris Lattner2cbdc452005-11-06 08:02:57 +00002403<h5>Example:</h5>
2404
2405<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002406 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002407
Reid Spencerca86e162006-12-31 07:07:53 +00002408 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2409 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2410 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2411 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2412 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00002413</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002414</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002415
Chris Lattner00950542001-06-06 20:29:01 +00002416<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002417<div class="doc_subsubsection">
2418 <a name="i_free">'<tt>free</tt>' Instruction</a>
2419</div>
2420
Misha Brukman9d0919f2003-11-08 01:05:38 +00002421<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002422
Chris Lattner00950542001-06-06 20:29:01 +00002423<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002424
2425<pre>
2426 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00002427</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002428
Chris Lattner00950542001-06-06 20:29:01 +00002429<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002430
Chris Lattner261efe92003-11-25 01:02:51 +00002431<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00002432memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002433
Chris Lattner00950542001-06-06 20:29:01 +00002434<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002435
Chris Lattner261efe92003-11-25 01:02:51 +00002436<p>'<tt>value</tt>' shall be a pointer value that points to a value
2437that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2438instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002439
Chris Lattner00950542001-06-06 20:29:01 +00002440<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002441
John Criswell9e2485c2004-12-10 15:51:16 +00002442<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00002443after this instruction executes.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002444
Chris Lattner00950542001-06-06 20:29:01 +00002445<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002446
2447<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002448 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2449 free [4 x i8]* %array
Chris Lattner00950542001-06-06 20:29:01 +00002450</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002451</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002452
Chris Lattner00950542001-06-06 20:29:01 +00002453<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002454<div class="doc_subsubsection">
2455 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2456</div>
2457
Misha Brukman9d0919f2003-11-08 01:05:38 +00002458<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002459
Chris Lattner00950542001-06-06 20:29:01 +00002460<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002461
2462<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002463 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002464</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002465
Chris Lattner00950542001-06-06 20:29:01 +00002466<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002467
Chris Lattner261efe92003-11-25 01:02:51 +00002468<p>The '<tt>alloca</tt>' instruction allocates memory on the current
2469stack frame of the procedure that is live until the current function
2470returns to its caller.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002471
Chris Lattner00950542001-06-06 20:29:01 +00002472<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002473
John Criswell9e2485c2004-12-10 15:51:16 +00002474<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002475bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002476appropriate type to the program. If "NumElements" is specified, it is the
2477number of elements allocated. If an alignment is specified, the value result
2478of the allocation is guaranteed to be aligned to at least that boundary. If
2479not specified, or if zero, the target can choose to align the allocation on any
2480convenient boundary.</p>
2481
Misha Brukman9d0919f2003-11-08 01:05:38 +00002482<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002483
Chris Lattner00950542001-06-06 20:29:01 +00002484<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002485
John Criswellc1f786c2005-05-13 22:25:59 +00002486<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00002487memory is automatically released when the function returns. The '<tt>alloca</tt>'
2488instruction is commonly used to represent automatic variables that must
2489have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00002490 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002491instructions), the memory is reclaimed.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002492
Chris Lattner00950542001-06-06 20:29:01 +00002493<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002494
2495<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002496 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
2497 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2498 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
2499 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00002500</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002501</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002502
Chris Lattner00950542001-06-06 20:29:01 +00002503<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002504<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2505Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002506<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002507<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002508<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002509<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002510<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002511<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002512<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00002513address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00002514 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00002515marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00002516the number or order of execution of this <tt>load</tt> with other
2517volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2518instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002519<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002520<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002521<h5>Examples:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002522<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002523 <a
Reid Spencerca86e162006-12-31 07:07:53 +00002524 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2525 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002526</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002527</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002528<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002529<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2530Instruction</a> </div>
Reid Spencer035ab572006-11-09 21:18:01 +00002531<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002532<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002533<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattnerf0651072003-09-08 18:27:49 +00002534 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002535</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002536<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002537<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002538<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002539<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell0ec250c2005-10-24 16:17:18 +00002540to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002541operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00002542operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00002543optimizer is not allowed to modify the number or order of execution of
2544this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2545 href="#i_store">store</a></tt> instructions.</p>
2546<h5>Semantics:</h5>
2547<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2548at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002549<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002550<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002551 <a
Reid Spencerca86e162006-12-31 07:07:53 +00002552 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2553 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002554</pre>
Reid Spencer47ce1792006-11-09 21:15:49 +00002555</div>
2556
Chris Lattner2b7d3202002-05-06 03:03:22 +00002557<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002558<div class="doc_subsubsection">
2559 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2560</div>
2561
Misha Brukman9d0919f2003-11-08 01:05:38 +00002562<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00002563<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002564<pre>
2565 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2566</pre>
2567
Chris Lattner7faa8832002-04-14 06:13:44 +00002568<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002569
2570<p>
2571The '<tt>getelementptr</tt>' instruction is used to get the address of a
2572subelement of an aggregate data structure.</p>
2573
Chris Lattner7faa8832002-04-14 06:13:44 +00002574<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002575
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002576<p>This instruction takes a list of integer operands that indicate what
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002577elements of the aggregate object to index to. The actual types of the arguments
2578provided depend on the type of the first pointer argument. The
2579'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00002580levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerca86e162006-12-31 07:07:53 +00002581structure, only <tt>i32</tt> integer constants are allowed. When indexing
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002582into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2583be sign extended to 64-bit values.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002584
Chris Lattner261efe92003-11-25 01:02:51 +00002585<p>For example, let's consider a C code fragment and how it gets
2586compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002587
2588<pre>
2589 struct RT {
2590 char A;
Reid Spencerca86e162006-12-31 07:07:53 +00002591 i32 B[10][20];
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002592 char C;
2593 };
2594 struct ST {
Reid Spencerca86e162006-12-31 07:07:53 +00002595 i32 X;
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002596 double Y;
2597 struct RT Z;
2598 };
2599
Reid Spencerca86e162006-12-31 07:07:53 +00002600 define i32 *foo(struct ST *s) {
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002601 return &amp;s[1].Z.B[5][13];
2602 }
2603</pre>
2604
Misha Brukman9d0919f2003-11-08 01:05:38 +00002605<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002606
2607<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002608 %RT = type { i8 , [10 x [20 x i32]], i8 }
2609 %ST = type { i32, double, %RT }
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002610
Brian Gaeke7283e7c2004-07-02 21:08:14 +00002611 implementation
2612
Reid Spencerca86e162006-12-31 07:07:53 +00002613 define i32* %foo(%ST* %s) {
Brian Gaeke7283e7c2004-07-02 21:08:14 +00002614 entry:
Reid Spencerca86e162006-12-31 07:07:53 +00002615 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
2616 ret i32* %reg
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002617 }
2618</pre>
2619
Chris Lattner7faa8832002-04-14 06:13:44 +00002620<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002621
2622<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00002623on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002624and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencer42ddd842006-12-03 16:53:48 +00002625<a href="#t_integer">integer</a> type but the value will always be sign extended
Reid Spencerca86e162006-12-31 07:07:53 +00002626to 64-bits. <a href="#t_struct">Structure</a> types, require <tt>i32</tt>
Reid Spencer42ddd842006-12-03 16:53:48 +00002627<b>constants</b>.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002628
Misha Brukman9d0919f2003-11-08 01:05:38 +00002629<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerca86e162006-12-31 07:07:53 +00002630type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002631}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerca86e162006-12-31 07:07:53 +00002632the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
2633i8 }</tt>' type, another structure. The third index indexes into the second
2634element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002635array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerca86e162006-12-31 07:07:53 +00002636'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
2637to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002638
Chris Lattner261efe92003-11-25 01:02:51 +00002639<p>Note that it is perfectly legal to index partially through a
2640structure, returning a pointer to an inner element. Because of this,
2641the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002642
2643<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002644 define i32* %foo(%ST* %s) {
2645 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
2646 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
2647 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
2648 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
2649 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
2650 ret i32* %t5
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002651 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00002652</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00002653
2654<p>Note that it is undefined to access an array out of bounds: array and
2655pointer indexes must always be within the defined bounds of the array type.
2656The one exception for this rules is zero length arrays. These arrays are
2657defined to be accessible as variable length arrays, which requires access
2658beyond the zero'th element.</p>
2659
Chris Lattner884a9702006-08-15 00:45:58 +00002660<p>The getelementptr instruction is often confusing. For some more insight
2661into how it works, see <a href="GetElementPtr.html">the getelementptr
2662FAQ</a>.</p>
2663
Chris Lattner7faa8832002-04-14 06:13:44 +00002664<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00002665
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002666<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002667 <i>; yields [12 x i8]*:aptr</i>
2668 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002669</pre>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002670</div>
Reid Spencer47ce1792006-11-09 21:15:49 +00002671
Chris Lattner00950542001-06-06 20:29:01 +00002672<!-- ======================================================================= -->
Reid Spencer2fd21e62006-11-08 01:18:52 +00002673<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002674</div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002675<div class="doc_text">
Reid Spencer2fd21e62006-11-08 01:18:52 +00002676<p>The instructions in this category are the conversion instructions (casting)
2677which all take a single operand and a type. They perform various bit conversions
2678on the operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002679</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002680
Chris Lattner6536cfe2002-05-06 22:08:29 +00002681<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00002682<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002683 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
2684</div>
2685<div class="doc_text">
2686
2687<h5>Syntax:</h5>
2688<pre>
2689 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2690</pre>
2691
2692<h5>Overview:</h5>
2693<p>
2694The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
2695</p>
2696
2697<h5>Arguments:</h5>
2698<p>
2699The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
2700be an <a href="#t_integer">integer</a> type, and a type that specifies the size
2701and type of the result, which must be an <a href="#t_integral">integral</a>
Reid Spencerd4448792006-11-09 23:03:26 +00002702type. The bit size of <tt>value</tt> must be larger than the bit size of
2703<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002704
2705<h5>Semantics:</h5>
2706<p>
2707The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencerd4448792006-11-09 23:03:26 +00002708and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
2709larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
2710It will always truncate bits.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002711
2712<h5>Example:</h5>
2713<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002714 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00002715 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
2716 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002717</pre>
2718</div>
2719
2720<!-- _______________________________________________________________________ -->
2721<div class="doc_subsubsection">
2722 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
2723</div>
2724<div class="doc_text">
2725
2726<h5>Syntax:</h5>
2727<pre>
2728 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2729</pre>
2730
2731<h5>Overview:</h5>
2732<p>The '<tt>zext</tt>' instruction zero extends its operand to type
2733<tt>ty2</tt>.</p>
2734
2735
2736<h5>Arguments:</h5>
2737<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
2738<a href="#t_integral">integral</a> type, and a type to cast it to, which must
2739also be of <a href="#t_integral">integral</a> type. The bit size of the
Reid Spencerd4448792006-11-09 23:03:26 +00002740<tt>value</tt> must be smaller than the bit size of the destination type,
2741<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002742
2743<h5>Semantics:</h5>
2744<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
2745bits until it reaches the size of the destination type, <tt>ty2</tt>. When the
2746the operand and the type are the same size, no bit filling is done and the
2747cast is considered a <i>no-op cast</i> because no bits change (only the type
2748changes).</p>
2749
Reid Spencerb5929522007-01-12 15:46:11 +00002750<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002751
2752<h5>Example:</h5>
2753<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002754 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00002755 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002756</pre>
2757</div>
2758
2759<!-- _______________________________________________________________________ -->
2760<div class="doc_subsubsection">
2761 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
2762</div>
2763<div class="doc_text">
2764
2765<h5>Syntax:</h5>
2766<pre>
2767 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2768</pre>
2769
2770<h5>Overview:</h5>
2771<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
2772
2773<h5>Arguments:</h5>
2774<p>
2775The '<tt>sext</tt>' instruction takes a value to cast, which must be of
2776<a href="#t_integral">integral</a> type, and a type to cast it to, which must
Reid Spencerd4448792006-11-09 23:03:26 +00002777also be of <a href="#t_integral">integral</a> type. The bit size of the
2778<tt>value</tt> must be smaller than the bit size of the destination type,
2779<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002780
2781<h5>Semantics:</h5>
2782<p>
2783The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
2784bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
2785the type <tt>ty2</tt>. When the the operand and the type are the same size,
2786no bit filling is done and the cast is considered a <i>no-op cast</i> because
2787no bits change (only the type changes).</p>
2788
Reid Spencerc78f3372007-01-12 03:35:51 +00002789<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002790
2791<h5>Example:</h5>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002792<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002793 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00002794 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002795</pre>
2796</div>
2797
2798<!-- _______________________________________________________________________ -->
2799<div class="doc_subsubsection">
Reid Spencer3fa91b02006-11-09 21:48:10 +00002800 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
2801</div>
2802
2803<div class="doc_text">
2804
2805<h5>Syntax:</h5>
2806
2807<pre>
2808 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2809</pre>
2810
2811<h5>Overview:</h5>
2812<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
2813<tt>ty2</tt>.</p>
2814
2815
2816<h5>Arguments:</h5>
2817<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
2818 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
2819cast it to. The size of <tt>value</tt> must be larger than the size of
2820<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
2821<i>no-op cast</i>.</p>
2822
2823<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002824<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
2825<a href="#t_floating">floating point</a> type to a smaller
2826<a href="#t_floating">floating point</a> type. If the value cannot fit within
2827the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer3fa91b02006-11-09 21:48:10 +00002828
2829<h5>Example:</h5>
2830<pre>
2831 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
2832 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
2833</pre>
2834</div>
2835
2836<!-- _______________________________________________________________________ -->
2837<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002838 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
2839</div>
2840<div class="doc_text">
2841
2842<h5>Syntax:</h5>
2843<pre>
2844 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2845</pre>
2846
2847<h5>Overview:</h5>
2848<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
2849floating point value.</p>
2850
2851<h5>Arguments:</h5>
2852<p>The '<tt>fpext</tt>' instruction takes a
2853<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencerd4448792006-11-09 23:03:26 +00002854and a <a href="#t_floating">floating point</a> type to cast it to. The source
2855type must be smaller than the destination type.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002856
2857<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002858<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
2859<a href="t_floating">floating point</a> type to a larger
2860<a href="t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
2861used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5c0ef472006-11-11 23:08:07 +00002862<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002863
2864<h5>Example:</h5>
2865<pre>
2866 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
2867 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
2868</pre>
2869</div>
2870
2871<!-- _______________________________________________________________________ -->
2872<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00002873 <a name="i_fp2uint">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002874</div>
2875<div class="doc_text">
2876
2877<h5>Syntax:</h5>
2878<pre>
2879 &lt;result&gt; = fp2uint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2880</pre>
2881
2882<h5>Overview:</h5>
2883<p>The '<tt>fp2uint</tt>' converts a floating point <tt>value</tt> to its
2884unsigned integer equivalent of type <tt>ty2</tt>.
2885</p>
2886
2887<h5>Arguments:</h5>
2888<p>The '<tt>fp2uint</tt>' instruction takes a value to cast, which must be a
2889<a href="#t_floating">floating point</a> value, and a type to cast it to, which
2890must be an <a href="#t_integral">integral</a> type.</p>
2891
2892<h5>Semantics:</h5>
2893<p> The '<tt>fp2uint</tt>' instruction converts its
2894<a href="#t_floating">floating point</a> operand into the nearest (rounding
2895towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
2896the results are undefined.</p>
2897
Reid Spencerc78f3372007-01-12 03:35:51 +00002898<p>When converting to i1, the conversion is done as a comparison against
2899zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
2900If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002901
2902<h5>Example:</h5>
2903<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00002904 %X = fp2uint double 123.0 to i32 <i>; yields i32:123</i>
2905 %Y = fp2uint float 1.0E+300 to i1 <i>; yields i1:true</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002906 %X = fp2uint float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002907</pre>
2908</div>
2909
2910<!-- _______________________________________________________________________ -->
2911<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00002912 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002913</div>
2914<div class="doc_text">
2915
2916<h5>Syntax:</h5>
2917<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00002918 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002919</pre>
2920
2921<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002922<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002923<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnercc37aae2004-03-12 05:50:16 +00002924</p>
2925
2926
Chris Lattner6536cfe2002-05-06 22:08:29 +00002927<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002928<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002929<a href="#t_floating">floating point</a> value, and a type to cast it to, which
2930must also be an <a href="#t_integral">integral</a> type.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002931
Chris Lattner6536cfe2002-05-06 22:08:29 +00002932<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002933<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002934<a href="#t_floating">floating point</a> operand into the nearest (rounding
2935towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
2936the results are undefined.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002937
Reid Spencerc78f3372007-01-12 03:35:51 +00002938<p>When converting to i1, the conversion is done as a comparison against
2939zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
2940If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002941
Chris Lattner33ba0d92001-07-09 00:26:23 +00002942<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002943<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00002944 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
2945 %Y = fptosi float 1.0E-247 to i1 <i>; yields i1:true</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002946 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002947</pre>
2948</div>
2949
2950<!-- _______________________________________________________________________ -->
2951<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00002952 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002953</div>
2954<div class="doc_text">
2955
2956<h5>Syntax:</h5>
2957<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00002958 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002959</pre>
2960
2961<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002962<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002963integer and converts that value to the <tt>ty2</tt> type.</p>
2964
2965
2966<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002967<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be an
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002968<a href="#t_integral">integral</a> value, and a type to cast it to, which must
2969be a <a href="#t_floating">floating point</a> type.</p>
2970
2971<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002972<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002973integer quantity and converts it to the corresponding floating point value. If
2974the value cannot fit in the floating point value, the results are undefined.</p>
2975
2976
2977<h5>Example:</h5>
2978<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002979 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
2980 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002981</pre>
2982</div>
2983
2984<!-- _______________________________________________________________________ -->
2985<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00002986 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002987</div>
2988<div class="doc_text">
2989
2990<h5>Syntax:</h5>
2991<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00002992 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002993</pre>
2994
2995<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00002996<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002997integer and converts that value to the <tt>ty2</tt> type.</p>
2998
2999<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003000<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be an
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003001<a href="#t_integral">integral</a> value, and a type to cast it to, which must be
3002a <a href="#t_floating">floating point</a> type.</p>
3003
3004<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003005<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003006integer quantity and converts it to the corresponding floating point value. If
3007the value cannot fit in the floating point value, the results are undefined.</p>
3008
3009<h5>Example:</h5>
3010<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003011 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
3012 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003013</pre>
3014</div>
3015
3016<!-- _______________________________________________________________________ -->
3017<div class="doc_subsubsection">
Reid Spencer72679252006-11-11 21:00:47 +00003018 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3019</div>
3020<div class="doc_text">
3021
3022<h5>Syntax:</h5>
3023<pre>
3024 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3025</pre>
3026
3027<h5>Overview:</h5>
3028<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3029the integer type <tt>ty2</tt>.</p>
3030
3031<h5>Arguments:</h5>
3032<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
3033must be a <a href="t_pointer">pointer</a> value, and a type to cast it to
3034<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3035
3036<h5>Semantics:</h5>
3037<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3038<tt>ty2</tt> by interpreting the pointer value as an integer and either
3039truncating or zero extending that value to the size of the integer type. If
3040<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3041<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
3042are the same size, then nothing is done (<i>no-op cast</i>).</p>
3043
3044<h5>Example:</h5>
3045<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003046 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit</i>
3047 %Y = ptrtoint i32* %x to i64 <i>; yields zero extend on 32-bit</i>
Reid Spencer72679252006-11-11 21:00:47 +00003048</pre>
3049</div>
3050
3051<!-- _______________________________________________________________________ -->
3052<div class="doc_subsubsection">
3053 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3054</div>
3055<div class="doc_text">
3056
3057<h5>Syntax:</h5>
3058<pre>
3059 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3060</pre>
3061
3062<h5>Overview:</h5>
3063<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3064a pointer type, <tt>ty2</tt>.</p>
3065
3066<h5>Arguments:</h5>
3067<p>The '<tt>inttoptr</tt>' instruction takes an <a href="i_integer">integer</a>
3068value to cast, and a type to cast it to, which must be a
Anton Korobeynikov7f705592007-01-12 19:20:47 +00003069<a href="#t_pointer">pointer</a> type.
Reid Spencer72679252006-11-11 21:00:47 +00003070
3071<h5>Semantics:</h5>
3072<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3073<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3074the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3075size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3076the size of a pointer then a zero extension is done. If they are the same size,
3077nothing is done (<i>no-op cast</i>).</p>
3078
3079<h5>Example:</h5>
3080<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003081 %X = inttoptr i32 255 to i32* <i>; yields zero extend on 64-bit</i>
3082 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit </i>
3083 %Y = inttoptr i16 0 to i32* <i>; yields zero extend on 32-bit</i>
Reid Spencer72679252006-11-11 21:00:47 +00003084</pre>
3085</div>
3086
3087<!-- _______________________________________________________________________ -->
3088<div class="doc_subsubsection">
Reid Spencer5c0ef472006-11-11 23:08:07 +00003089 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003090</div>
3091<div class="doc_text">
3092
3093<h5>Syntax:</h5>
3094<pre>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003095 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003096</pre>
3097
3098<h5>Overview:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003099<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003100<tt>ty2</tt> without changing any bits.</p>
3101
3102<h5>Arguments:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003103<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003104a first class value, and a type to cast it to, which must also be a <a
3105 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencer19b569f2007-01-09 20:08:58 +00003106and the destination type, <tt>ty2</tt>, must be identical. If the source
3107type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003108
3109<h5>Semantics:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003110<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer72679252006-11-11 21:00:47 +00003111<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3112this conversion. The conversion is done as if the <tt>value</tt> had been
3113stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3114converted to other pointer types with this instruction. To convert pointers to
3115other types, use the <a href="#i_inttoptr">inttoptr</a> or
3116<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003117
3118<h5>Example:</h5>
3119<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003120 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
3121 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3122 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00003123</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003124</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003125
Reid Spencer2fd21e62006-11-08 01:18:52 +00003126<!-- ======================================================================= -->
3127<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3128<div class="doc_text">
3129<p>The instructions in this category are the "miscellaneous"
3130instructions, which defy better classification.</p>
3131</div>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003132
3133<!-- _______________________________________________________________________ -->
3134<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3135</div>
3136<div class="doc_text">
3137<h5>Syntax:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00003138<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3139<i>; yields {i1}:result</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003140</pre>
3141<h5>Overview:</h5>
3142<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3143of its two integer operands.</p>
3144<h5>Arguments:</h5>
3145<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
3146the condition code which indicates the kind of comparison to perform. It is not
3147a value, just a keyword. The possibilities for the condition code are:
3148<ol>
3149 <li><tt>eq</tt>: equal</li>
3150 <li><tt>ne</tt>: not equal </li>
3151 <li><tt>ugt</tt>: unsigned greater than</li>
3152 <li><tt>uge</tt>: unsigned greater or equal</li>
3153 <li><tt>ult</tt>: unsigned less than</li>
3154 <li><tt>ule</tt>: unsigned less or equal</li>
3155 <li><tt>sgt</tt>: signed greater than</li>
3156 <li><tt>sge</tt>: signed greater or equal</li>
3157 <li><tt>slt</tt>: signed less than</li>
3158 <li><tt>sle</tt>: signed less or equal</li>
3159</ol>
Reid Spencer350f8aa2007-01-04 05:19:58 +00003160<p>The remaining two arguments must be <a href="#t_integral">integral</a> or
3161<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003162<h5>Semantics:</h5>
3163<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3164the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencerc78f3372007-01-12 03:35:51 +00003165yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003166<ol>
3167 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3168 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3169 </li>
3170 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3171 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3172 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3173 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3174 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3175 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3176 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3177 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3178 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3179 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3180 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3181 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3182 <li><tt>sge</tt>: interprets the operands as signed values and yields
3183 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3184 <li><tt>slt</tt>: interprets the operands as signed values and yields
3185 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3186 <li><tt>sle</tt>: interprets the operands as signed values and yields
3187 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003188</ol>
3189<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
3190values are treated as integers and then compared.</p>
3191<p>If the operands are <a href="#t_packed">packed</a> typed, the elements of
Reid Spencerb7f26282006-11-19 03:00:14 +00003192the vector are compared in turn and the predicate must hold for all
3193elements.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003194
3195<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003196<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3197 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3198 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3199 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3200 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3201 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003202</pre>
3203</div>
3204
3205<!-- _______________________________________________________________________ -->
3206<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3207</div>
3208<div class="doc_text">
3209<h5>Syntax:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00003210<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3211<i>; yields {i1}:result</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003212</pre>
3213<h5>Overview:</h5>
3214<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3215of its floating point operands.</p>
3216<h5>Arguments:</h5>
3217<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
3218the condition code which indicates the kind of comparison to perform. It is not
3219a value, just a keyword. The possibilities for the condition code are:
3220<ol>
Reid Spencerb7f26282006-11-19 03:00:14 +00003221 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003222 <li><tt>oeq</tt>: ordered and equal</li>
3223 <li><tt>ogt</tt>: ordered and greater than </li>
3224 <li><tt>oge</tt>: ordered and greater than or equal</li>
3225 <li><tt>olt</tt>: ordered and less than </li>
3226 <li><tt>ole</tt>: ordered and less than or equal</li>
3227 <li><tt>one</tt>: ordered and not equal</li>
3228 <li><tt>ord</tt>: ordered (no nans)</li>
3229 <li><tt>ueq</tt>: unordered or equal</li>
3230 <li><tt>ugt</tt>: unordered or greater than </li>
3231 <li><tt>uge</tt>: unordered or greater than or equal</li>
3232 <li><tt>ult</tt>: unordered or less than </li>
3233 <li><tt>ule</tt>: unordered or less than or equal</li>
3234 <li><tt>une</tt>: unordered or not equal</li>
3235 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003236 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003237</ol>
Reid Spencer93a49852006-12-06 07:08:07 +00003238<p>In the preceding, <i>ordered</i> means that neither operand is a QNAN while
3239<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer350f8aa2007-01-04 05:19:58 +00003240<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3241<a href="#t_floating">floating point</a> typed. They must have identical
3242types.</p>
Reid Spencerb7f26282006-11-19 03:00:14 +00003243<p>In the foregoing, <i>ordered</i> means that neither operand is a QNAN and
3244<i>unordered</i> means that either operand is a QNAN.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003245<h5>Semantics:</h5>
3246<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3247the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencerc78f3372007-01-12 03:35:51 +00003248yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003249<ol>
3250 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003251 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003252 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003253 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003254 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003255 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003256 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003257 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003258 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003259 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003260 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003261 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003262 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003263 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3264 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003265 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003266 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003267 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003268 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003269 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003270 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003271 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003272 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003273 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003274 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003275 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003276 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003277 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3278</ol>
3279<p>If the operands are <a href="#t_packed">packed</a> typed, the elements of
3280the vector are compared in turn and the predicate must hold for all elements.
Reid Spencerb7f26282006-11-19 03:00:14 +00003281</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003282
3283<h5>Example:</h5>
3284<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3285 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3286 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3287 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3288</pre>
3289</div>
3290
Reid Spencer2fd21e62006-11-08 01:18:52 +00003291<!-- _______________________________________________________________________ -->
3292<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3293Instruction</a> </div>
3294<div class="doc_text">
3295<h5>Syntax:</h5>
3296<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3297<h5>Overview:</h5>
3298<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3299the SSA graph representing the function.</p>
3300<h5>Arguments:</h5>
3301<p>The type of the incoming values are specified with the first type
3302field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3303as arguments, with one pair for each predecessor basic block of the
3304current block. Only values of <a href="#t_firstclass">first class</a>
3305type may be used as the value arguments to the PHI node. Only labels
3306may be used as the label arguments.</p>
3307<p>There must be no non-phi instructions between the start of a basic
3308block and the PHI instructions: i.e. PHI instructions must be first in
3309a basic block.</p>
3310<h5>Semantics:</h5>
3311<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
3312value specified by the parameter, depending on which basic block we
3313came from in the last <a href="#terminators">terminator</a> instruction.</p>
3314<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003315<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add i32 %indvar, 1<br> br label %Loop<br></pre>
Reid Spencer2fd21e62006-11-08 01:18:52 +00003316</div>
3317
Chris Lattnercc37aae2004-03-12 05:50:16 +00003318<!-- _______________________________________________________________________ -->
3319<div class="doc_subsubsection">
3320 <a name="i_select">'<tt>select</tt>' Instruction</a>
3321</div>
3322
3323<div class="doc_text">
3324
3325<h5>Syntax:</h5>
3326
3327<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003328 &lt;result&gt; = select i1 &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003329</pre>
3330
3331<h5>Overview:</h5>
3332
3333<p>
3334The '<tt>select</tt>' instruction is used to choose one value based on a
3335condition, without branching.
3336</p>
3337
3338
3339<h5>Arguments:</h5>
3340
3341<p>
3342The '<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.
3343</p>
3344
3345<h5>Semantics:</h5>
3346
3347<p>
3348If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00003349value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00003350</p>
3351
3352<h5>Example:</h5>
3353
3354<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003355 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003356</pre>
3357</div>
3358
Robert Bocchino05ccd702006-01-15 20:48:27 +00003359
3360<!-- _______________________________________________________________________ -->
3361<div class="doc_subsubsection">
Chris Lattner2bff5242005-05-06 05:47:36 +00003362 <a name="i_call">'<tt>call</tt>' Instruction</a>
3363</div>
3364
Misha Brukman9d0919f2003-11-08 01:05:38 +00003365<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00003366
Chris Lattner00950542001-06-06 20:29:01 +00003367<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003368<pre>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003369 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00003370</pre>
3371
Chris Lattner00950542001-06-06 20:29:01 +00003372<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003373
Misha Brukman9d0919f2003-11-08 01:05:38 +00003374<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003375
Chris Lattner00950542001-06-06 20:29:01 +00003376<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003377
Misha Brukman9d0919f2003-11-08 01:05:38 +00003378<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003379
Chris Lattner6536cfe2002-05-06 22:08:29 +00003380<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00003381 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003382 <p>The optional "tail" marker indicates whether the callee function accesses
3383 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00003384 function call is eligible for tail call optimization. Note that calls may
3385 be marked "tail" even if they do not occur before a <a
3386 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00003387 </li>
3388 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003389 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
3390 convention</a> the call should use. If none is specified, the call defaults
3391 to using C calling conventions.
3392 </li>
3393 <li>
Chris Lattner2bff5242005-05-06 05:47:36 +00003394 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
3395 being invoked. The argument types must match the types implied by this
John Criswellfc6b8952005-05-16 16:17:45 +00003396 signature. This type can be omitted if the function is not varargs and
3397 if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003398 </li>
3399 <li>
3400 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3401 be invoked. In most cases, this is a direct function invocation, but
3402 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00003403 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003404 </li>
3405 <li>
3406 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00003407 function signature argument types. All arguments must be of
3408 <a href="#t_firstclass">first class</a> type. If the function signature
3409 indicates the function accepts a variable number of arguments, the extra
3410 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003411 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00003412</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00003413
Chris Lattner00950542001-06-06 20:29:01 +00003414<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003415
Chris Lattner261efe92003-11-25 01:02:51 +00003416<p>The '<tt>call</tt>' instruction is used to cause control flow to
3417transfer to a specified function, with its incoming arguments bound to
3418the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3419instruction in the called function, control flow continues with the
3420instruction after the function call, and the return value of the
3421function is bound to the result argument. This is a simpler case of
3422the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003423
Chris Lattner00950542001-06-06 20:29:01 +00003424<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003425
3426<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003427 %retval = call i32 %test(i32 %argc)
3428 call i32(i8 *, ...) *%printf(i8 * %msg, i32 12, i8 42);
3429 %X = tail call i32 %foo()
3430 %Y = tail call <a href="#callingconv">fastcc</a> i32 %foo()
Chris Lattner2bff5242005-05-06 05:47:36 +00003431</pre>
3432
Misha Brukman9d0919f2003-11-08 01:05:38 +00003433</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003434
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003435<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00003436<div class="doc_subsubsection">
Chris Lattnerfb6977d2006-01-13 23:26:01 +00003437 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003438</div>
3439
Misha Brukman9d0919f2003-11-08 01:05:38 +00003440<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00003441
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003442<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003443
3444<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003445 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00003446</pre>
3447
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003448<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003449
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003450<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00003451the "variable argument" area of a function call. It is used to implement the
3452<tt>va_arg</tt> macro in C.</p>
3453
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003454<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003455
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003456<p>This instruction takes a <tt>va_list*</tt> value and the type of
3457the argument. It returns a value of the specified argument type and
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00003458increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003459actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003460
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003461<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003462
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003463<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3464type from the specified <tt>va_list</tt> and causes the
3465<tt>va_list</tt> to point to the next argument. For more information,
3466see the variable argument handling <a href="#int_varargs">Intrinsic
3467Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003468
3469<p>It is legal for this instruction to be called in a function which does not
3470take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003471function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003472
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003473<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00003474href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00003475argument.</p>
3476
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003477<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003478
3479<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3480
Misha Brukman9d0919f2003-11-08 01:05:38 +00003481</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003482
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003483<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00003484<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3485<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003486
Misha Brukman9d0919f2003-11-08 01:05:38 +00003487<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003488
3489<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswellfc6b8952005-05-16 16:17:45 +00003490well known names and semantics and are required to follow certain
Chris Lattner33aec9e2004-02-12 17:01:32 +00003491restrictions. Overall, these instructions represent an extension mechanism for
3492the LLVM language that does not require changing all of the transformations in
3493LLVM to add to the language (or the bytecode reader/writer, the parser,
3494etc...).</p>
3495
John Criswellfc6b8952005-05-16 16:17:45 +00003496<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
3497prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattner33aec9e2004-02-12 17:01:32 +00003498this. Intrinsic functions must always be external functions: you cannot define
3499the body of intrinsic functions. Intrinsic functions may only be used in call
3500or invoke instructions: it is illegal to take the address of an intrinsic
3501function. Additionally, because intrinsic functions are part of the LLVM
3502language, it is required that they all be documented here if any are added.</p>
3503
3504
John Criswellfc6b8952005-05-16 16:17:45 +00003505<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner590cff32005-05-11 03:35:57 +00003506href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003507</p>
3508
Misha Brukman9d0919f2003-11-08 01:05:38 +00003509</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003510
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003511<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003512<div class="doc_subsection">
3513 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3514</div>
3515
Misha Brukman9d0919f2003-11-08 01:05:38 +00003516<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00003517
Misha Brukman9d0919f2003-11-08 01:05:38 +00003518<p>Variable argument support is defined in LLVM with the <a
Chris Lattnerfb6977d2006-01-13 23:26:01 +00003519 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner261efe92003-11-25 01:02:51 +00003520intrinsic functions. These functions are related to the similarly
3521named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003522
Chris Lattner261efe92003-11-25 01:02:51 +00003523<p>All of these functions operate on arguments that use a
3524target-specific value type "<tt>va_list</tt>". The LLVM assembly
3525language reference manual does not define what this type is, so all
3526transformations should be prepared to handle intrinsics with any type
3527used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003528
Chris Lattner374ab302006-05-15 17:26:46 +00003529<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00003530instruction and the variable argument handling intrinsic functions are
3531used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003532
Chris Lattner33aec9e2004-02-12 17:01:32 +00003533<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003534define i32 %test(i32 %X, ...) {
Chris Lattner33aec9e2004-02-12 17:01:32 +00003535 ; Initialize variable argument processing
Reid Spencerca86e162006-12-31 07:07:53 +00003536 %ap = alloca i8 *
Chris Lattnerb75137d2007-01-08 07:55:15 +00003537 %ap2 = bitcast i8** %ap to i8*
3538 call void %<a href="#i_va_start">llvm.va_start</a>(i8* %ap2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003539
3540 ; Read a single integer argument
Reid Spencerca86e162006-12-31 07:07:53 +00003541 %tmp = va_arg i8 ** %ap, i32
Chris Lattner33aec9e2004-02-12 17:01:32 +00003542
3543 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Reid Spencerca86e162006-12-31 07:07:53 +00003544 %aq = alloca i8 *
Chris Lattnerb75137d2007-01-08 07:55:15 +00003545 %aq2 = bitcast i8** %aq to i8*
3546 call void %<a href="#i_va_copy">llvm.va_copy</a>(i8 *%aq2, i8* %ap2)
3547 call void %<a href="#i_va_end">llvm.va_end</a>(i8* %aq2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003548
3549 ; Stop processing of arguments.
Chris Lattnerb75137d2007-01-08 07:55:15 +00003550 call void %<a href="#i_va_end">llvm.va_end</a>(i8* %ap2)
Reid Spencerca86e162006-12-31 07:07:53 +00003551 ret i32 %tmp
Chris Lattner33aec9e2004-02-12 17:01:32 +00003552}
3553</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003554</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003555
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003556<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003557<div class="doc_subsubsection">
3558 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
3559</div>
3560
3561
Misha Brukman9d0919f2003-11-08 01:05:38 +00003562<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003563<h5>Syntax:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003564<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003565<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003566<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3567<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3568href="#i_va_arg">va_arg</a></tt>.</p>
3569
3570<h5>Arguments:</h5>
3571
3572<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3573
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003574<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003575
3576<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3577macro available in C. In a target-dependent way, it initializes the
3578<tt>va_list</tt> element the argument points to, so that the next call to
3579<tt>va_arg</tt> will produce the first variable argument passed to the function.
3580Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
3581last argument of the function, the compiler can figure that out.</p>
3582
Misha Brukman9d0919f2003-11-08 01:05:38 +00003583</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003584
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003585<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003586<div class="doc_subsubsection">
3587 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
3588</div>
3589
Misha Brukman9d0919f2003-11-08 01:05:38 +00003590<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003591<h5>Syntax:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003592<pre> declare void %llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003593<h5>Overview:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003594
Chris Lattner261efe92003-11-25 01:02:51 +00003595<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
3596which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
3597or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003598
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003599<h5>Arguments:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003600
Misha Brukman9d0919f2003-11-08 01:05:38 +00003601<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003602
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003603<h5>Semantics:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003604
Misha Brukman9d0919f2003-11-08 01:05:38 +00003605<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00003606macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
3607Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
3608 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
3609with calls to <tt>llvm.va_end</tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003610
Misha Brukman9d0919f2003-11-08 01:05:38 +00003611</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003612
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003613<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003614<div class="doc_subsubsection">
3615 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
3616</div>
3617
Misha Brukman9d0919f2003-11-08 01:05:38 +00003618<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00003619
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003620<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003621
3622<pre>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003623 declare void %llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00003624</pre>
3625
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003626<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003627
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003628<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
3629the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003630
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003631<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003632
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003633<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00003634The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003635
Chris Lattnerd7923912004-05-23 21:06:01 +00003636
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003637<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003638
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003639<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
3640available in C. In a target-dependent way, it copies the source
3641<tt>va_list</tt> element into the destination list. This intrinsic is necessary
3642because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattnerd7923912004-05-23 21:06:01 +00003643arbitrarily complex and require memory allocation, for example.</p>
3644
Misha Brukman9d0919f2003-11-08 01:05:38 +00003645</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003646
Chris Lattner33aec9e2004-02-12 17:01:32 +00003647<!-- ======================================================================= -->
3648<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00003649 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
3650</div>
3651
3652<div class="doc_text">
3653
3654<p>
3655LLVM support for <a href="GarbageCollection.html">Accurate Garbage
3656Collection</a> requires the implementation and generation of these intrinsics.
3657These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
3658stack</a>, as well as garbage collector implementations that require <a
3659href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
3660Front-ends for type-safe garbage collected languages should generate these
3661intrinsics to make use of the LLVM garbage collectors. For more details, see <a
3662href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
3663</p>
3664</div>
3665
3666<!-- _______________________________________________________________________ -->
3667<div class="doc_subsubsection">
3668 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
3669</div>
3670
3671<div class="doc_text">
3672
3673<h5>Syntax:</h5>
3674
3675<pre>
Reid Spencera8d451e2005-04-26 20:50:44 +00003676 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00003677</pre>
3678
3679<h5>Overview:</h5>
3680
John Criswell9e2485c2004-12-10 15:51:16 +00003681<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00003682the code generator, and allows some metadata to be associated with it.</p>
3683
3684<h5>Arguments:</h5>
3685
3686<p>The first argument specifies the address of a stack object that contains the
3687root pointer. The second pointer (which must be either a constant or a global
3688value address) contains the meta-data to be associated with the root.</p>
3689
3690<h5>Semantics:</h5>
3691
3692<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
3693location. At compile-time, the code generator generates information to allow
3694the runtime to find the pointer at GC safe points.
3695</p>
3696
3697</div>
3698
3699
3700<!-- _______________________________________________________________________ -->
3701<div class="doc_subsubsection">
3702 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
3703</div>
3704
3705<div class="doc_text">
3706
3707<h5>Syntax:</h5>
3708
3709<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003710 declare i8 * %llvm.gcread(i8 * %ObjPtr, i8 ** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00003711</pre>
3712
3713<h5>Overview:</h5>
3714
3715<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3716locations, allowing garbage collector implementations that require read
3717barriers.</p>
3718
3719<h5>Arguments:</h5>
3720
Chris Lattner80626e92006-03-14 20:02:51 +00003721<p>The second argument is the address to read from, which should be an address
3722allocated from the garbage collector. The first object is a pointer to the
3723start of the referenced object, if needed by the language runtime (otherwise
3724null).</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003725
3726<h5>Semantics:</h5>
3727
3728<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3729instruction, but may be replaced with substantially more complex code by the
3730garbage collector runtime, as needed.</p>
3731
3732</div>
3733
3734
3735<!-- _______________________________________________________________________ -->
3736<div class="doc_subsubsection">
3737 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
3738</div>
3739
3740<div class="doc_text">
3741
3742<h5>Syntax:</h5>
3743
3744<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003745 declare void %llvm.gcwrite(i8 * %P1, i8 * %Obj, i8 ** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00003746</pre>
3747
3748<h5>Overview:</h5>
3749
3750<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3751locations, allowing garbage collector implementations that require write
3752barriers (such as generational or reference counting collectors).</p>
3753
3754<h5>Arguments:</h5>
3755
Chris Lattner80626e92006-03-14 20:02:51 +00003756<p>The first argument is the reference to store, the second is the start of the
3757object to store it to, and the third is the address of the field of Obj to
3758store to. If the runtime does not require a pointer to the object, Obj may be
3759null.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003760
3761<h5>Semantics:</h5>
3762
3763<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3764instruction, but may be replaced with substantially more complex code by the
3765garbage collector runtime, as needed.</p>
3766
3767</div>
3768
3769
3770
3771<!-- ======================================================================= -->
3772<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00003773 <a name="int_codegen">Code Generator Intrinsics</a>
3774</div>
3775
3776<div class="doc_text">
3777<p>
3778These intrinsics are provided by LLVM to expose special features that may only
3779be implemented with code generator support.
3780</p>
3781
3782</div>
3783
3784<!-- _______________________________________________________________________ -->
3785<div class="doc_subsubsection">
3786 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
3787</div>
3788
3789<div class="doc_text">
3790
3791<h5>Syntax:</h5>
3792<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003793 declare i8 *%llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003794</pre>
3795
3796<h5>Overview:</h5>
3797
3798<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00003799The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
3800target-specific value indicating the return address of the current function
3801or one of its callers.
Chris Lattner10610642004-02-14 04:08:35 +00003802</p>
3803
3804<h5>Arguments:</h5>
3805
3806<p>
3807The argument to this intrinsic indicates which function to return the address
3808for. Zero indicates the calling function, one indicates its caller, etc. The
3809argument is <b>required</b> to be a constant integer value.
3810</p>
3811
3812<h5>Semantics:</h5>
3813
3814<p>
3815The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3816the return address of the specified call frame, or zero if it cannot be
3817identified. The value returned by this intrinsic is likely to be incorrect or 0
3818for arguments other than zero, so it should only be used for debugging purposes.
3819</p>
3820
3821<p>
3822Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00003823aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00003824source-language caller.
3825</p>
3826</div>
3827
3828
3829<!-- _______________________________________________________________________ -->
3830<div class="doc_subsubsection">
3831 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
3832</div>
3833
3834<div class="doc_text">
3835
3836<h5>Syntax:</h5>
3837<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003838 declare i8 *%llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00003839</pre>
3840
3841<h5>Overview:</h5>
3842
3843<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00003844The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
3845target-specific frame pointer value for the specified stack frame.
Chris Lattner10610642004-02-14 04:08:35 +00003846</p>
3847
3848<h5>Arguments:</h5>
3849
3850<p>
3851The argument to this intrinsic indicates which function to return the frame
3852pointer for. Zero indicates the calling function, one indicates its caller,
3853etc. The argument is <b>required</b> to be a constant integer value.
3854</p>
3855
3856<h5>Semantics:</h5>
3857
3858<p>
3859The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3860the frame address of the specified call frame, or zero if it cannot be
3861identified. The value returned by this intrinsic is likely to be incorrect or 0
3862for arguments other than zero, so it should only be used for debugging purposes.
3863</p>
3864
3865<p>
3866Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00003867aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00003868source-language caller.
3869</p>
3870</div>
3871
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003872<!-- _______________________________________________________________________ -->
3873<div class="doc_subsubsection">
Chris Lattner57e1f392006-01-13 02:03:13 +00003874 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
3875</div>
3876
3877<div class="doc_text">
3878
3879<h5>Syntax:</h5>
3880<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003881 declare i8 *%llvm.stacksave()
Chris Lattner57e1f392006-01-13 02:03:13 +00003882</pre>
3883
3884<h5>Overview:</h5>
3885
3886<p>
3887The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
3888the function stack, for use with <a href="#i_stackrestore">
3889<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
3890features like scoped automatic variable sized arrays in C99.
3891</p>
3892
3893<h5>Semantics:</h5>
3894
3895<p>
3896This intrinsic returns a opaque pointer value that can be passed to <a
3897href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
3898<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
3899<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
3900state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
3901practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
3902that were allocated after the <tt>llvm.stacksave</tt> was executed.
3903</p>
3904
3905</div>
3906
3907<!-- _______________________________________________________________________ -->
3908<div class="doc_subsubsection">
3909 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
3910</div>
3911
3912<div class="doc_text">
3913
3914<h5>Syntax:</h5>
3915<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003916 declare void %llvm.stackrestore(i8 * %ptr)
Chris Lattner57e1f392006-01-13 02:03:13 +00003917</pre>
3918
3919<h5>Overview:</h5>
3920
3921<p>
3922The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
3923the function stack to the state it was in when the corresponding <a
3924href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
3925useful for implementing language features like scoped automatic variable sized
3926arrays in C99.
3927</p>
3928
3929<h5>Semantics:</h5>
3930
3931<p>
3932See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
3933</p>
3934
3935</div>
3936
3937
3938<!-- _______________________________________________________________________ -->
3939<div class="doc_subsubsection">
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003940 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
3941</div>
3942
3943<div class="doc_text">
3944
3945<h5>Syntax:</h5>
3946<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003947 declare void %llvm.prefetch(i8 * &lt;address&gt;,
3948 i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003949</pre>
3950
3951<h5>Overview:</h5>
3952
3953
3954<p>
3955The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00003956a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
3957no
3958effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00003959characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003960</p>
3961
3962<h5>Arguments:</h5>
3963
3964<p>
3965<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
3966determining if the fetch should be for a read (0) or write (1), and
3967<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00003968locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00003969<tt>locality</tt> arguments must be constant integers.
3970</p>
3971
3972<h5>Semantics:</h5>
3973
3974<p>
3975This intrinsic does not modify the behavior of the program. In particular,
3976prefetches cannot trap and do not produce a value. On targets that support this
3977intrinsic, the prefetch can provide hints to the processor cache for better
3978performance.
3979</p>
3980
3981</div>
3982
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003983<!-- _______________________________________________________________________ -->
3984<div class="doc_subsubsection">
3985 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
3986</div>
3987
3988<div class="doc_text">
3989
3990<h5>Syntax:</h5>
3991<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003992 declare void %llvm.pcmarker( i32 &lt;id&gt; )
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00003993</pre>
3994
3995<h5>Overview:</h5>
3996
3997
3998<p>
John Criswellfc6b8952005-05-16 16:17:45 +00003999The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4000(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004001code to simulators and other tools. The method is target specific, but it is
4002expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00004003The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnerd07c3f42005-11-15 06:07:55 +00004004after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb3e7afd2006-03-24 07:16:10 +00004005optimizations. The intended use is to be inserted after optimizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00004006correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004007</p>
4008
4009<h5>Arguments:</h5>
4010
4011<p>
4012<tt>id</tt> is a numerical id identifying the marker.
4013</p>
4014
4015<h5>Semantics:</h5>
4016
4017<p>
4018This intrinsic does not modify the behavior of the program. Backends that do not
4019support this intrinisic may ignore it.
4020</p>
4021
4022</div>
4023
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004024<!-- _______________________________________________________________________ -->
4025<div class="doc_subsubsection">
4026 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
4027</div>
4028
4029<div class="doc_text">
4030
4031<h5>Syntax:</h5>
4032<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004033 declare i64 %llvm.readcyclecounter( )
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004034</pre>
4035
4036<h5>Overview:</h5>
4037
4038
4039<p>
4040The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4041counter register (or similar low latency, high accuracy clocks) on those targets
4042that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4043As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4044should only be used for small timings.
4045</p>
4046
4047<h5>Semantics:</h5>
4048
4049<p>
4050When directly supported, reading the cycle counter should not modify any memory.
4051Implementations are allowed to either return a application specific value or a
4052system wide value. On backends without support, this is lowered to a constant 0.
4053</p>
4054
4055</div>
4056
Chris Lattner10610642004-02-14 04:08:35 +00004057<!-- ======================================================================= -->
4058<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00004059 <a name="int_libc">Standard C Library Intrinsics</a>
4060</div>
4061
4062<div class="doc_text">
4063<p>
Chris Lattner10610642004-02-14 04:08:35 +00004064LLVM provides intrinsics for a few important standard C library functions.
4065These intrinsics allow source-language front-ends to pass information about the
4066alignment of the pointer arguments to the code generator, providing opportunity
4067for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004068</p>
4069
4070</div>
4071
4072<!-- _______________________________________________________________________ -->
4073<div class="doc_subsubsection">
4074 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
4075</div>
4076
4077<div class="doc_text">
4078
4079<h5>Syntax:</h5>
4080<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004081 declare void %llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4082 i32 &lt;len&gt;, i32 &lt;align&gt;)
4083 declare void %llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4084 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004085</pre>
4086
4087<h5>Overview:</h5>
4088
4089<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004090The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004091location to the destination location.
4092</p>
4093
4094<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004095Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4096intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004097</p>
4098
4099<h5>Arguments:</h5>
4100
4101<p>
4102The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004103the source. The third argument is an integer argument
Chris Lattner33aec9e2004-02-12 17:01:32 +00004104specifying the number of bytes to copy, and the fourth argument is the alignment
4105of the source and destination locations.
4106</p>
4107
Chris Lattner3301ced2004-02-12 21:18:15 +00004108<p>
4109If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004110the caller guarantees that both the source and destination pointers are aligned
4111to that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004112</p>
4113
Chris Lattner33aec9e2004-02-12 17:01:32 +00004114<h5>Semantics:</h5>
4115
4116<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004117The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004118location to the destination location, which are not allowed to overlap. It
4119copies "len" bytes of memory over. If the argument is known to be aligned to
4120some boundary, this can be specified as the fourth argument, otherwise it should
4121be set to 0 or 1.
4122</p>
4123</div>
4124
4125
Chris Lattner0eb51b42004-02-12 18:10:10 +00004126<!-- _______________________________________________________________________ -->
4127<div class="doc_subsubsection">
4128 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
4129</div>
4130
4131<div class="doc_text">
4132
4133<h5>Syntax:</h5>
4134<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004135 declare void %llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4136 i32 &lt;len&gt;, i32 &lt;align&gt;)
4137 declare void %llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4138 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00004139</pre>
4140
4141<h5>Overview:</h5>
4142
4143<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004144The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4145location to the destination location. It is similar to the
4146'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004147</p>
4148
4149<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004150Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4151intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004152</p>
4153
4154<h5>Arguments:</h5>
4155
4156<p>
4157The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004158the source. The third argument is an integer argument
Chris Lattner0eb51b42004-02-12 18:10:10 +00004159specifying the number of bytes to copy, and the fourth argument is the alignment
4160of the source and destination locations.
4161</p>
4162
Chris Lattner3301ced2004-02-12 21:18:15 +00004163<p>
4164If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004165the caller guarantees that the source and destination pointers are aligned to
4166that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004167</p>
4168
Chris Lattner0eb51b42004-02-12 18:10:10 +00004169<h5>Semantics:</h5>
4170
4171<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004172The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner0eb51b42004-02-12 18:10:10 +00004173location to the destination location, which may overlap. It
4174copies "len" bytes of memory over. If the argument is known to be aligned to
4175some boundary, this can be specified as the fourth argument, otherwise it should
4176be set to 0 or 1.
4177</p>
4178</div>
4179
Chris Lattner8ff75902004-01-06 05:31:32 +00004180
Chris Lattner10610642004-02-14 04:08:35 +00004181<!-- _______________________________________________________________________ -->
4182<div class="doc_subsubsection">
Chris Lattner5b310c32006-03-03 00:07:20 +00004183 <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner10610642004-02-14 04:08:35 +00004184</div>
4185
4186<div class="doc_text">
4187
4188<h5>Syntax:</h5>
4189<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004190 declare void %llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
4191 i32 &lt;len&gt;, i32 &lt;align&gt;)
4192 declare void %llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
4193 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004194</pre>
4195
4196<h5>Overview:</h5>
4197
4198<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004199The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner10610642004-02-14 04:08:35 +00004200byte value.
4201</p>
4202
4203<p>
4204Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4205does not return a value, and takes an extra alignment argument.
4206</p>
4207
4208<h5>Arguments:</h5>
4209
4210<p>
4211The first argument is a pointer to the destination to fill, the second is the
Chris Lattner5b310c32006-03-03 00:07:20 +00004212byte value to fill it with, the third argument is an integer
Chris Lattner10610642004-02-14 04:08:35 +00004213argument specifying the number of bytes to fill, and the fourth argument is the
4214known alignment of destination location.
4215</p>
4216
4217<p>
4218If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004219the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner10610642004-02-14 04:08:35 +00004220</p>
4221
4222<h5>Semantics:</h5>
4223
4224<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004225The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4226the
Chris Lattner10610642004-02-14 04:08:35 +00004227destination location. If the argument is known to be aligned to some boundary,
4228this can be specified as the fourth argument, otherwise it should be set to 0 or
42291.
4230</p>
4231</div>
4232
4233
Chris Lattner32006282004-06-11 02:28:03 +00004234<!-- _______________________________________________________________________ -->
4235<div class="doc_subsubsection">
Chris Lattnerec6cb612006-01-16 22:38:59 +00004236 <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattnera4d74142005-07-21 01:29:16 +00004237</div>
4238
4239<div class="doc_text">
4240
4241<h5>Syntax:</h5>
4242<pre>
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004243 declare float %llvm.sqrt.f32(float %Val)
4244 declare double %llvm.sqrt.f64(double %Val)
Chris Lattnera4d74142005-07-21 01:29:16 +00004245</pre>
4246
4247<h5>Overview:</h5>
4248
4249<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004250The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattnera4d74142005-07-21 01:29:16 +00004251returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
4252<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
4253negative numbers (which allows for better optimization).
4254</p>
4255
4256<h5>Arguments:</h5>
4257
4258<p>
4259The argument and return value are floating point numbers of the same type.
4260</p>
4261
4262<h5>Semantics:</h5>
4263
4264<p>
4265This function returns the sqrt of the specified operand if it is a positive
4266floating point number.
4267</p>
4268</div>
4269
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004270<!-- _______________________________________________________________________ -->
4271<div class="doc_subsubsection">
4272 <a name="i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
4273</div>
4274
4275<div class="doc_text">
4276
4277<h5>Syntax:</h5>
4278<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004279 declare float %llvm.powi.f32(float %Val, i32 %power)
4280 declare double %llvm.powi.f64(double %Val, i32 %power)
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004281</pre>
4282
4283<h5>Overview:</h5>
4284
4285<p>
4286The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4287specified (positive or negative) power. The order of evaluation of
4288multiplications is not defined.
4289</p>
4290
4291<h5>Arguments:</h5>
4292
4293<p>
4294The second argument is an integer power, and the first is a value to raise to
4295that power.
4296</p>
4297
4298<h5>Semantics:</h5>
4299
4300<p>
4301This function returns the first value raised to the second power with an
4302unspecified sequence of rounding operations.</p>
4303</div>
4304
4305
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004306<!-- ======================================================================= -->
4307<div class="doc_subsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00004308 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004309</div>
4310
4311<div class="doc_text">
4312<p>
Nate Begeman7e36c472006-01-13 23:26:38 +00004313LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004314These allow efficient code generation for some algorithms.
4315</p>
4316
4317</div>
4318
4319<!-- _______________________________________________________________________ -->
4320<div class="doc_subsubsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00004321 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
4322</div>
4323
4324<div class="doc_text">
4325
4326<h5>Syntax:</h5>
4327<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004328 declare i16 %llvm.bswap.i16(i16 &lt;id&gt;)
4329 declare i32 %llvm.bswap.i32(i32 &lt;id&gt;)
4330 declare i64 %llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman7e36c472006-01-13 23:26:38 +00004331</pre>
4332
4333<h5>Overview:</h5>
4334
4335<p>
4336The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
433764 bit quantity. These are useful for performing operations on data that is not
4338in the target's native byte order.
4339</p>
4340
4341<h5>Semantics:</h5>
4342
4343<p>
Reid Spencerca86e162006-12-31 07:07:53 +00004344The <tt>llvm.bswap.16</tt> intrinsic returns an i16 value that has the high
4345and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
4346intrinsic returns an i32 value that has the four bytes of the input i32
4347swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
4348i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt>
4349intrinsic extends this concept to 64 bits.
Nate Begeman7e36c472006-01-13 23:26:38 +00004350</p>
4351
4352</div>
4353
4354<!-- _______________________________________________________________________ -->
4355<div class="doc_subsubsection">
Reid Spencer0b118202006-01-16 21:12:35 +00004356 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004357</div>
4358
4359<div class="doc_text">
4360
4361<h5>Syntax:</h5>
4362<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004363 declare i8 %llvm.ctpop.i8 (i8 &lt;src&gt;)
4364 declare i16 %llvm.ctpop.i16(i16 &lt;src&gt;)
4365 declare i32 %llvm.ctpop.i32(i32 &lt;src&gt;)
4366 declare i64 %llvm.ctpop.i64(i64 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004367</pre>
4368
4369<h5>Overview:</h5>
4370
4371<p>
Chris Lattnerec6cb612006-01-16 22:38:59 +00004372The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4373value.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004374</p>
4375
4376<h5>Arguments:</h5>
4377
4378<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00004379The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004380integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004381</p>
4382
4383<h5>Semantics:</h5>
4384
4385<p>
4386The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4387</p>
4388</div>
4389
4390<!-- _______________________________________________________________________ -->
4391<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00004392 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004393</div>
4394
4395<div class="doc_text">
4396
4397<h5>Syntax:</h5>
4398<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004399 declare i8 %llvm.ctlz.i8 (i8 &lt;src&gt;)
4400 declare i16 %llvm.ctlz.i16(i16 &lt;src&gt;)
4401 declare i32 %llvm.ctlz.i32(i32 &lt;src&gt;)
4402 declare i64 %llvm.ctlz.i64(i64 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004403</pre>
4404
4405<h5>Overview:</h5>
4406
4407<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004408The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4409leading zeros in a variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004410</p>
4411
4412<h5>Arguments:</h5>
4413
4414<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00004415The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004416integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004417</p>
4418
4419<h5>Semantics:</h5>
4420
4421<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00004422The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4423in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerca86e162006-12-31 07:07:53 +00004424of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004425</p>
4426</div>
Chris Lattner32006282004-06-11 02:28:03 +00004427
4428
Chris Lattnereff29ab2005-05-15 19:39:26 +00004429
4430<!-- _______________________________________________________________________ -->
4431<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00004432 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnereff29ab2005-05-15 19:39:26 +00004433</div>
4434
4435<div class="doc_text">
4436
4437<h5>Syntax:</h5>
4438<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00004439 declare i8 %llvm.cttz.i8 (i8 &lt;src&gt;)
4440 declare i16 %llvm.cttz.i16(i16 &lt;src&gt;)
4441 declare i32 %llvm.cttz.i32(i32 &lt;src&gt;)
4442 declare i64 %llvm.cttz.i64(i64 &lt;src&gt;)
Chris Lattnereff29ab2005-05-15 19:39:26 +00004443</pre>
4444
4445<h5>Overview:</h5>
4446
4447<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004448The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
4449trailing zeros.
Chris Lattnereff29ab2005-05-15 19:39:26 +00004450</p>
4451
4452<h5>Arguments:</h5>
4453
4454<p>
4455The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004456integer type. The return type must match the argument type.
Chris Lattnereff29ab2005-05-15 19:39:26 +00004457</p>
4458
4459<h5>Semantics:</h5>
4460
4461<p>
4462The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
4463in a variable. If the src == 0 then the result is the size in bits of the type
4464of src. For example, <tt>llvm.cttz(2) = 1</tt>.
4465</p>
4466</div>
4467
Chris Lattner8ff75902004-01-06 05:31:32 +00004468<!-- ======================================================================= -->
4469<div class="doc_subsection">
4470 <a name="int_debugger">Debugger Intrinsics</a>
4471</div>
4472
4473<div class="doc_text">
4474<p>
4475The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
4476are described in the <a
4477href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
4478Debugging</a> document.
4479</p>
4480</div>
4481
4482
Chris Lattner00950542001-06-06 20:29:01 +00004483<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00004484<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00004485<address>
4486 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
4487 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
4488 <a href="http://validator.w3.org/check/referer"><img
4489 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
4490
4491 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00004492 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00004493 Last modified: $Date$
4494</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00004495</body>
4496</html>