blob: 807d1047f61dc2c306089215ef0a851410b06d96 [file] [log] [blame]
Misha Brukmanc501f552004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner0132aff2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +000027 <li><a href="#paramattrs">Parameter Attributes</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000028 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Reid Spencer50c723a2007-02-19 23:54:10 +000029 <li><a href="#datalayout">Data Layout</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000030 </ol>
31 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000032 <li><a href="#typesystem">Type System</a>
33 <ol>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000034 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000035 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000036 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000037 </ol>
38 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000039 <li><a href="#t_derived">Derived Types</a>
40 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000041 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000042 <li><a href="#t_function">Function Type</a></li>
43 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000044 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth8df88e22006-12-08 17:13:00 +000045 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer404a3252007-02-15 03:07:05 +000046 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000047 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000048 </ol>
49 </li>
50 </ol>
51 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000052 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000053 <ol>
54 <li><a href="#simpleconstants">Simple Constants</a>
55 <li><a href="#aggregateconstants">Aggregate Constants</a>
56 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
57 <li><a href="#undefvalues">Undefined Values</a>
58 <li><a href="#constantexprs">Constant Expressions</a>
59 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000060 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000061 <li><a href="#othervalues">Other Values</a>
62 <ol>
63 <li><a href="#inlineasm">Inline Assembler Expressions</a>
64 </ol>
65 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000066 <li><a href="#instref">Instruction Reference</a>
67 <ol>
68 <li><a href="#terminators">Terminator Instructions</a>
69 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000070 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
71 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000072 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
73 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000074 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000075 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000076 </ol>
77 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000078 <li><a href="#binaryops">Binary Operations</a>
79 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000080 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
81 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
82 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +000083 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
84 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
85 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +000086 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
87 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
88 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000089 </ol>
90 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000091 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
92 <ol>
Reid Spencer2ab01932007-02-02 13:57:07 +000093 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
94 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
95 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000096 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000097 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000098 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000099 </ol>
100 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000101 <li><a href="#vectorops">Vector Operations</a>
102 <ol>
103 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
104 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
105 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000106 </ol>
107 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000108 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000109 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000110 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
111 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
112 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000113 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
114 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
115 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000116 </ol>
117 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000118 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000119 <ol>
120 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
121 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
122 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
123 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
124 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000125 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
126 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
127 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
128 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000129 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
130 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000131 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000132 </ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000133 <li><a href="#otherops">Other Operations</a>
134 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000135 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
136 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000137 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000138 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000139 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000140 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000141 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000142 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000143 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000144 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000145 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000146 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000147 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
148 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000149 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
150 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
151 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000152 </ol>
153 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000154 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
155 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000156 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
157 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
158 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000159 </ol>
160 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000161 <li><a href="#int_codegen">Code Generator Intrinsics</a>
162 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000163 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
164 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
165 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
166 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
167 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
168 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
169 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000170 </ol>
171 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000172 <li><a href="#int_libc">Standard C Library Intrinsics</a>
173 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000174 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
175 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
176 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
177 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
178 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000179 </ol>
180 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000181 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000182 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000183 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000184 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
185 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
186 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Reid Spencer5bf54c82007-04-11 23:23:49 +0000187 <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li>
188 <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000189 </ol>
190 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000191 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskey2211f492007-03-14 19:31:19 +0000192 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000193 </ol>
194 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000195</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000196
197<div class="doc_author">
198 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
199 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000200</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000201
Chris Lattner2f7c9632001-06-06 20:29:01 +0000202<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000203<div class="doc_section"> <a name="abstract">Abstract </a></div>
204<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000205
Misha Brukman76307852003-11-08 01:05:38 +0000206<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000207<p>This document is a reference manual for the LLVM assembly language.
208LLVM is an SSA based representation that provides type safety,
209low-level operations, flexibility, and the capability of representing
210'all' high-level languages cleanly. It is the common code
211representation used throughout all phases of the LLVM compilation
212strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000213</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000214
Chris Lattner2f7c9632001-06-06 20:29:01 +0000215<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000216<div class="doc_section"> <a name="introduction">Introduction</a> </div>
217<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000218
Misha Brukman76307852003-11-08 01:05:38 +0000219<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000220
Chris Lattner48b383b02003-11-25 01:02:51 +0000221<p>The LLVM code representation is designed to be used in three
222different forms: as an in-memory compiler IR, as an on-disk bytecode
223representation (suitable for fast loading by a Just-In-Time compiler),
224and as a human readable assembly language representation. This allows
225LLVM to provide a powerful intermediate representation for efficient
226compiler transformations and analysis, while providing a natural means
227to debug and visualize the transformations. The three different forms
228of LLVM are all equivalent. This document describes the human readable
229representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000230
John Criswell4a3327e2005-05-13 22:25:59 +0000231<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000232while being expressive, typed, and extensible at the same time. It
233aims to be a "universal IR" of sorts, by being at a low enough level
234that high-level ideas may be cleanly mapped to it (similar to how
235microprocessors are "universal IR's", allowing many source languages to
236be mapped to them). By providing type information, LLVM can be used as
237the target of optimizations: for example, through pointer analysis, it
238can be proven that a C automatic variable is never accessed outside of
239the current function... allowing it to be promoted to a simple SSA
240value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000241
Misha Brukman76307852003-11-08 01:05:38 +0000242</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000243
Chris Lattner2f7c9632001-06-06 20:29:01 +0000244<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000245<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000246
Misha Brukman76307852003-11-08 01:05:38 +0000247<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000248
Chris Lattner48b383b02003-11-25 01:02:51 +0000249<p>It is important to note that this document describes 'well formed'
250LLVM assembly language. There is a difference between what the parser
251accepts and what is considered 'well formed'. For example, the
252following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000253
254<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000255 %x = <a href="#i_add">add</a> i32 1, %x
Chris Lattner757528b0b2004-05-23 21:06:01 +0000256</pre>
257
Chris Lattner48b383b02003-11-25 01:02:51 +0000258<p>...because the definition of <tt>%x</tt> does not dominate all of
259its uses. The LLVM infrastructure provides a verification pass that may
260be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000261automatically run by the parser after parsing input assembly and by
Chris Lattner48b383b02003-11-25 01:02:51 +0000262the optimizer before it outputs bytecode. The violations pointed out
263by the verifier pass indicate bugs in transformation passes or input to
264the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000265
Chris Lattner48b383b02003-11-25 01:02:51 +0000266<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000267
Chris Lattner2f7c9632001-06-06 20:29:01 +0000268<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000269<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000270<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000271
Misha Brukman76307852003-11-08 01:05:38 +0000272<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000273
Chris Lattner48b383b02003-11-25 01:02:51 +0000274<p>LLVM uses three different forms of identifiers, for different
275purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000276
Chris Lattner2f7c9632001-06-06 20:29:01 +0000277<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000278 <li>Named values are represented as a string of characters with a '%' prefix.
279 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
280 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
281 Identifiers which require other characters in their names can be surrounded
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000282 with quotes. In this way, anything except a <tt>&quot;</tt> character can be used
Chris Lattnerd79749a2004-12-09 16:36:40 +0000283 in a name.</li>
284
285 <li>Unnamed values are represented as an unsigned numeric value with a '%'
286 prefix. For example, %12, %2, %44.</li>
287
Reid Spencer8f08d802004-12-09 18:02:53 +0000288 <li>Constants, which are described in a <a href="#constants">section about
289 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000290</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000291
292<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
293don't need to worry about name clashes with reserved words, and the set of
294reserved words may be expanded in the future without penalty. Additionally,
295unnamed identifiers allow a compiler to quickly come up with a temporary
296variable without having to avoid symbol table conflicts.</p>
297
Chris Lattner48b383b02003-11-25 01:02:51 +0000298<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5b950642006-11-11 23:08:07 +0000299languages. There are keywords for different opcodes
300('<tt><a href="#i_add">add</a></tt>',
301 '<tt><a href="#i_bitcast">bitcast</a></tt>',
302 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000303href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnerd79749a2004-12-09 16:36:40 +0000304and others. These reserved words cannot conflict with variable names, because
305none of them start with a '%' character.</p>
306
307<p>Here is an example of LLVM code to multiply the integer variable
308'<tt>%X</tt>' by 8:</p>
309
Misha Brukman76307852003-11-08 01:05:38 +0000310<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000311
312<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000313 %result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnerd79749a2004-12-09 16:36:40 +0000314</pre>
315
Misha Brukman76307852003-11-08 01:05:38 +0000316<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000317
318<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000319 %result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnerd79749a2004-12-09 16:36:40 +0000320</pre>
321
Misha Brukman76307852003-11-08 01:05:38 +0000322<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000323
324<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000325 <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
326 <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
327 %result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnerd79749a2004-12-09 16:36:40 +0000328</pre>
329
Chris Lattner48b383b02003-11-25 01:02:51 +0000330<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
331important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000332
Chris Lattner2f7c9632001-06-06 20:29:01 +0000333<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000334
335 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
336 line.</li>
337
338 <li>Unnamed temporaries are created when the result of a computation is not
339 assigned to a named value.</li>
340
Misha Brukman76307852003-11-08 01:05:38 +0000341 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000342
Misha Brukman76307852003-11-08 01:05:38 +0000343</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000344
John Criswell02fdc6f2005-05-12 16:52:32 +0000345<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000346demonstrating instructions, we will follow an instruction with a comment that
347defines the type and name of value produced. Comments are shown in italic
348text.</p>
349
Misha Brukman76307852003-11-08 01:05:38 +0000350</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000351
352<!-- *********************************************************************** -->
353<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
354<!-- *********************************************************************** -->
355
356<!-- ======================================================================= -->
357<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
358</div>
359
360<div class="doc_text">
361
362<p>LLVM programs are composed of "Module"s, each of which is a
363translation unit of the input programs. Each module consists of
364functions, global variables, and symbol table entries. Modules may be
365combined together with the LLVM linker, which merges function (and
366global variable) definitions, resolves forward declarations, and merges
367symbol table entries. Here is an example of the "hello world" module:</p>
368
369<pre><i>; Declare the string constant as a global constant...</i>
370<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000371 href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000372
373<i>; External declaration of the puts function</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000374<a href="#functionstructure">declare</a> i32 %puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000375
376<i>; Definition of main function</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000377define i32 %main() { <i>; i32()* </i>
378 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000379 %cast210 = <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000380 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* %.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000381
382 <i>; Call puts function to write out the string to stdout...</i>
383 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000384 href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000385 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000386 href="#i_ret">ret</a> i32 0<br>}<br></pre>
Chris Lattner6af02f32004-12-09 16:11:40 +0000387
388<p>This example is made up of a <a href="#globalvars">global variable</a>
389named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
390function, and a <a href="#functionstructure">function definition</a>
391for "<tt>main</tt>".</p>
392
Chris Lattnerd79749a2004-12-09 16:36:40 +0000393<p>In general, a module is made up of a list of global values,
394where both functions and global variables are global values. Global values are
395represented by a pointer to a memory location (in this case, a pointer to an
396array of char, and a pointer to a function), and have one of the following <a
397href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000398
Chris Lattnerd79749a2004-12-09 16:36:40 +0000399</div>
400
401<!-- ======================================================================= -->
402<div class="doc_subsection">
403 <a name="linkage">Linkage Types</a>
404</div>
405
406<div class="doc_text">
407
408<p>
409All Global Variables and Functions have one of the following types of linkage:
410</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000411
412<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000413
Chris Lattner6af02f32004-12-09 16:11:40 +0000414 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000415
416 <dd>Global values with internal linkage are only directly accessible by
417 objects in the current module. In particular, linking code into a module with
418 an internal global value may cause the internal to be renamed as necessary to
419 avoid collisions. Because the symbol is internal to the module, all
420 references can be updated. This corresponds to the notion of the
Chris Lattnere20b4702007-01-14 06:51:48 +0000421 '<tt>static</tt>' keyword in C.
Chris Lattner6af02f32004-12-09 16:11:40 +0000422 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000423
Chris Lattner6af02f32004-12-09 16:11:40 +0000424 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000425
Chris Lattnere20b4702007-01-14 06:51:48 +0000426 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
427 the same name when linkage occurs. This is typically used to implement
428 inline functions, templates, or other code which must be generated in each
429 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
430 allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000431 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000432
Chris Lattner6af02f32004-12-09 16:11:40 +0000433 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000434
435 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
436 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattnere20b4702007-01-14 06:51:48 +0000437 used for globals that may be emitted in multiple translation units, but that
438 are not guaranteed to be emitted into every translation unit that uses them.
439 One example of this are common globals in C, such as "<tt>int X;</tt>" at
440 global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000441 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000442
Chris Lattner6af02f32004-12-09 16:11:40 +0000443 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000444
445 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
446 pointer to array type. When two global variables with appending linkage are
447 linked together, the two global arrays are appended together. This is the
448 LLVM, typesafe, equivalent of having the system linker append together
449 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000450 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000451
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000452 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
453 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
454 until linked, if not linked, the symbol becomes null instead of being an
455 undefined reference.
456 </dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000457
Chris Lattner6af02f32004-12-09 16:11:40 +0000458 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000459
460 <dd>If none of the above identifiers are used, the global is externally
461 visible, meaning that it participates in linkage and can be used to resolve
462 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000463 </dd>
Reid Spencer7972c472007-04-11 23:49:50 +0000464</dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000465
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000466 <p>
467 The next two types of linkage are targeted for Microsoft Windows platform
468 only. They are designed to support importing (exporting) symbols from (to)
469 DLLs.
470 </p>
471
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000472 <dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000473 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
474
475 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
476 or variable via a global pointer to a pointer that is set up by the DLL
477 exporting the symbol. On Microsoft Windows targets, the pointer name is
478 formed by combining <code>_imp__</code> and the function or variable name.
479 </dd>
480
481 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
482
483 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
484 pointer to a pointer in a DLL, so that it can be referenced with the
485 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
486 name is formed by combining <code>_imp__</code> and the function or variable
487 name.
488 </dd>
489
Chris Lattner6af02f32004-12-09 16:11:40 +0000490</dl>
491
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000492<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattner6af02f32004-12-09 16:11:40 +0000493variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
494variable and was linked with this one, one of the two would be renamed,
495preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
496external (i.e., lacking any linkage declarations), they are accessible
Reid Spencer92c671e2007-01-05 00:59:10 +0000497outside of the current module.</p>
498<p>It is illegal for a function <i>declaration</i>
499to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000500or <tt>extern_weak</tt>.</p>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000501<p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt>
502linkages.
Chris Lattner6af02f32004-12-09 16:11:40 +0000503</div>
504
505<!-- ======================================================================= -->
506<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000507 <a name="callingconv">Calling Conventions</a>
508</div>
509
510<div class="doc_text">
511
512<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
513and <a href="#i_invoke">invokes</a> can all have an optional calling convention
514specified for the call. The calling convention of any pair of dynamic
515caller/callee must match, or the behavior of the program is undefined. The
516following calling conventions are supported by LLVM, and more may be added in
517the future:</p>
518
519<dl>
520 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
521
522 <dd>This calling convention (the default if no other calling convention is
523 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000524 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencer72ba4992006-12-31 21:30:18 +0000525 prototype and implemented declaration of the function (as does normal C).
Chris Lattner0132aff2005-05-06 22:57:40 +0000526 </dd>
527
528 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
529
530 <dd>This calling convention attempts to make calls as fast as possible
531 (e.g. by passing things in registers). This calling convention allows the
532 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000533 without having to conform to an externally specified ABI. Implementations of
534 this convention should allow arbitrary tail call optimization to be supported.
535 This calling convention does not support varargs and requires the prototype of
536 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000537 </dd>
538
539 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
540
541 <dd>This calling convention attempts to make code in the caller as efficient
542 as possible under the assumption that the call is not commonly executed. As
543 such, these calls often preserve all registers so that the call does not break
544 any live ranges in the caller side. This calling convention does not support
545 varargs and requires the prototype of all callees to exactly match the
546 prototype of the function definition.
547 </dd>
548
Chris Lattner573f64e2005-05-07 01:46:40 +0000549 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000550
551 <dd>Any calling convention may be specified by number, allowing
552 target-specific calling conventions to be used. Target specific calling
553 conventions start at 64.
554 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000555</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000556
557<p>More calling conventions can be added/defined on an as-needed basis, to
558support pascal conventions or any other well-known target-independent
559convention.</p>
560
561</div>
562
563<!-- ======================================================================= -->
564<div class="doc_subsection">
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000565 <a name="visibility">Visibility Styles</a>
566</div>
567
568<div class="doc_text">
569
570<p>
571All Global Variables and Functions have one of the following visibility styles:
572</p>
573
574<dl>
575 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
576
577 <dd>On ELF, default visibility means that the declaration is visible to other
578 modules and, in shared libraries, means that the declared entity may be
579 overridden. On Darwin, default visibility means that the declaration is
580 visible to other modules. Default visibility corresponds to "external
581 linkage" in the language.
582 </dd>
583
584 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
585
586 <dd>Two declarations of an object with hidden visibility refer to the same
587 object if they are in the same shared object. Usually, hidden visibility
588 indicates that the symbol will not be placed into the dynamic symbol table,
589 so no other module (executable or shared library) can reference it
590 directly.
591 </dd>
592
593</dl>
594
595</div>
596
597<!-- ======================================================================= -->
598<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000599 <a name="globalvars">Global Variables</a>
600</div>
601
602<div class="doc_text">
603
Chris Lattner5d5aede2005-02-12 19:30:21 +0000604<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000605instead of run-time. Global variables may optionally be initialized, may have
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000606an explicit section to be placed in, and may have an optional explicit alignment
607specified. A variable may be defined as "thread_local", which means that it
608will not be shared by threads (each thread will have a separated copy of the
609variable). A variable may be defined as a global "constant," which indicates
610that the contents of the variable will <b>never</b> be modified (enabling better
Chris Lattner5d5aede2005-02-12 19:30:21 +0000611optimization, allowing the global data to be placed in the read-only section of
612an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000613cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000614
615<p>
616LLVM explicitly allows <em>declarations</em> of global variables to be marked
617constant, even if the final definition of the global is not. This capability
618can be used to enable slightly better optimization of the program, but requires
619the language definition to guarantee that optimizations based on the
620'constantness' are valid for the translation units that do not include the
621definition.
622</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000623
624<p>As SSA values, global variables define pointer values that are in
625scope (i.e. they dominate) all basic blocks in the program. Global
626variables always define a pointer to their "content" type because they
627describe a region of memory, and all memory objects in LLVM are
628accessed through pointers.</p>
629
Chris Lattner662c8722005-11-12 00:45:07 +0000630<p>LLVM allows an explicit section to be specified for globals. If the target
631supports it, it will emit globals to the section specified.</p>
632
Chris Lattner54611b42005-11-06 08:02:57 +0000633<p>An explicit alignment may be specified for a global. If not present, or if
634the alignment is set to zero, the alignment of the global is set by the target
635to whatever it feels convenient. If an explicit alignment is specified, the
636global is forced to have at least that much alignment. All alignments must be
637a power of 2.</p>
638
Chris Lattner5760c502007-01-14 00:27:09 +0000639<p>For example, the following defines a global with an initializer, section,
640 and alignment:</p>
641
642<pre>
643 %G = constant float 1.0, section "foo", align 4
644</pre>
645
Chris Lattner6af02f32004-12-09 16:11:40 +0000646</div>
647
648
649<!-- ======================================================================= -->
650<div class="doc_subsection">
651 <a name="functionstructure">Functions</a>
652</div>
653
654<div class="doc_text">
655
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000656<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
657an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000658<a href="#visibility">visibility style</a>, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000659<a href="#callingconv">calling convention</a>, a return type, an optional
660<a href="#paramattrs">parameter attribute</a> for the return type, a function
661name, a (possibly empty) argument list (each with optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000662<a href="#paramattrs">parameter attributes</a>), an optional section, an
663optional alignment, an opening curly brace, a list of basic blocks, and a
664closing curly brace.
665
666LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
667optional <a href="#linkage">linkage type</a>, an optional
668<a href="#visibility">visibility style</a>, an optional
669<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000670<a href="#paramattrs">parameter attribute</a> for the return type, a function
671name, a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000672
673<p>A function definition contains a list of basic blocks, forming the CFG for
674the function. Each basic block may optionally start with a label (giving the
675basic block a symbol table entry), contains a list of instructions, and ends
676with a <a href="#terminators">terminator</a> instruction (such as a branch or
677function return).</p>
678
John Criswell02fdc6f2005-05-12 16:52:32 +0000679<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000680executed on entrance to the function, and it is not allowed to have predecessor
681basic blocks (i.e. there can not be any branches to the entry block of a
682function). Because the block can have no predecessors, it also cannot have any
683<a href="#i_phi">PHI nodes</a>.</p>
684
685<p>LLVM functions are identified by their name and type signature. Hence, two
686functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000687considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000688appropriately.</p>
689
Chris Lattner662c8722005-11-12 00:45:07 +0000690<p>LLVM allows an explicit section to be specified for functions. If the target
691supports it, it will emit functions to the section specified.</p>
692
Chris Lattner54611b42005-11-06 08:02:57 +0000693<p>An explicit alignment may be specified for a function. If not present, or if
694the alignment is set to zero, the alignment of the function is set by the target
695to whatever it feels convenient. If an explicit alignment is specified, the
696function is forced to have at least that much alignment. All alignments must be
697a power of 2.</p>
698
Chris Lattner6af02f32004-12-09 16:11:40 +0000699</div>
700
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000701
702<!-- ======================================================================= -->
703<div class="doc_subsection">
704 <a name="aliasstructure">Aliases</a>
705</div>
706<div class="doc_text">
707 <p>Aliases act as "second name" for the aliasee value (which can be either
708 function or global variable). Aliases may have an
709 optional <a href="#linkage">linkage type</a>, and an
710 optional <a href="#visibility">visibility style</a>.</p>
711
712 <h5>Syntax:</h5>
713
714 <pre>
715 @&lt;Name&gt; = [Linkage] [Visibility] alias &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
716 </pre>
717
718</div>
719
720
721
Chris Lattner91c15c42006-01-23 23:23:47 +0000722<!-- ======================================================================= -->
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000723<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
724<div class="doc_text">
725 <p>The return type and each parameter of a function type may have a set of
726 <i>parameter attributes</i> associated with them. Parameter attributes are
727 used to communicate additional information about the result or parameters of
728 a function. Parameter attributes are considered to be part of the function
729 type so two functions types that differ only by the parameter attributes
730 are different function types.</p>
731
Reid Spencercf7ebf52007-01-15 18:27:39 +0000732 <p>Parameter attributes are simple keywords that follow the type specified. If
733 multiple parameter attributes are needed, they are space separated. For
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000734 example:</p><pre>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000735 %someFunc = i16 (i8 sext %someParam) zext
736 %someFunc = i16 (i8 zext %someParam) zext</pre>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000737 <p>Note that the two function types above are unique because the parameter has
Reid Spencercf7ebf52007-01-15 18:27:39 +0000738 a different attribute (sext in the first one, zext in the second). Also note
739 that the attribute for the function result (zext) comes immediately after the
740 argument list.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000741
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000742 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000743 <dl>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000744 <dt><tt>zext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000745 <dd>This indicates that the parameter should be zero extended just before
746 a call to this function.</dd>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000747 <dt><tt>sext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000748 <dd>This indicates that the parameter should be sign extended just before
749 a call to this function.</dd>
Anton Korobeynikove8166852007-01-28 14:30:45 +0000750 <dt><tt>inreg</tt></dt>
751 <dd>This indicates that the parameter should be placed in register (if
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000752 possible) during assembling function call. Support for this attribute is
753 target-specific</dd>
Anton Korobeynikove8166852007-01-28 14:30:45 +0000754 <dt><tt>sret</tt></dt>
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000755 <dd>This indicates that the parameter specifies the address of a structure
Reid Spencer05dbb9d2007-03-22 02:02:11 +0000756 that is the return value of the function in the source program.</dd>
Reid Spencer9d1700e2007-03-22 02:18:56 +0000757 <dt><tt>noreturn</tt></dt>
758 <dd>This function attribute indicates that the function never returns. This
759 indicates to LLVM that every call to this function should be treated as if
760 an <tt>unreachable</tt> instruction immediately followed the call.</dd>
Reid Spencer05dbb9d2007-03-22 02:02:11 +0000761 <dt><tt>nounwind</tt></dt>
762 <dd>This function attribute indicates that the function type does not use
763 the unwind instruction and does not allow stack unwinding to propagate
764 through it.</dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000765 </dl>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000766
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000767</div>
768
769<!-- ======================================================================= -->
Chris Lattner91c15c42006-01-23 23:23:47 +0000770<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +0000771 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +0000772</div>
773
774<div class="doc_text">
775<p>
776Modules may contain "module-level inline asm" blocks, which corresponds to the
777GCC "file scope inline asm" blocks. These blocks are internally concatenated by
778LLVM and treated as a single unit, but may be separated in the .ll file if
779desired. The syntax is very simple:
780</p>
781
782<div class="doc_code"><pre>
Chris Lattnera1280ad2006-01-24 00:37:20 +0000783 module asm "inline asm code goes here"
784 module asm "more can go here"
Chris Lattner91c15c42006-01-23 23:23:47 +0000785</pre></div>
786
787<p>The strings can contain any character by escaping non-printable characters.
788 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
789 for the number.
790</p>
791
792<p>
793 The inline asm code is simply printed to the machine code .s file when
794 assembly code is generated.
795</p>
796</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000797
Reid Spencer50c723a2007-02-19 23:54:10 +0000798<!-- ======================================================================= -->
799<div class="doc_subsection">
800 <a name="datalayout">Data Layout</a>
801</div>
802
803<div class="doc_text">
804<p>A module may specify a target specific data layout string that specifies how
Reid Spencer7972c472007-04-11 23:49:50 +0000805data is to be laid out in memory. The syntax for the data layout is simply:</p>
806<pre> target datalayout = "<i>layout specification</i>"</pre>
807<p>The <i>layout specification</i> consists of a list of specifications
808separated by the minus sign character ('-'). Each specification starts with a
809letter and may include other information after the letter to define some
810aspect of the data layout. The specifications accepted are as follows: </p>
Reid Spencer50c723a2007-02-19 23:54:10 +0000811<dl>
812 <dt><tt>E</tt></dt>
813 <dd>Specifies that the target lays out data in big-endian form. That is, the
814 bits with the most significance have the lowest address location.</dd>
815 <dt><tt>e</tt></dt>
816 <dd>Specifies that hte target lays out data in little-endian form. That is,
817 the bits with the least significance have the lowest address location.</dd>
818 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
819 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
820 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
821 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
822 too.</dd>
823 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
824 <dd>This specifies the alignment for an integer type of a given bit
825 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
826 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
827 <dd>This specifies the alignment for a vector type of a given bit
828 <i>size</i>.</dd>
829 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
830 <dd>This specifies the alignment for a floating point type of a given bit
831 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
832 (double).</dd>
833 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
834 <dd>This specifies the alignment for an aggregate type of a given bit
835 <i>size</i>.</dd>
836</dl>
837<p>When constructing the data layout for a given target, LLVM starts with a
838default set of specifications which are then (possibly) overriden by the
839specifications in the <tt>datalayout</tt> keyword. The default specifications
840are given in this list:</p>
841<ul>
842 <li><tt>E</tt> - big endian</li>
843 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
844 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
845 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
846 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
847 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
848 <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred
849 alignment of 64-bits</li>
850 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
851 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
852 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
853 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
854 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
855</ul>
856<p>When llvm is determining the alignment for a given type, it uses the
857following rules:
858<ol>
859 <li>If the type sought is an exact match for one of the specifications, that
860 specification is used.</li>
861 <li>If no match is found, and the type sought is an integer type, then the
862 smallest integer type that is larger than the bitwidth of the sought type is
863 used. If none of the specifications are larger than the bitwidth then the the
864 largest integer type is used. For example, given the default specifications
865 above, the i7 type will use the alignment of i8 (next largest) while both
866 i65 and i256 will use the alignment of i64 (largest specified).</li>
867 <li>If no match is found, and the type sought is a vector type, then the
868 largest vector type that is smaller than the sought vector type will be used
869 as a fall back. This happens because <128 x double> can be implemented in
870 terms of 64 <2 x double>, for example.</li>
871</ol>
872</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000873
Chris Lattner2f7c9632001-06-06 20:29:01 +0000874<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000875<div class="doc_section"> <a name="typesystem">Type System</a> </div>
876<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000877
Misha Brukman76307852003-11-08 01:05:38 +0000878<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000879
Misha Brukman76307852003-11-08 01:05:38 +0000880<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000881intermediate representation. Being typed enables a number of
882optimizations to be performed on the IR directly, without having to do
883extra analyses on the side before the transformation. A strong type
884system makes it easier to read the generated code and enables novel
885analyses and transformations that are not feasible to perform on normal
886three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000887
888</div>
889
Chris Lattner2f7c9632001-06-06 20:29:01 +0000890<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000891<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000892<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000893<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000894system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000895
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000896<table class="layout">
897 <tr class="layout">
898 <td class="left">
899 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000900 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000901 <tr><th>Type</th><th>Description</th></tr>
Duncan Sands16f122e2007-03-30 12:22:09 +0000902 <tr><td><tt><a name="t_void">void</a></tt></td><td>No value</td></tr>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000903 <tr><td><tt>i8</tt></td><td>8-bit value</td></tr>
904 <tr><td><tt>i32</tt></td><td>32-bit value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000905 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000906 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000907 </tbody>
908 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000909 </td>
910 <td class="right">
911 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000912 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000913 <tr><th>Type</th><th>Description</th></tr>
Reid Spencer36a15422007-01-12 03:35:51 +0000914 <tr><td><tt>i1</tt></td><td>True or False value</td></tr>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000915 <tr><td><tt>i16</tt></td><td>16-bit value</td></tr>
916 <tr><td><tt>i64</tt></td><td>64-bit value</td></tr>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000917 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000918 </tbody>
919 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000920 </td>
921 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000922</table>
Misha Brukman76307852003-11-08 01:05:38 +0000923</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000924
Chris Lattner2f7c9632001-06-06 20:29:01 +0000925<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000926<div class="doc_subsubsection"> <a name="t_classifications">Type
927Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000928<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000929<p>These different primitive types fall into a few useful
930classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000931
932<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000933 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000934 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000935 <tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000936 <td><a name="t_integer">integer</a></td>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000937 <td><tt>i1, i8, i16, i32, i64</tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000938 </tr>
939 <tr>
940 <td><a name="t_floating">floating point</a></td>
941 <td><tt>float, double</tt></td>
942 </tr>
943 <tr>
944 <td><a name="t_firstclass">first class</a></td>
Reid Spencer36a15422007-01-12 03:35:51 +0000945 <td><tt>i1, i8, i16, i32, i64, float, double, <br/>
Reid Spencer404a3252007-02-15 03:07:05 +0000946 <a href="#t_pointer">pointer</a>,<a href="#t_vector">vector</a></tt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000947 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000948 </tr>
949 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000950</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000951
Chris Lattner48b383b02003-11-25 01:02:51 +0000952<p>The <a href="#t_firstclass">first class</a> types are perhaps the
953most important. Values of these types are the only ones which can be
954produced by instructions, passed as arguments, or used as operands to
955instructions. This means that all structures and arrays must be
956manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000957</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000958
Chris Lattner2f7c9632001-06-06 20:29:01 +0000959<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000960<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000961
Misha Brukman76307852003-11-08 01:05:38 +0000962<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000963
Chris Lattner48b383b02003-11-25 01:02:51 +0000964<p>The real power in LLVM comes from the derived types in the system.
965This is what allows a programmer to represent arrays, functions,
966pointers, and other useful types. Note that these derived types may be
967recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000968
Misha Brukman76307852003-11-08 01:05:38 +0000969</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000970
Chris Lattner2f7c9632001-06-06 20:29:01 +0000971<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000972<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000973
Misha Brukman76307852003-11-08 01:05:38 +0000974<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000975
Chris Lattner2f7c9632001-06-06 20:29:01 +0000976<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000977
Misha Brukman76307852003-11-08 01:05:38 +0000978<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000979sequentially in memory. The array type requires a size (number of
980elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000981
Chris Lattner590645f2002-04-14 06:13:44 +0000982<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000983
984<pre>
985 [&lt;# elements&gt; x &lt;elementtype&gt;]
986</pre>
987
John Criswell02fdc6f2005-05-12 16:52:32 +0000988<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000989be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000990
Chris Lattner590645f2002-04-14 06:13:44 +0000991<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000992<table class="layout">
993 <tr class="layout">
994 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000995 <tt>[40 x i32 ]</tt><br/>
996 <tt>[41 x i32 ]</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +0000997 <tt>[40 x i8]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000998 </td>
999 <td class="left">
Reid Spencer3e628eb92007-01-04 16:43:23 +00001000 Array of 40 32-bit integer values.<br/>
1001 Array of 41 32-bit integer values.<br/>
1002 Array of 40 8-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001003 </td>
1004 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001005</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001006<p>Here are some examples of multidimensional arrays:</p>
1007<table class="layout">
1008 <tr class="layout">
1009 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001010 <tt>[3 x [4 x i32]]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001011 <tt>[12 x [10 x float]]</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001012 <tt>[2 x [3 x [4 x i16]]]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001013 </td>
1014 <td class="left">
Reid Spencer3e628eb92007-01-04 16:43:23 +00001015 3x4 array of 32-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001016 12x10 array of single precision floating point values.<br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001017 2x3x4 array of 16-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001018 </td>
1019 </tr>
1020</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001021
John Criswell4c0cf7f2005-10-24 16:17:18 +00001022<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1023length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001024LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1025As a special case, however, zero length arrays are recognized to be variable
1026length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001027type "{ i32, [0 x float]}", for example.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001028
Misha Brukman76307852003-11-08 01:05:38 +00001029</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001030
Chris Lattner2f7c9632001-06-06 20:29:01 +00001031<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001032<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001033<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001034<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001035<p>The function type can be thought of as a function signature. It
1036consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +00001037Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +00001038(which are structures of pointers to functions), for indirect function
1039calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +00001040<p>
1041The return type of a function type cannot be an aggregate type.
1042</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001043<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001044<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +00001045<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +00001046specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +00001047which indicates that the function takes a variable number of arguments.
1048Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001049 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001050<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001051<table class="layout">
1052 <tr class="layout">
Reid Spencer58c08712006-12-31 07:18:34 +00001053 <td class="left"><tt>i32 (i32)</tt></td>
1054 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001055 </td>
Reid Spencer58c08712006-12-31 07:18:34 +00001056 </tr><tr class="layout">
Reid Spencere6a338d2007-01-15 18:28:34 +00001057 <td class="left"><tt>float&nbsp;(i16&nbsp;sext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencer655dcc62006-12-31 07:20:23 +00001058 </tt></td>
Reid Spencer58c08712006-12-31 07:18:34 +00001059 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1060 an <tt>i16</tt> that should be sign extended and a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001061 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer58c08712006-12-31 07:18:34 +00001062 <tt>float</tt>.
1063 </td>
1064 </tr><tr class="layout">
1065 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1066 <td class="left">A vararg function that takes at least one
Reid Spencer3e628eb92007-01-04 16:43:23 +00001067 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer58c08712006-12-31 07:18:34 +00001068 which returns an integer. This is the signature for <tt>printf</tt> in
1069 LLVM.
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001070 </td>
1071 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001072</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001073
Misha Brukman76307852003-11-08 01:05:38 +00001074</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001075<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001076<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001077<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001078<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001079<p>The structure type is used to represent a collection of data members
1080together in memory. The packing of the field types is defined to match
1081the ABI of the underlying processor. The elements of a structure may
1082be any type that has a size.</p>
1083<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1084and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1085field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1086instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001087<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001088<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001089<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001090<table class="layout">
1091 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001092 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1093 <td class="left">A triple of three <tt>i32</tt> values</td>
1094 </tr><tr class="layout">
1095 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1096 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1097 second element is a <a href="#t_pointer">pointer</a> to a
1098 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1099 an <tt>i32</tt>.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001100 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001101</table>
Misha Brukman76307852003-11-08 01:05:38 +00001102</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001103
Chris Lattner2f7c9632001-06-06 20:29:01 +00001104<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001105<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1106</div>
1107<div class="doc_text">
1108<h5>Overview:</h5>
1109<p>The packed structure type is used to represent a collection of data members
1110together in memory. There is no padding between fields. Further, the alignment
1111of a packed structure is 1 byte. The elements of a packed structure may
1112be any type that has a size.</p>
1113<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1114and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1115field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1116instruction.</p>
1117<h5>Syntax:</h5>
1118<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1119<h5>Examples:</h5>
1120<table class="layout">
1121 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001122 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1123 <td class="left">A triple of three <tt>i32</tt> values</td>
1124 </tr><tr class="layout">
1125 <td class="left"><tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}&nbsp;&gt;</tt></td>
1126 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1127 second element is a <a href="#t_pointer">pointer</a> to a
1128 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1129 an <tt>i32</tt>.</td>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001130 </tr>
1131</table>
1132</div>
1133
1134<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001135<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001136<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001137<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001138<p>As in many languages, the pointer type represents a pointer or
1139reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +00001140<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001141<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001142<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001143<table class="layout">
1144 <tr class="layout">
1145 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001146 <tt>[4x i32]*</tt><br/>
1147 <tt>i32 (i32 *) *</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001148 </td>
1149 <td class="left">
1150 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001151 four <tt>i32</tt> values<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001152 A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001153 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
1154 <tt>i32</tt>.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001155 </td>
1156 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001157</table>
Misha Brukman76307852003-11-08 01:05:38 +00001158</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001159
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001160<!-- _______________________________________________________________________ -->
Reid Spencer404a3252007-02-15 03:07:05 +00001161<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001162<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001163
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001164<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001165
Reid Spencer404a3252007-02-15 03:07:05 +00001166<p>A vector type is a simple derived type that represents a vector
1167of elements. Vector types are used when multiple primitive data
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001168are operated in parallel using a single instruction (SIMD).
Reid Spencer404a3252007-02-15 03:07:05 +00001169A vector type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +00001170elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer404a3252007-02-15 03:07:05 +00001171of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001172considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001173
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001174<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001175
1176<pre>
1177 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1178</pre>
1179
John Criswell4a3327e2005-05-13 22:25:59 +00001180<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001181be any integer or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001182
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001183<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001184
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001185<table class="layout">
1186 <tr class="layout">
1187 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001188 <tt>&lt;4 x i32&gt;</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001189 <tt>&lt;8 x float&gt;</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001190 <tt>&lt;2 x i64&gt;</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001191 </td>
1192 <td class="left">
Reid Spencer404a3252007-02-15 03:07:05 +00001193 Vector of 4 32-bit integer values.<br/>
1194 Vector of 8 floating-point values.<br/>
1195 Vector of 2 64-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001196 </td>
1197 </tr>
1198</table>
Misha Brukman76307852003-11-08 01:05:38 +00001199</div>
1200
Chris Lattner37b6b092005-04-25 17:34:15 +00001201<!-- _______________________________________________________________________ -->
1202<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1203<div class="doc_text">
1204
1205<h5>Overview:</h5>
1206
1207<p>Opaque types are used to represent unknown types in the system. This
1208corresponds (for example) to the C notion of a foward declared structure type.
1209In LLVM, opaque types can eventually be resolved to any type (not just a
1210structure type).</p>
1211
1212<h5>Syntax:</h5>
1213
1214<pre>
1215 opaque
1216</pre>
1217
1218<h5>Examples:</h5>
1219
1220<table class="layout">
1221 <tr class="layout">
1222 <td class="left">
1223 <tt>opaque</tt>
1224 </td>
1225 <td class="left">
1226 An opaque type.<br/>
1227 </td>
1228 </tr>
1229</table>
1230</div>
1231
1232
Chris Lattner74d3f822004-12-09 17:30:23 +00001233<!-- *********************************************************************** -->
1234<div class="doc_section"> <a name="constants">Constants</a> </div>
1235<!-- *********************************************************************** -->
1236
1237<div class="doc_text">
1238
1239<p>LLVM has several different basic types of constants. This section describes
1240them all and their syntax.</p>
1241
1242</div>
1243
1244<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001245<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001246
1247<div class="doc_text">
1248
1249<dl>
1250 <dt><b>Boolean constants</b></dt>
1251
1252 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencer36a15422007-01-12 03:35:51 +00001253 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattner74d3f822004-12-09 17:30:23 +00001254 </dd>
1255
1256 <dt><b>Integer constants</b></dt>
1257
Reid Spencer8f08d802004-12-09 18:02:53 +00001258 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencer3e628eb92007-01-04 16:43:23 +00001259 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattner74d3f822004-12-09 17:30:23 +00001260 integer types.
1261 </dd>
1262
1263 <dt><b>Floating point constants</b></dt>
1264
1265 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1266 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +00001267 notation (see below). Floating point constants must have a <a
1268 href="#t_floating">floating point</a> type. </dd>
1269
1270 <dt><b>Null pointer constants</b></dt>
1271
John Criswelldfe6a862004-12-10 15:51:16 +00001272 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001273 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1274
1275</dl>
1276
John Criswelldfe6a862004-12-10 15:51:16 +00001277<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001278of floating point constants. For example, the form '<tt>double
12790x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
12804.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001281(and the only time that they are generated by the disassembler) is when a
1282floating point constant must be emitted but it cannot be represented as a
1283decimal floating point number. For example, NaN's, infinities, and other
1284special values are represented in their IEEE hexadecimal format so that
1285assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001286
1287</div>
1288
1289<!-- ======================================================================= -->
1290<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1291</div>
1292
1293<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +00001294<p>Aggregate constants arise from aggregation of simple constants
1295and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001296
1297<dl>
1298 <dt><b>Structure constants</b></dt>
1299
1300 <dd>Structure constants are represented with notation similar to structure
1301 type definitions (a comma separated list of elements, surrounded by braces
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001302 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* %G }</tt>",
1303 where "<tt>%G</tt>" is declared as "<tt>%G = external global i32</tt>". Structure constants
Chris Lattner455fc8c2005-03-07 22:13:59 +00001304 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001305 types of elements must match those specified by the type.
1306 </dd>
1307
1308 <dt><b>Array constants</b></dt>
1309
1310 <dd>Array constants are represented with notation similar to array type
1311 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001312 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001313 constants must have <a href="#t_array">array type</a>, and the number and
1314 types of elements must match those specified by the type.
1315 </dd>
1316
Reid Spencer404a3252007-02-15 03:07:05 +00001317 <dt><b>Vector constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001318
Reid Spencer404a3252007-02-15 03:07:05 +00001319 <dd>Vector constants are represented with notation similar to vector type
Chris Lattner74d3f822004-12-09 17:30:23 +00001320 definitions (a comma separated list of elements, surrounded by
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001321 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Jeff Cohen5819f182007-04-22 01:17:39 +00001322 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
Reid Spencer404a3252007-02-15 03:07:05 +00001323 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattner74d3f822004-12-09 17:30:23 +00001324 match those specified by the type.
1325 </dd>
1326
1327 <dt><b>Zero initialization</b></dt>
1328
1329 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1330 value to zero of <em>any</em> type, including scalar and aggregate types.
1331 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001332 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001333 initializers.
1334 </dd>
1335</dl>
1336
1337</div>
1338
1339<!-- ======================================================================= -->
1340<div class="doc_subsection">
1341 <a name="globalconstants">Global Variable and Function Addresses</a>
1342</div>
1343
1344<div class="doc_text">
1345
1346<p>The addresses of <a href="#globalvars">global variables</a> and <a
1347href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001348constants. These constants are explicitly referenced when the <a
1349href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001350href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1351file:</p>
1352
1353<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001354 %X = global i32 17
1355 %Y = global i32 42
1356 %Z = global [2 x i32*] [ i32* %X, i32* %Y ]
Chris Lattner74d3f822004-12-09 17:30:23 +00001357</pre>
1358
1359</div>
1360
1361<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001362<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001363<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001364 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001365 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001366 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001367
Reid Spencer641f5c92004-12-09 18:13:12 +00001368 <p>Undefined values indicate to the compiler that the program is well defined
1369 no matter what value is used, giving the compiler more freedom to optimize.
1370 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001371</div>
1372
1373<!-- ======================================================================= -->
1374<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1375</div>
1376
1377<div class="doc_text">
1378
1379<p>Constant expressions are used to allow expressions involving other constants
1380to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001381href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001382that does not have side effects (e.g. load and call are not supported). The
1383following is the syntax for constant expressions:</p>
1384
1385<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001386 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1387 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001388 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001389
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001390 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1391 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001392 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001393
1394 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1395 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001396 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001397
1398 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1399 <dd>Truncate a floating point constant to another floating point type. The
1400 size of CST must be larger than the size of TYPE. Both types must be
1401 floating point.</dd>
1402
1403 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1404 <dd>Floating point extend a constant to another type. The size of CST must be
1405 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1406
1407 <dt><b><tt>fp2uint ( CST to TYPE )</tt></b></dt>
1408 <dd>Convert a floating point constant to the corresponding unsigned integer
1409 constant. TYPE must be an integer type. CST must be floating point. If the
1410 value won't fit in the integer type, the results are undefined.</dd>
1411
Reid Spencer51b07252006-11-09 23:03:26 +00001412 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001413 <dd>Convert a floating point constant to the corresponding signed integer
1414 constant. TYPE must be an integer type. CST must be floating point. If the
1415 value won't fit in the integer type, the results are undefined.</dd>
1416
Reid Spencer51b07252006-11-09 23:03:26 +00001417 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001418 <dd>Convert an unsigned integer constant to the corresponding floating point
1419 constant. TYPE must be floating point. CST must be of integer type. If the
Jeff Cohenbeccb742007-04-22 14:56:37 +00001420 value won't fit in the floating point type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001421
Reid Spencer51b07252006-11-09 23:03:26 +00001422 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001423 <dd>Convert a signed integer constant to the corresponding floating point
1424 constant. TYPE must be floating point. CST must be of integer type. If the
Jeff Cohenbeccb742007-04-22 14:56:37 +00001425 value won't fit in the floating point type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001426
Reid Spencer5b950642006-11-11 23:08:07 +00001427 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1428 <dd>Convert a pointer typed constant to the corresponding integer constant
1429 TYPE must be an integer type. CST must be of pointer type. The CST value is
1430 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1431
1432 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1433 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1434 pointer type. CST must be of integer type. The CST value is zero extended,
1435 truncated, or unchanged to make it fit in a pointer size. This one is
1436 <i>really</i> dangerous!</dd>
1437
1438 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001439 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1440 identical (same number of bits). The conversion is done as if the CST value
1441 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5b950642006-11-11 23:08:07 +00001442 with this operator, just the type. This can be used for conversion of
Reid Spencer404a3252007-02-15 03:07:05 +00001443 vector types to any other type, as long as they have the same bit width. For
Reid Spencer5b950642006-11-11 23:08:07 +00001444 pointers it is only valid to cast to another pointer type.
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001445 </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001446
1447 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1448
1449 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1450 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1451 instruction, the index list may have zero or more indexes, which are required
1452 to make sense for the type of "CSTPTR".</dd>
1453
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001454 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1455
1456 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer9965ee72006-12-04 19:23:19 +00001457 constants.</dd>
1458
1459 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1460 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1461
1462 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1463 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001464
1465 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1466
1467 <dd>Perform the <a href="#i_extractelement">extractelement
1468 operation</a> on constants.
1469
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001470 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1471
1472 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer9965ee72006-12-04 19:23:19 +00001473 operation</a> on constants.</dd>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001474
Chris Lattner016a0e52006-04-08 00:13:41 +00001475
1476 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1477
1478 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer9965ee72006-12-04 19:23:19 +00001479 operation</a> on constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00001480
Chris Lattner74d3f822004-12-09 17:30:23 +00001481 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1482
Reid Spencer641f5c92004-12-09 18:13:12 +00001483 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1484 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001485 binary</a> operations. The constraints on operands are the same as those for
1486 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001487 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001488</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001489</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001490
Chris Lattner2f7c9632001-06-06 20:29:01 +00001491<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00001492<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1493<!-- *********************************************************************** -->
1494
1495<!-- ======================================================================= -->
1496<div class="doc_subsection">
1497<a name="inlineasm">Inline Assembler Expressions</a>
1498</div>
1499
1500<div class="doc_text">
1501
1502<p>
1503LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1504Module-Level Inline Assembly</a>) through the use of a special value. This
1505value represents the inline assembler as a string (containing the instructions
1506to emit), a list of operand constraints (stored as a string), and a flag that
1507indicates whether or not the inline asm expression has side effects. An example
1508inline assembler expression is:
1509</p>
1510
1511<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001512 i32 (i32) asm "bswap $0", "=r,r"
Chris Lattner98f013c2006-01-25 23:47:57 +00001513</pre>
1514
1515<p>
1516Inline assembler expressions may <b>only</b> be used as the callee operand of
1517a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1518</p>
1519
1520<pre>
Reid Spencer96a5f022007-04-04 02:42:35 +00001521 %X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattner98f013c2006-01-25 23:47:57 +00001522</pre>
1523
1524<p>
1525Inline asms with side effects not visible in the constraint list must be marked
1526as having side effects. This is done through the use of the
1527'<tt>sideeffect</tt>' keyword, like so:
1528</p>
1529
1530<pre>
1531 call void asm sideeffect "eieio", ""()
1532</pre>
1533
1534<p>TODO: The format of the asm and constraints string still need to be
1535documented here. Constraints on what can be done (e.g. duplication, moving, etc
1536need to be documented).
1537</p>
1538
1539</div>
1540
1541<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001542<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1543<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001544
Misha Brukman76307852003-11-08 01:05:38 +00001545<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001546
Chris Lattner48b383b02003-11-25 01:02:51 +00001547<p>The LLVM instruction set consists of several different
1548classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001549instructions</a>, <a href="#binaryops">binary instructions</a>,
1550<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001551 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1552instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001553
Misha Brukman76307852003-11-08 01:05:38 +00001554</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001555
Chris Lattner2f7c9632001-06-06 20:29:01 +00001556<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001557<div class="doc_subsection"> <a name="terminators">Terminator
1558Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001559
Misha Brukman76307852003-11-08 01:05:38 +00001560<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001561
Chris Lattner48b383b02003-11-25 01:02:51 +00001562<p>As mentioned <a href="#functionstructure">previously</a>, every
1563basic block in a program ends with a "Terminator" instruction, which
1564indicates which block should be executed after the current block is
1565finished. These terminator instructions typically yield a '<tt>void</tt>'
1566value: they produce control flow, not values (the one exception being
1567the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001568<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001569 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1570instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001571the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1572 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1573 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001574
Misha Brukman76307852003-11-08 01:05:38 +00001575</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001576
Chris Lattner2f7c9632001-06-06 20:29:01 +00001577<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001578<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1579Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001580<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001581<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001582<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001583 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001584</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001585<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001586<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001587value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001588<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001589returns a value and then causes control flow, and one that just causes
1590control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001591<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001592<p>The '<tt>ret</tt>' instruction may return any '<a
1593 href="#t_firstclass">first class</a>' type. Notice that a function is
1594not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1595instruction inside of the function that returns a value that does not
1596match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001597<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001598<p>When the '<tt>ret</tt>' instruction is executed, control flow
1599returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001600 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001601the instruction after the call. If the caller was an "<a
1602 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001603at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001604returns a value, that value shall set the call or invoke instruction's
1605return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001606<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001607<pre> ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001608 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001609</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001610</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001611<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001612<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001613<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001614<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001615<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 Lattner2f7c9632001-06-06 20:29:01 +00001616</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001617<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001618<p>The '<tt>br</tt>' instruction is used to cause control flow to
1619transfer to a different basic block in the current function. There are
1620two forms of this instruction, corresponding to a conditional branch
1621and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001622<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001623<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencer36a15422007-01-12 03:35:51 +00001624single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Reid Spencer50c723a2007-02-19 23:54:10 +00001625unconditional form of the '<tt>br</tt>' instruction takes a single
1626'<tt>label</tt>' value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001627<h5>Semantics:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001628<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001629argument is evaluated. If the value is <tt>true</tt>, control flows
1630to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1631control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001632<h5>Example:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001633<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 Spencerb5ebf3d2006-12-31 07:07:53 +00001634 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001635</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001636<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001637<div class="doc_subsubsection">
1638 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1639</div>
1640
Misha Brukman76307852003-11-08 01:05:38 +00001641<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001642<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001643
1644<pre>
1645 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1646</pre>
1647
Chris Lattner2f7c9632001-06-06 20:29:01 +00001648<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001649
1650<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1651several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001652instruction, allowing a branch to occur to one of many possible
1653destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001654
1655
Chris Lattner2f7c9632001-06-06 20:29:01 +00001656<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001657
1658<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1659comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1660an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1661table is not allowed to contain duplicate constant entries.</p>
1662
Chris Lattner2f7c9632001-06-06 20:29:01 +00001663<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001664
Chris Lattner48b383b02003-11-25 01:02:51 +00001665<p>The <tt>switch</tt> instruction specifies a table of values and
1666destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001667table is searched for the given value. If the value is found, control flow is
1668transfered to the corresponding destination; otherwise, control flow is
1669transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001670
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001671<h5>Implementation:</h5>
1672
1673<p>Depending on properties of the target machine and the particular
1674<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001675ways. For example, it could be generated as a series of chained conditional
1676branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001677
1678<h5>Example:</h5>
1679
1680<pre>
1681 <i>; Emulate a conditional br instruction</i>
Reid Spencer36a15422007-01-12 03:35:51 +00001682 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001683 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001684
1685 <i>; Emulate an unconditional br instruction</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001686 switch i32 0, label %dest [ ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001687
1688 <i>; Implement a jump table:</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001689 switch i32 %val, label %otherwise [ i32 0, label %onzero
1690 i32 1, label %onone
1691 i32 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001692</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001693</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001694
Chris Lattner2f7c9632001-06-06 20:29:01 +00001695<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001696<div class="doc_subsubsection">
1697 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1698</div>
1699
Misha Brukman76307852003-11-08 01:05:38 +00001700<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001701
Chris Lattner2f7c9632001-06-06 20:29:01 +00001702<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001703
1704<pre>
1705 &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 Lattner6b7a0082006-05-14 18:23:06 +00001706 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00001707</pre>
1708
Chris Lattnera8292f32002-05-06 22:08:29 +00001709<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001710
1711<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1712function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001713'<tt>normal</tt>' label or the
1714'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001715"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1716"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001717href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1718continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001719
Chris Lattner2f7c9632001-06-06 20:29:01 +00001720<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001721
Misha Brukman76307852003-11-08 01:05:38 +00001722<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001723
Chris Lattner2f7c9632001-06-06 20:29:01 +00001724<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001725 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00001726 The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001727 convention</a> the call should use. If none is specified, the call defaults
1728 to using C calling conventions.
1729 </li>
1730 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1731 function value being invoked. In most cases, this is a direct function
1732 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1733 an arbitrary pointer to function value.
1734 </li>
1735
1736 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1737 function to be invoked. </li>
1738
1739 <li>'<tt>function args</tt>': argument list whose types match the function
1740 signature argument types. If the function signature indicates the function
1741 accepts a variable number of arguments, the extra arguments can be
1742 specified. </li>
1743
1744 <li>'<tt>normal label</tt>': the label reached when the called function
1745 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1746
1747 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1748 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1749
Chris Lattner2f7c9632001-06-06 20:29:01 +00001750</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001751
Chris Lattner2f7c9632001-06-06 20:29:01 +00001752<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001753
Misha Brukman76307852003-11-08 01:05:38 +00001754<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001755href="#i_call">call</a></tt>' instruction in most regards. The primary
1756difference is that it establishes an association with a label, which is used by
1757the runtime library to unwind the stack.</p>
1758
1759<p>This instruction is used in languages with destructors to ensure that proper
1760cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1761exception. Additionally, this is important for implementation of
1762'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1763
Chris Lattner2f7c9632001-06-06 20:29:01 +00001764<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001765<pre>
Jeff Cohen5819f182007-04-22 01:17:39 +00001766 %retval = invoke i32 %Test(i32 15) to label %Continue
1767 unwind label %TestCleanup <i>; {i32}:retval set</i>
1768 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Test(i32 15) to label %Continue
1769 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001770</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001771</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001772
1773
Chris Lattner5ed60612003-09-03 00:41:47 +00001774<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001775
Chris Lattner48b383b02003-11-25 01:02:51 +00001776<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1777Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001778
Misha Brukman76307852003-11-08 01:05:38 +00001779<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001780
Chris Lattner5ed60612003-09-03 00:41:47 +00001781<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001782<pre>
1783 unwind
1784</pre>
1785
Chris Lattner5ed60612003-09-03 00:41:47 +00001786<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001787
1788<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1789at the first callee in the dynamic call stack which used an <a
1790href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1791primarily used to implement exception handling.</p>
1792
Chris Lattner5ed60612003-09-03 00:41:47 +00001793<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001794
1795<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1796immediately halt. The dynamic call stack is then searched for the first <a
1797href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1798execution continues at the "exceptional" destination block specified by the
1799<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1800dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001801</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001802
1803<!-- _______________________________________________________________________ -->
1804
1805<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1806Instruction</a> </div>
1807
1808<div class="doc_text">
1809
1810<h5>Syntax:</h5>
1811<pre>
1812 unreachable
1813</pre>
1814
1815<h5>Overview:</h5>
1816
1817<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1818instruction is used to inform the optimizer that a particular portion of the
1819code is not reachable. This can be used to indicate that the code after a
1820no-return function cannot be reached, and other facts.</p>
1821
1822<h5>Semantics:</h5>
1823
1824<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1825</div>
1826
1827
1828
Chris Lattner2f7c9632001-06-06 20:29:01 +00001829<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001830<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001831<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001832<p>Binary operators are used to do most of the computation in a
1833program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001834produce a single value. The operands might represent
Reid Spencer404a3252007-02-15 03:07:05 +00001835multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001836The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001837necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001838<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001839</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001840<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001841<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1842Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001843<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001844<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001845<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001846</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001847<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001848<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001849<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001850<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001851 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
Reid Spencer404a3252007-02-15 03:07:05 +00001852 This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001853Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001854<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001855<p>The value produced is the integer or floating point sum of the two
1856operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001857<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001858<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001859</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001860</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001861<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001862<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1863Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001864<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001865<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001866<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001867</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001868<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001869<p>The '<tt>sub</tt>' instruction returns the difference of its two
1870operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001871<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1872instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001873<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001874<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001875 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001876values.
Reid Spencer404a3252007-02-15 03:07:05 +00001877This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001878Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001879<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001880<p>The value produced is the integer or floating point difference of
1881the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001882<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001883<pre> &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
1884 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001885</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001886</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001887<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001888<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1889Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001890<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001891<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001892<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001893</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001894<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001895<p>The '<tt>mul</tt>' instruction returns the product of its two
1896operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001897<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001898<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001899 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001900values.
Reid Spencer404a3252007-02-15 03:07:05 +00001901This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001902Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001903<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001904<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001905two operands.</p>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001906<p>Because the operands are the same width, the result of an integer
1907multiplication is the same whether the operands should be deemed unsigned or
1908signed.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001909<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001910<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001911</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001912</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001913<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001914<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
1915</a></div>
1916<div class="doc_text">
1917<h5>Syntax:</h5>
1918<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1919</pre>
1920<h5>Overview:</h5>
1921<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
1922operands.</p>
1923<h5>Arguments:</h5>
1924<p>The two arguments to the '<tt>udiv</tt>' instruction must be
1925<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00001926types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001927of the values in which case the elements must be integers.</p>
1928<h5>Semantics:</h5>
1929<p>The value produced is the unsigned integer quotient of the two operands. This
1930instruction always performs an unsigned division operation, regardless of
1931whether the arguments are unsigned or not.</p>
1932<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001933<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001934</pre>
1935</div>
1936<!-- _______________________________________________________________________ -->
1937<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
1938</a> </div>
1939<div class="doc_text">
1940<h5>Syntax:</h5>
1941<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1942</pre>
1943<h5>Overview:</h5>
1944<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
1945operands.</p>
1946<h5>Arguments:</h5>
1947<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
1948<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00001949types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001950of the values in which case the elements must be integers.</p>
1951<h5>Semantics:</h5>
1952<p>The value produced is the signed integer quotient of the two operands. This
1953instruction always performs a signed division operation, regardless of whether
1954the arguments are signed or not.</p>
1955<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001956<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001957</pre>
1958</div>
1959<!-- _______________________________________________________________________ -->
1960<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001961Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001962<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001963<h5>Syntax:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001964<pre> &lt;result&gt; = fdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001965</pre>
1966<h5>Overview:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001967<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner48b383b02003-11-25 01:02:51 +00001968operands.</p>
1969<h5>Arguments:</h5>
Jeff Cohen5819f182007-04-22 01:17:39 +00001970<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001971<a href="#t_floating">floating point</a> values. Both arguments must have
Reid Spencer404a3252007-02-15 03:07:05 +00001972identical types. This instruction can also take <a href="#t_vector">vector</a>
Jeff Cohen5819f182007-04-22 01:17:39 +00001973versions of floating point values.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001974<h5>Semantics:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001975<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001976<h5>Example:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001977<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001978</pre>
1979</div>
1980<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00001981<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
1982</div>
1983<div class="doc_text">
1984<h5>Syntax:</h5>
1985<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1986</pre>
1987<h5>Overview:</h5>
1988<p>The '<tt>urem</tt>' instruction returns the remainder from the
1989unsigned division of its two arguments.</p>
1990<h5>Arguments:</h5>
1991<p>The two arguments to the '<tt>urem</tt>' instruction must be
1992<a href="#t_integer">integer</a> values. Both arguments must have identical
1993types.</p>
1994<h5>Semantics:</h5>
1995<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
1996This instruction always performs an unsigned division to get the remainder,
1997regardless of whether the arguments are unsigned or not.</p>
1998<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001999<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002000</pre>
2001
2002</div>
2003<!-- _______________________________________________________________________ -->
2004<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002005Instruction</a> </div>
2006<div class="doc_text">
2007<h5>Syntax:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002008<pre> &lt;result&gt; = srem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002009</pre>
2010<h5>Overview:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002011<p>The '<tt>srem</tt>' instruction returns the remainder from the
2012signed division of its two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002013<h5>Arguments:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002014<p>The two arguments to the '<tt>srem</tt>' instruction must be
2015<a href="#t_integer">integer</a> values. Both arguments must have identical
2016types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002017<h5>Semantics:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002018<p>This instruction returns the <i>remainder</i> of a division (where the result
Reid Spencer806ad6a2007-03-24 22:23:39 +00002019has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i>
2020operator (where the result has the same sign as the divisor, <tt>var2</tt>) of
2021a value. For more information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002022 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
Reid Spencer806ad6a2007-03-24 22:23:39 +00002023Math Forum</a>. For a table of how this is implemented in various languages,
Reid Spencerdb3b93b2007-03-24 22:40:44 +00002024please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
Reid Spencer806ad6a2007-03-24 22:23:39 +00002025Wikipedia: modulo operation</a>.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002026<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002027<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002028</pre>
2029
2030</div>
2031<!-- _______________________________________________________________________ -->
2032<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
2033Instruction</a> </div>
2034<div class="doc_text">
2035<h5>Syntax:</h5>
2036<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2037</pre>
2038<h5>Overview:</h5>
2039<p>The '<tt>frem</tt>' instruction returns the remainder from the
2040division of its two operands.</p>
2041<h5>Arguments:</h5>
2042<p>The two arguments to the '<tt>frem</tt>' instruction must be
2043<a href="#t_floating">floating point</a> values. Both arguments must have
2044identical types.</p>
2045<h5>Semantics:</h5>
2046<p>This instruction returns the <i>remainder</i> of a division.</p>
2047<h5>Example:</h5>
2048<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002049</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002050</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00002051
Reid Spencer2ab01932007-02-02 13:57:07 +00002052<!-- ======================================================================= -->
2053<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2054Operations</a> </div>
2055<div class="doc_text">
2056<p>Bitwise binary operators are used to do various forms of
2057bit-twiddling in a program. They are generally very efficient
2058instructions and can commonly be strength reduced from other
2059instructions. They require two operands, execute an operation on them,
2060and produce a single value. The resulting value of the bitwise binary
2061operators is always the same type as its first operand.</p>
2062</div>
2063
Reid Spencer04e259b2007-01-31 21:39:12 +00002064<!-- _______________________________________________________________________ -->
2065<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2066Instruction</a> </div>
2067<div class="doc_text">
2068<h5>Syntax:</h5>
2069<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2070</pre>
2071<h5>Overview:</h5>
2072<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2073the left a specified number of bits.</p>
2074<h5>Arguments:</h5>
2075<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
2076 href="#t_integer">integer</a> type.</p>
2077<h5>Semantics:</h5>
2078<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
2079<h5>Example:</h5><pre>
2080 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2081 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2082 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
2083</pre>
2084</div>
2085<!-- _______________________________________________________________________ -->
2086<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2087Instruction</a> </div>
2088<div class="doc_text">
2089<h5>Syntax:</h5>
2090<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2091</pre>
2092
2093<h5>Overview:</h5>
2094<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00002095operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002096
2097<h5>Arguments:</h5>
2098<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
2099<a href="#t_integer">integer</a> type.</p>
2100
2101<h5>Semantics:</h5>
2102<p>This instruction always performs a logical shift right operation. The most
2103significant bits of the result will be filled with zero bits after the
2104shift.</p>
2105
2106<h5>Example:</h5>
2107<pre>
2108 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
2109 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
2110 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
2111 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
2112</pre>
2113</div>
2114
Reid Spencer2ab01932007-02-02 13:57:07 +00002115<!-- _______________________________________________________________________ -->
Reid Spencer04e259b2007-01-31 21:39:12 +00002116<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2117Instruction</a> </div>
2118<div class="doc_text">
2119
2120<h5>Syntax:</h5>
2121<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2122</pre>
2123
2124<h5>Overview:</h5>
2125<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00002126operand shifted to the right a specified number of bits with sign extension.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002127
2128<h5>Arguments:</h5>
2129<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
2130<a href="#t_integer">integer</a> type.</p>
2131
2132<h5>Semantics:</h5>
2133<p>This instruction always performs an arithmetic shift right operation,
2134The most significant bits of the result will be filled with the sign bit
2135of <tt>var1</tt>.</p>
2136
2137<h5>Example:</h5>
2138<pre>
2139 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
2140 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
2141 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
2142 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
2143</pre>
2144</div>
2145
Chris Lattner2f7c9632001-06-06 20:29:01 +00002146<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002147<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
2148Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002149<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002150<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002151<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002152</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002153<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002154<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
2155its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002156<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002157<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002158 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002159identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002160<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002161<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002162<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002163<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00002164<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00002165 <tbody>
2166 <tr>
2167 <td>In0</td>
2168 <td>In1</td>
2169 <td>Out</td>
2170 </tr>
2171 <tr>
2172 <td>0</td>
2173 <td>0</td>
2174 <td>0</td>
2175 </tr>
2176 <tr>
2177 <td>0</td>
2178 <td>1</td>
2179 <td>0</td>
2180 </tr>
2181 <tr>
2182 <td>1</td>
2183 <td>0</td>
2184 <td>0</td>
2185 </tr>
2186 <tr>
2187 <td>1</td>
2188 <td>1</td>
2189 <td>1</td>
2190 </tr>
2191 </tbody>
2192</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002193</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002194<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002195<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
2196 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
2197 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002198</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002199</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002200<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002201<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002202<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002203<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002204<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002205</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00002206<h5>Overview:</h5>
2207<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2208or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002209<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002210<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002211 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002212identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002213<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002214<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002215<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002216<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002217<table border="1" cellspacing="0" cellpadding="4">
2218 <tbody>
2219 <tr>
2220 <td>In0</td>
2221 <td>In1</td>
2222 <td>Out</td>
2223 </tr>
2224 <tr>
2225 <td>0</td>
2226 <td>0</td>
2227 <td>0</td>
2228 </tr>
2229 <tr>
2230 <td>0</td>
2231 <td>1</td>
2232 <td>1</td>
2233 </tr>
2234 <tr>
2235 <td>1</td>
2236 <td>0</td>
2237 <td>1</td>
2238 </tr>
2239 <tr>
2240 <td>1</td>
2241 <td>1</td>
2242 <td>1</td>
2243 </tr>
2244 </tbody>
2245</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002246</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002247<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002248<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2249 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2250 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002251</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002252</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002253<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002254<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2255Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002256<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002257<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002258<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002259</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002260<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002261<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2262or of its two operands. The <tt>xor</tt> is used to implement the
2263"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002264<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002265<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002266 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002267identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002268<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002269<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002270<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002271<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002272<table border="1" cellspacing="0" cellpadding="4">
2273 <tbody>
2274 <tr>
2275 <td>In0</td>
2276 <td>In1</td>
2277 <td>Out</td>
2278 </tr>
2279 <tr>
2280 <td>0</td>
2281 <td>0</td>
2282 <td>0</td>
2283 </tr>
2284 <tr>
2285 <td>0</td>
2286 <td>1</td>
2287 <td>1</td>
2288 </tr>
2289 <tr>
2290 <td>1</td>
2291 <td>0</td>
2292 <td>1</td>
2293 </tr>
2294 <tr>
2295 <td>1</td>
2296 <td>1</td>
2297 <td>0</td>
2298 </tr>
2299 </tbody>
2300</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002301</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00002302<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002303<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002304<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2305 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2306 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2307 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002308</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002309</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002310
Chris Lattner2f7c9632001-06-06 20:29:01 +00002311<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00002312<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00002313 <a name="vectorops">Vector Operations</a>
2314</div>
2315
2316<div class="doc_text">
2317
2318<p>LLVM supports several instructions to represent vector operations in a
Jeff Cohen5819f182007-04-22 01:17:39 +00002319target-independent manner. These instructions cover the element-access and
Chris Lattnerce83bff2006-04-08 23:07:04 +00002320vector-specific operations needed to process vectors effectively. While LLVM
2321does directly support these vector operations, many sophisticated algorithms
2322will want to use target-specific intrinsics to take full advantage of a specific
2323target.</p>
2324
2325</div>
2326
2327<!-- _______________________________________________________________________ -->
2328<div class="doc_subsubsection">
2329 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2330</div>
2331
2332<div class="doc_text">
2333
2334<h5>Syntax:</h5>
2335
2336<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002337 &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 Lattnerce83bff2006-04-08 23:07:04 +00002338</pre>
2339
2340<h5>Overview:</h5>
2341
2342<p>
2343The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002344element from a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002345</p>
2346
2347
2348<h5>Arguments:</h5>
2349
2350<p>
2351The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002352value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattnerce83bff2006-04-08 23:07:04 +00002353an index indicating the position from which to extract the element.
2354The index may be a variable.</p>
2355
2356<h5>Semantics:</h5>
2357
2358<p>
2359The result is a scalar of the same type as the element type of
2360<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2361<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2362results are undefined.
2363</p>
2364
2365<h5>Example:</h5>
2366
2367<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002368 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002369</pre>
2370</div>
2371
2372
2373<!-- _______________________________________________________________________ -->
2374<div class="doc_subsubsection">
2375 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2376</div>
2377
2378<div class="doc_text">
2379
2380<h5>Syntax:</h5>
2381
2382<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002383 &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 Lattnerce83bff2006-04-08 23:07:04 +00002384</pre>
2385
2386<h5>Overview:</h5>
2387
2388<p>
2389The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002390element into a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002391</p>
2392
2393
2394<h5>Arguments:</h5>
2395
2396<p>
2397The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002398value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattnerce83bff2006-04-08 23:07:04 +00002399scalar value whose type must equal the element type of the first
2400operand. The third operand is an index indicating the position at
2401which to insert the value. The index may be a variable.</p>
2402
2403<h5>Semantics:</h5>
2404
2405<p>
Reid Spencer404a3252007-02-15 03:07:05 +00002406The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattnerce83bff2006-04-08 23:07:04 +00002407element values are those of <tt>val</tt> except at position
2408<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2409exceeds the length of <tt>val</tt>, the results are undefined.
2410</p>
2411
2412<h5>Example:</h5>
2413
2414<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002415 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002416</pre>
2417</div>
2418
2419<!-- _______________________________________________________________________ -->
2420<div class="doc_subsubsection">
2421 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2422</div>
2423
2424<div class="doc_text">
2425
2426<h5>Syntax:</h5>
2427
2428<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002429 &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 Lattnerce83bff2006-04-08 23:07:04 +00002430</pre>
2431
2432<h5>Overview:</h5>
2433
2434<p>
2435The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2436from two input vectors, returning a vector of the same type.
2437</p>
2438
2439<h5>Arguments:</h5>
2440
2441<p>
2442The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2443with types that match each other and types that match the result of the
2444instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002445of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002446</p>
2447
2448<p>
2449The shuffle mask operand is required to be a constant vector with either
2450constant integer or undef values.
2451</p>
2452
2453<h5>Semantics:</h5>
2454
2455<p>
2456The elements of the two input vectors are numbered from left to right across
2457both of the vectors. The shuffle mask operand specifies, for each element of
2458the result vector, which element of the two input registers the result element
2459gets. The element selector may be undef (meaning "don't care") and the second
2460operand may be undef if performing a shuffle from only one vector.
2461</p>
2462
2463<h5>Example:</h5>
2464
2465<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002466 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen5819f182007-04-22 01:17:39 +00002467 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002468 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2469 &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 Lattnerce83bff2006-04-08 23:07:04 +00002470</pre>
2471</div>
2472
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00002473
Chris Lattnerce83bff2006-04-08 23:07:04 +00002474<!-- ======================================================================= -->
2475<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00002476 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00002477</div>
2478
Misha Brukman76307852003-11-08 01:05:38 +00002479<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002480
Chris Lattner48b383b02003-11-25 01:02:51 +00002481<p>A key design point of an SSA-based representation is how it
2482represents memory. In LLVM, no memory locations are in SSA form, which
2483makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00002484allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002485
Misha Brukman76307852003-11-08 01:05:38 +00002486</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002487
Chris Lattner2f7c9632001-06-06 20:29:01 +00002488<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002489<div class="doc_subsubsection">
2490 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2491</div>
2492
Misha Brukman76307852003-11-08 01:05:38 +00002493<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002494
Chris Lattner2f7c9632001-06-06 20:29:01 +00002495<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002496
2497<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002498 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002499</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002500
Chris Lattner2f7c9632001-06-06 20:29:01 +00002501<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002502
Chris Lattner48b383b02003-11-25 01:02:51 +00002503<p>The '<tt>malloc</tt>' instruction allocates memory from the system
2504heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002505
Chris Lattner2f7c9632001-06-06 20:29:01 +00002506<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002507
2508<p>The '<tt>malloc</tt>' instruction allocates
2509<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00002510bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002511appropriate type to the program. If "NumElements" is specified, it is the
2512number of elements allocated. If an alignment is specified, the value result
2513of the allocation is guaranteed to be aligned to at least that boundary. If
2514not specified, or if zero, the target can choose to align the allocation on any
2515convenient boundary.</p>
2516
Misha Brukman76307852003-11-08 01:05:38 +00002517<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002518
Chris Lattner2f7c9632001-06-06 20:29:01 +00002519<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002520
Chris Lattner48b383b02003-11-25 01:02:51 +00002521<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2522a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002523
Chris Lattner54611b42005-11-06 08:02:57 +00002524<h5>Example:</h5>
2525
2526<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002527 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002528
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002529 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2530 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2531 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2532 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2533 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002534</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002535</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002536
Chris Lattner2f7c9632001-06-06 20:29:01 +00002537<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002538<div class="doc_subsubsection">
2539 <a name="i_free">'<tt>free</tt>' Instruction</a>
2540</div>
2541
Misha Brukman76307852003-11-08 01:05:38 +00002542<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002543
Chris Lattner2f7c9632001-06-06 20:29:01 +00002544<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002545
2546<pre>
2547 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002548</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002549
Chris Lattner2f7c9632001-06-06 20:29:01 +00002550<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002551
Chris Lattner48b383b02003-11-25 01:02:51 +00002552<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00002553memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002554
Chris Lattner2f7c9632001-06-06 20:29:01 +00002555<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002556
Chris Lattner48b383b02003-11-25 01:02:51 +00002557<p>'<tt>value</tt>' shall be a pointer value that points to a value
2558that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2559instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002560
Chris Lattner2f7c9632001-06-06 20:29:01 +00002561<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002562
John Criswelldfe6a862004-12-10 15:51:16 +00002563<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00002564after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002565
Chris Lattner2f7c9632001-06-06 20:29:01 +00002566<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002567
2568<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002569 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2570 free [4 x i8]* %array
Chris Lattner2f7c9632001-06-06 20:29:01 +00002571</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002572</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002573
Chris Lattner2f7c9632001-06-06 20:29:01 +00002574<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002575<div class="doc_subsubsection">
2576 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2577</div>
2578
Misha Brukman76307852003-11-08 01:05:38 +00002579<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002580
Chris Lattner2f7c9632001-06-06 20:29:01 +00002581<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002582
2583<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002584 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002585</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002586
Chris Lattner2f7c9632001-06-06 20:29:01 +00002587<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002588
Jeff Cohen5819f182007-04-22 01:17:39 +00002589<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
2590currently executing function, to be automatically released when this function
Chris Lattner48b383b02003-11-25 01:02:51 +00002591returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002592
Chris Lattner2f7c9632001-06-06 20:29:01 +00002593<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002594
John Criswelldfe6a862004-12-10 15:51:16 +00002595<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002596bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002597appropriate type to the program. If "NumElements" is specified, it is the
2598number of elements allocated. If an alignment is specified, the value result
2599of the allocation is guaranteed to be aligned to at least that boundary. If
2600not specified, or if zero, the target can choose to align the allocation on any
2601convenient boundary.</p>
2602
Misha Brukman76307852003-11-08 01:05:38 +00002603<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002604
Chris Lattner2f7c9632001-06-06 20:29:01 +00002605<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002606
John Criswell4a3327e2005-05-13 22:25:59 +00002607<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00002608memory is automatically released when the function returns. The '<tt>alloca</tt>'
2609instruction is commonly used to represent automatic variables that must
2610have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00002611 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00002612instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002613
Chris Lattner2f7c9632001-06-06 20:29:01 +00002614<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002615
2616<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002617 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
2618 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2619 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
2620 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002621</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002622</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002623
Chris Lattner2f7c9632001-06-06 20:29:01 +00002624<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002625<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2626Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002627<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002628<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00002629<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br></pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002630<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002631<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002632<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002633<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00002634address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00002635 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00002636marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00002637the number or order of execution of this <tt>load</tt> with other
2638volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2639instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00002640<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002641<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002642<h5>Examples:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002643<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002644 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002645 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2646 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002647</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002648</div>
Chris Lattner095735d2002-05-06 03:03:22 +00002649<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002650<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2651Instruction</a> </div>
Reid Spencera89fb182006-11-09 21:18:01 +00002652<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002653<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00002654<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
2655 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002656</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002657<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002658<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002659<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002660<p>There are two arguments to the '<tt>store</tt>' instruction: a value
Jeff Cohen5819f182007-04-22 01:17:39 +00002661to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002662operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00002663operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00002664optimizer is not allowed to modify the number or order of execution of
2665this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2666 href="#i_store">store</a></tt> instructions.</p>
2667<h5>Semantics:</h5>
2668<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2669at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002670<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002671<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002672 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002673 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2674 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002675</pre>
Reid Spencer443460a2006-11-09 21:15:49 +00002676</div>
2677
Chris Lattner095735d2002-05-06 03:03:22 +00002678<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00002679<div class="doc_subsubsection">
2680 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2681</div>
2682
Misha Brukman76307852003-11-08 01:05:38 +00002683<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00002684<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002685<pre>
2686 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2687</pre>
2688
Chris Lattner590645f2002-04-14 06:13:44 +00002689<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002690
2691<p>
2692The '<tt>getelementptr</tt>' instruction is used to get the address of a
2693subelement of an aggregate data structure.</p>
2694
Chris Lattner590645f2002-04-14 06:13:44 +00002695<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002696
Reid Spencercee005c2006-12-04 21:29:24 +00002697<p>This instruction takes a list of integer operands that indicate what
Chris Lattner33fd7022004-04-05 01:30:49 +00002698elements of the aggregate object to index to. The actual types of the arguments
2699provided depend on the type of the first pointer argument. The
2700'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002701levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002702structure, only <tt>i32</tt> integer constants are allowed. When indexing
Reid Spencercee005c2006-12-04 21:29:24 +00002703into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2704be sign extended to 64-bit values.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002705
Chris Lattner48b383b02003-11-25 01:02:51 +00002706<p>For example, let's consider a C code fragment and how it gets
2707compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002708
2709<pre>
2710 struct RT {
2711 char A;
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002712 i32 B[10][20];
Chris Lattner33fd7022004-04-05 01:30:49 +00002713 char C;
2714 };
2715 struct ST {
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002716 i32 X;
Chris Lattner33fd7022004-04-05 01:30:49 +00002717 double Y;
2718 struct RT Z;
2719 };
2720
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002721 define i32 *foo(struct ST *s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002722 return &amp;s[1].Z.B[5][13];
2723 }
2724</pre>
2725
Misha Brukman76307852003-11-08 01:05:38 +00002726<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002727
2728<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002729 %RT = type { i8 , [10 x [20 x i32]], i8 }
2730 %ST = type { i32, double, %RT }
Chris Lattner33fd7022004-04-05 01:30:49 +00002731
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002732 define i32* %foo(%ST* %s) {
Brian Gaeke317ef962004-07-02 21:08:14 +00002733 entry:
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002734 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
2735 ret i32* %reg
Chris Lattner33fd7022004-04-05 01:30:49 +00002736 }
2737</pre>
2738
Chris Lattner590645f2002-04-14 06:13:44 +00002739<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002740
2741<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002742on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencercee005c2006-12-04 21:29:24 +00002743and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencerc0312692006-12-03 16:53:48 +00002744<a href="#t_integer">integer</a> type but the value will always be sign extended
Jeff Cohen5819f182007-04-22 01:17:39 +00002745to 64-bits. <a href="#t_struct">Structure</a> types require <tt>i32</tt>
Reid Spencerc0312692006-12-03 16:53:48 +00002746<b>constants</b>.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002747
Misha Brukman76307852003-11-08 01:05:38 +00002748<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002749type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattner33fd7022004-04-05 01:30:49 +00002750}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002751the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
2752i8 }</tt>' type, another structure. The third index indexes into the second
2753element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattner33fd7022004-04-05 01:30:49 +00002754array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002755'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
2756to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002757
Chris Lattner48b383b02003-11-25 01:02:51 +00002758<p>Note that it is perfectly legal to index partially through a
2759structure, returning a pointer to an inner element. Because of this,
2760the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002761
2762<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002763 define i32* %foo(%ST* %s) {
2764 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen5819f182007-04-22 01:17:39 +00002765 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
2766 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002767 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
2768 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
2769 ret i32* %t5
Chris Lattner33fd7022004-04-05 01:30:49 +00002770 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002771</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002772
2773<p>Note that it is undefined to access an array out of bounds: array and
2774pointer indexes must always be within the defined bounds of the array type.
2775The one exception for this rules is zero length arrays. These arrays are
2776defined to be accessible as variable length arrays, which requires access
2777beyond the zero'th element.</p>
2778
Chris Lattner6ab66722006-08-15 00:45:58 +00002779<p>The getelementptr instruction is often confusing. For some more insight
2780into how it works, see <a href="GetElementPtr.html">the getelementptr
2781FAQ</a>.</p>
2782
Chris Lattner590645f2002-04-14 06:13:44 +00002783<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002784
Chris Lattner33fd7022004-04-05 01:30:49 +00002785<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002786 <i>; yields [12 x i8]*:aptr</i>
2787 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattner33fd7022004-04-05 01:30:49 +00002788</pre>
Chris Lattner33fd7022004-04-05 01:30:49 +00002789</div>
Reid Spencer443460a2006-11-09 21:15:49 +00002790
Chris Lattner2f7c9632001-06-06 20:29:01 +00002791<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00002792<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00002793</div>
Misha Brukman76307852003-11-08 01:05:38 +00002794<div class="doc_text">
Reid Spencer97c5fa42006-11-08 01:18:52 +00002795<p>The instructions in this category are the conversion instructions (casting)
2796which all take a single operand and a type. They perform various bit conversions
2797on the operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002798</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002799
Chris Lattnera8292f32002-05-06 22:08:29 +00002800<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002801<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002802 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
2803</div>
2804<div class="doc_text">
2805
2806<h5>Syntax:</h5>
2807<pre>
2808 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2809</pre>
2810
2811<h5>Overview:</h5>
2812<p>
2813The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
2814</p>
2815
2816<h5>Arguments:</h5>
2817<p>
2818The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
2819be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002820and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencer51b07252006-11-09 23:03:26 +00002821type. The bit size of <tt>value</tt> must be larger than the bit size of
2822<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002823
2824<h5>Semantics:</h5>
2825<p>
2826The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencer51b07252006-11-09 23:03:26 +00002827and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
2828larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
2829It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002830
2831<h5>Example:</h5>
2832<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002833 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002834 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
2835 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002836</pre>
2837</div>
2838
2839<!-- _______________________________________________________________________ -->
2840<div class="doc_subsubsection">
2841 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
2842</div>
2843<div class="doc_text">
2844
2845<h5>Syntax:</h5>
2846<pre>
2847 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2848</pre>
2849
2850<h5>Overview:</h5>
2851<p>The '<tt>zext</tt>' instruction zero extends its operand to type
2852<tt>ty2</tt>.</p>
2853
2854
2855<h5>Arguments:</h5>
2856<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002857<a href="#t_integer">integer</a> type, and a type to cast it to, which must
2858also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00002859<tt>value</tt> must be smaller than the bit size of the destination type,
2860<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002861
2862<h5>Semantics:</h5>
2863<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
2864bits until it reaches the size of the destination type, <tt>ty2</tt>. When the
2865the operand and the type are the same size, no bit filling is done and the
2866cast is considered a <i>no-op cast</i> because no bits change (only the type
2867changes).</p>
2868
Reid Spencer07c9c682007-01-12 15:46:11 +00002869<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002870
2871<h5>Example:</h5>
2872<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002873 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002874 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002875</pre>
2876</div>
2877
2878<!-- _______________________________________________________________________ -->
2879<div class="doc_subsubsection">
2880 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
2881</div>
2882<div class="doc_text">
2883
2884<h5>Syntax:</h5>
2885<pre>
2886 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2887</pre>
2888
2889<h5>Overview:</h5>
2890<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
2891
2892<h5>Arguments:</h5>
2893<p>
2894The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002895<a href="#t_integer">integer</a> type, and a type to cast it to, which must
2896also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00002897<tt>value</tt> must be smaller than the bit size of the destination type,
2898<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002899
2900<h5>Semantics:</h5>
2901<p>
2902The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
2903bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
2904the type <tt>ty2</tt>. When the the operand and the type are the same size,
2905no bit filling is done and the cast is considered a <i>no-op cast</i> because
2906no bits change (only the type changes).</p>
2907
Reid Spencer36a15422007-01-12 03:35:51 +00002908<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002909
2910<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002911<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002912 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002913 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002914</pre>
2915</div>
2916
2917<!-- _______________________________________________________________________ -->
2918<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00002919 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
2920</div>
2921
2922<div class="doc_text">
2923
2924<h5>Syntax:</h5>
2925
2926<pre>
2927 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2928</pre>
2929
2930<h5>Overview:</h5>
2931<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
2932<tt>ty2</tt>.</p>
2933
2934
2935<h5>Arguments:</h5>
2936<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
2937 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
2938cast it to. The size of <tt>value</tt> must be larger than the size of
2939<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
2940<i>no-op cast</i>.</p>
2941
2942<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002943<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
2944<a href="#t_floating">floating point</a> type to a smaller
2945<a href="#t_floating">floating point</a> type. If the value cannot fit within
2946the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00002947
2948<h5>Example:</h5>
2949<pre>
2950 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
2951 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
2952</pre>
2953</div>
2954
2955<!-- _______________________________________________________________________ -->
2956<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002957 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
2958</div>
2959<div class="doc_text">
2960
2961<h5>Syntax:</h5>
2962<pre>
2963 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2964</pre>
2965
2966<h5>Overview:</h5>
2967<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
2968floating point value.</p>
2969
2970<h5>Arguments:</h5>
2971<p>The '<tt>fpext</tt>' instruction takes a
2972<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencer51b07252006-11-09 23:03:26 +00002973and a <a href="#t_floating">floating point</a> type to cast it to. The source
2974type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002975
2976<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002977<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Duncan Sands16f122e2007-03-30 12:22:09 +00002978<a href="#t_floating">floating point</a> type to a larger
2979<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
Reid Spencer51b07252006-11-09 23:03:26 +00002980used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5b950642006-11-11 23:08:07 +00002981<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002982
2983<h5>Example:</h5>
2984<pre>
2985 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
2986 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
2987</pre>
2988</div>
2989
2990<!-- _______________________________________________________________________ -->
2991<div class="doc_subsubsection">
Reid Spencer2eadb532007-01-21 00:29:26 +00002992 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002993</div>
2994<div class="doc_text">
2995
2996<h5>Syntax:</h5>
2997<pre>
2998 &lt;result&gt; = fp2uint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2999</pre>
3000
3001<h5>Overview:</h5>
3002<p>The '<tt>fp2uint</tt>' converts a floating point <tt>value</tt> to its
3003unsigned integer equivalent of type <tt>ty2</tt>.
3004</p>
3005
3006<h5>Arguments:</h5>
3007<p>The '<tt>fp2uint</tt>' instruction takes a value to cast, which must be a
3008<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003009must be an <a href="#t_integer">integer</a> type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003010
3011<h5>Semantics:</h5>
3012<p> The '<tt>fp2uint</tt>' instruction converts its
3013<a href="#t_floating">floating point</a> operand into the nearest (rounding
3014towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
3015the results are undefined.</p>
3016
Reid Spencer36a15422007-01-12 03:35:51 +00003017<p>When converting to i1, the conversion is done as a comparison against
3018zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
3019If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003020
3021<h5>Example:</h5>
3022<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003023 %X = fp2uint double 123.0 to i32 <i>; yields i32:123</i>
3024 %Y = fp2uint float 1.0E+300 to i1 <i>; yields i1:true</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003025 %X = fp2uint float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003026</pre>
3027</div>
3028
3029<!-- _______________________________________________________________________ -->
3030<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003031 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003032</div>
3033<div class="doc_text">
3034
3035<h5>Syntax:</h5>
3036<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003037 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003038</pre>
3039
3040<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003041<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003042<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003043</p>
3044
3045
Chris Lattnera8292f32002-05-06 22:08:29 +00003046<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003047<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003048<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003049must also be an <a href="#t_integer">integer</a> type.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003050
Chris Lattnera8292f32002-05-06 22:08:29 +00003051<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003052<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003053<a href="#t_floating">floating point</a> operand into the nearest (rounding
3054towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
3055the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003056
Reid Spencer36a15422007-01-12 03:35:51 +00003057<p>When converting to i1, the conversion is done as a comparison against
3058zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
3059If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003060
Chris Lattner70de6632001-07-09 00:26:23 +00003061<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003062<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003063 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
3064 %Y = fptosi float 1.0E-247 to i1 <i>; yields i1:true</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003065 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003066</pre>
3067</div>
3068
3069<!-- _______________________________________________________________________ -->
3070<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003071 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003072</div>
3073<div class="doc_text">
3074
3075<h5>Syntax:</h5>
3076<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003077 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003078</pre>
3079
3080<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003081<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003082integer and converts that value to the <tt>ty2</tt> type.</p>
3083
3084
3085<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003086<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003087<a href="#t_integer">integer</a> value, and a type to cast it to, which must
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003088be a <a href="#t_floating">floating point</a> type.</p>
3089
3090<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003091<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003092integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00003093the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003094
3095
3096<h5>Example:</h5>
3097<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003098 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
3099 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003100</pre>
3101</div>
3102
3103<!-- _______________________________________________________________________ -->
3104<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003105 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003106</div>
3107<div class="doc_text">
3108
3109<h5>Syntax:</h5>
3110<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003111 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003112</pre>
3113
3114<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003115<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003116integer and converts that value to the <tt>ty2</tt> type.</p>
3117
3118<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003119<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003120<a href="#t_integer">integer</a> value, and a type to cast it to, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003121a <a href="#t_floating">floating point</a> type.</p>
3122
3123<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003124<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003125integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00003126the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003127
3128<h5>Example:</h5>
3129<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003130 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
3131 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003132</pre>
3133</div>
3134
3135<!-- _______________________________________________________________________ -->
3136<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00003137 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3138</div>
3139<div class="doc_text">
3140
3141<h5>Syntax:</h5>
3142<pre>
3143 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3144</pre>
3145
3146<h5>Overview:</h5>
3147<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3148the integer type <tt>ty2</tt>.</p>
3149
3150<h5>Arguments:</h5>
3151<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
Duncan Sands16f122e2007-03-30 12:22:09 +00003152must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Reid Spencerb7344ff2006-11-11 21:00:47 +00003153<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3154
3155<h5>Semantics:</h5>
3156<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3157<tt>ty2</tt> by interpreting the pointer value as an integer and either
3158truncating or zero extending that value to the size of the integer type. If
3159<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3160<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
3161are the same size, then nothing is done (<i>no-op cast</i>).</p>
3162
3163<h5>Example:</h5>
3164<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003165 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit</i>
3166 %Y = ptrtoint i32* %x to i64 <i>; yields zero extend on 32-bit</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003167</pre>
3168</div>
3169
3170<!-- _______________________________________________________________________ -->
3171<div class="doc_subsubsection">
3172 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3173</div>
3174<div class="doc_text">
3175
3176<h5>Syntax:</h5>
3177<pre>
3178 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3179</pre>
3180
3181<h5>Overview:</h5>
3182<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3183a pointer type, <tt>ty2</tt>.</p>
3184
3185<h5>Arguments:</h5>
Duncan Sands16f122e2007-03-30 12:22:09 +00003186<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003187value to cast, and a type to cast it to, which must be a
Anton Korobeynikova0554d92007-01-12 19:20:47 +00003188<a href="#t_pointer">pointer</a> type.
Reid Spencerb7344ff2006-11-11 21:00:47 +00003189
3190<h5>Semantics:</h5>
3191<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3192<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3193the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3194size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3195the size of a pointer then a zero extension is done. If they are the same size,
3196nothing is done (<i>no-op cast</i>).</p>
3197
3198<h5>Example:</h5>
3199<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003200 %X = inttoptr i32 255 to i32* <i>; yields zero extend on 64-bit</i>
3201 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit </i>
3202 %Y = inttoptr i16 0 to i32* <i>; yields zero extend on 32-bit</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003203</pre>
3204</div>
3205
3206<!-- _______________________________________________________________________ -->
3207<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00003208 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003209</div>
3210<div class="doc_text">
3211
3212<h5>Syntax:</h5>
3213<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00003214 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003215</pre>
3216
3217<h5>Overview:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003218<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003219<tt>ty2</tt> without changing any bits.</p>
3220
3221<h5>Arguments:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003222<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003223a first class value, and a type to cast it to, which must also be a <a
3224 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencere3db84c2007-01-09 20:08:58 +00003225and the destination type, <tt>ty2</tt>, must be identical. If the source
3226type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003227
3228<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003229<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencerb7344ff2006-11-11 21:00:47 +00003230<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3231this conversion. The conversion is done as if the <tt>value</tt> had been
3232stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3233converted to other pointer types with this instruction. To convert pointers to
3234other types, use the <a href="#i_inttoptr">inttoptr</a> or
3235<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003236
3237<h5>Example:</h5>
3238<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003239 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
3240 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3241 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00003242</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003243</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003244
Reid Spencer97c5fa42006-11-08 01:18:52 +00003245<!-- ======================================================================= -->
3246<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3247<div class="doc_text">
3248<p>The instructions in this category are the "miscellaneous"
3249instructions, which defy better classification.</p>
3250</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003251
3252<!-- _______________________________________________________________________ -->
3253<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3254</div>
3255<div class="doc_text">
3256<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00003257<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3258<i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003259</pre>
3260<h5>Overview:</h5>
3261<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3262of its two integer operands.</p>
3263<h5>Arguments:</h5>
3264<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
3265the condition code which indicates the kind of comparison to perform. It is not
3266a value, just a keyword. The possibilities for the condition code are:
3267<ol>
3268 <li><tt>eq</tt>: equal</li>
3269 <li><tt>ne</tt>: not equal </li>
3270 <li><tt>ugt</tt>: unsigned greater than</li>
3271 <li><tt>uge</tt>: unsigned greater or equal</li>
3272 <li><tt>ult</tt>: unsigned less than</li>
3273 <li><tt>ule</tt>: unsigned less or equal</li>
3274 <li><tt>sgt</tt>: signed greater than</li>
3275 <li><tt>sge</tt>: signed greater or equal</li>
3276 <li><tt>slt</tt>: signed less than</li>
3277 <li><tt>sle</tt>: signed less or equal</li>
3278</ol>
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003279<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Reid Spencer784ef792007-01-04 05:19:58 +00003280<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003281<h5>Semantics:</h5>
3282<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3283the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003284yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003285<ol>
3286 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3287 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3288 </li>
3289 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3290 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3291 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3292 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3293 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3294 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3295 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3296 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3297 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3298 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3299 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3300 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3301 <li><tt>sge</tt>: interprets the operands as signed values and yields
3302 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3303 <li><tt>slt</tt>: interprets the operands as signed values and yields
3304 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3305 <li><tt>sle</tt>: interprets the operands as signed values and yields
3306 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003307</ol>
3308<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
3309values are treated as integers and then compared.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003310
3311<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003312<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3313 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3314 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3315 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3316 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3317 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003318</pre>
3319</div>
3320
3321<!-- _______________________________________________________________________ -->
3322<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3323</div>
3324<div class="doc_text">
3325<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00003326<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3327<i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003328</pre>
3329<h5>Overview:</h5>
3330<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3331of its floating point operands.</p>
3332<h5>Arguments:</h5>
3333<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
3334the condition code which indicates the kind of comparison to perform. It is not
3335a value, just a keyword. The possibilities for the condition code are:
3336<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00003337 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003338 <li><tt>oeq</tt>: ordered and equal</li>
3339 <li><tt>ogt</tt>: ordered and greater than </li>
3340 <li><tt>oge</tt>: ordered and greater than or equal</li>
3341 <li><tt>olt</tt>: ordered and less than </li>
3342 <li><tt>ole</tt>: ordered and less than or equal</li>
3343 <li><tt>one</tt>: ordered and not equal</li>
3344 <li><tt>ord</tt>: ordered (no nans)</li>
3345 <li><tt>ueq</tt>: unordered or equal</li>
3346 <li><tt>ugt</tt>: unordered or greater than </li>
3347 <li><tt>uge</tt>: unordered or greater than or equal</li>
3348 <li><tt>ult</tt>: unordered or less than </li>
3349 <li><tt>ule</tt>: unordered or less than or equal</li>
3350 <li><tt>une</tt>: unordered or not equal</li>
3351 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003352 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003353</ol>
Reid Spencer02e0d1d2006-12-06 07:08:07 +00003354<p>In the preceding, <i>ordered</i> means that neither operand is a QNAN while
3355<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer784ef792007-01-04 05:19:58 +00003356<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3357<a href="#t_floating">floating point</a> typed. They must have identical
3358types.</p>
Reid Spencerf69acf32006-11-19 03:00:14 +00003359<p>In the foregoing, <i>ordered</i> means that neither operand is a QNAN and
3360<i>unordered</i> means that either operand is a QNAN.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003361<h5>Semantics:</h5>
3362<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3363the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003364yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003365<ol>
3366 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003367 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003368 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003369 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003370 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003371 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003372 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003373 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003374 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003375 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003376 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003377 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003378 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003379 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3380 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003381 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003382 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003383 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003384 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003385 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003386 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003387 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003388 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003389 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003390 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003391 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003392 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003393 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3394</ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003395
3396<h5>Example:</h5>
3397<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3398 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3399 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3400 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3401</pre>
3402</div>
3403
Reid Spencer97c5fa42006-11-08 01:18:52 +00003404<!-- _______________________________________________________________________ -->
3405<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3406Instruction</a> </div>
3407<div class="doc_text">
3408<h5>Syntax:</h5>
3409<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3410<h5>Overview:</h5>
3411<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3412the SSA graph representing the function.</p>
3413<h5>Arguments:</h5>
3414<p>The type of the incoming values are specified with the first type
3415field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3416as arguments, with one pair for each predecessor basic block of the
3417current block. Only values of <a href="#t_firstclass">first class</a>
3418type may be used as the value arguments to the PHI node. Only labels
3419may be used as the label arguments.</p>
3420<p>There must be no non-phi instructions between the start of a basic
3421block and the PHI instructions: i.e. PHI instructions must be first in
3422a basic block.</p>
3423<h5>Semantics:</h5>
3424<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
3425value specified by the parameter, depending on which basic block we
3426came from in the last <a href="#terminators">terminator</a> instruction.</p>
3427<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003428<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 Spencer97c5fa42006-11-08 01:18:52 +00003429</div>
3430
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003431<!-- _______________________________________________________________________ -->
3432<div class="doc_subsubsection">
3433 <a name="i_select">'<tt>select</tt>' Instruction</a>
3434</div>
3435
3436<div class="doc_text">
3437
3438<h5>Syntax:</h5>
3439
3440<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003441 &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 Lattnerb53c28d2004-03-12 05:50:16 +00003442</pre>
3443
3444<h5>Overview:</h5>
3445
3446<p>
3447The '<tt>select</tt>' instruction is used to choose one value based on a
3448condition, without branching.
3449</p>
3450
3451
3452<h5>Arguments:</h5>
3453
3454<p>
3455The '<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.
3456</p>
3457
3458<h5>Semantics:</h5>
3459
3460<p>
3461If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00003462value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003463</p>
3464
3465<h5>Example:</h5>
3466
3467<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003468 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003469</pre>
3470</div>
3471
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00003472
3473<!-- _______________________________________________________________________ -->
3474<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00003475 <a name="i_call">'<tt>call</tt>' Instruction</a>
3476</div>
3477
Misha Brukman76307852003-11-08 01:05:38 +00003478<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00003479
Chris Lattner2f7c9632001-06-06 20:29:01 +00003480<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003481<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00003482 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattnere23c1392005-05-06 05:47:36 +00003483</pre>
3484
Chris Lattner2f7c9632001-06-06 20:29:01 +00003485<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003486
Misha Brukman76307852003-11-08 01:05:38 +00003487<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003488
Chris Lattner2f7c9632001-06-06 20:29:01 +00003489<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003490
Misha Brukman76307852003-11-08 01:05:38 +00003491<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003492
Chris Lattnera8292f32002-05-06 22:08:29 +00003493<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00003494 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003495 <p>The optional "tail" marker indicates whether the callee function accesses
3496 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00003497 function call is eligible for tail call optimization. Note that calls may
3498 be marked "tail" even if they do not occur before a <a
3499 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00003500 </li>
3501 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00003502 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00003503 convention</a> the call should use. If none is specified, the call defaults
3504 to using C calling conventions.
3505 </li>
3506 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00003507 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
3508 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00003509 signature. This type can be omitted if the function is not varargs and
3510 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003511 </li>
3512 <li>
3513 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3514 be invoked. In most cases, this is a direct function invocation, but
3515 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00003516 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003517 </li>
3518 <li>
3519 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00003520 function signature argument types. All arguments must be of
3521 <a href="#t_firstclass">first class</a> type. If the function signature
3522 indicates the function accepts a variable number of arguments, the extra
3523 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003524 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00003525</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00003526
Chris Lattner2f7c9632001-06-06 20:29:01 +00003527<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003528
Chris Lattner48b383b02003-11-25 01:02:51 +00003529<p>The '<tt>call</tt>' instruction is used to cause control flow to
3530transfer to a specified function, with its incoming arguments bound to
3531the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3532instruction in the called function, control flow continues with the
3533instruction after the function call, and the return value of the
3534function is bound to the result argument. This is a simpler case of
3535the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003536
Chris Lattner2f7c9632001-06-06 20:29:01 +00003537<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003538
3539<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003540 %retval = call i32 %test(i32 %argc)
3541 call i32(i8 *, ...) *%printf(i8 * %msg, i32 12, i8 42);
3542 %X = tail call i32 %foo()
3543 %Y = tail call <a href="#callingconv">fastcc</a> i32 %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00003544</pre>
3545
Misha Brukman76307852003-11-08 01:05:38 +00003546</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003547
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003548<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00003549<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00003550 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003551</div>
3552
Misha Brukman76307852003-11-08 01:05:38 +00003553<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00003554
Chris Lattner26ca62e2003-10-18 05:51:36 +00003555<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003556
3557<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003558 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00003559</pre>
3560
Chris Lattner26ca62e2003-10-18 05:51:36 +00003561<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003562
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003563<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00003564the "variable argument" area of a function call. It is used to implement the
3565<tt>va_arg</tt> macro in C.</p>
3566
Chris Lattner26ca62e2003-10-18 05:51:36 +00003567<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003568
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003569<p>This instruction takes a <tt>va_list*</tt> value and the type of
3570the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00003571increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003572actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003573
Chris Lattner26ca62e2003-10-18 05:51:36 +00003574<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003575
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003576<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3577type from the specified <tt>va_list</tt> and causes the
3578<tt>va_list</tt> to point to the next argument. For more information,
3579see the variable argument handling <a href="#int_varargs">Intrinsic
3580Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003581
3582<p>It is legal for this instruction to be called in a function which does not
3583take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00003584function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003585
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003586<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00003587href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00003588argument.</p>
3589
Chris Lattner26ca62e2003-10-18 05:51:36 +00003590<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003591
3592<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3593
Misha Brukman76307852003-11-08 01:05:38 +00003594</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003595
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003596<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003597<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3598<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00003599
Misha Brukman76307852003-11-08 01:05:38 +00003600<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00003601
3602<p>LLVM supports the notion of an "intrinsic function". These functions have
Reid Spencer4eefaab2007-04-01 08:04:23 +00003603well known names and semantics and are required to follow certain restrictions.
3604Overall, these intrinsics represent an extension mechanism for the LLVM
3605language that does not require changing all of the transformations in LLVM to
3606add to the language (or the bytecode reader/writer, the parser,
Chris Lattnerfee11462004-02-12 17:01:32 +00003607etc...).</p>
3608
John Criswell88190562005-05-16 16:17:45 +00003609<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
3610prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00003611this. Intrinsic functions must always be external functions: you cannot define
3612the body of intrinsic functions. Intrinsic functions may only be used in call
3613or invoke instructions: it is illegal to take the address of an intrinsic
3614function. Additionally, because intrinsic functions are part of the LLVM
3615language, it is required that they all be documented here if any are added.</p>
3616
Reid Spencer4eefaab2007-04-01 08:04:23 +00003617<p>Some intrinsic functions can be overloaded. That is, the intrinsic represents
3618a family of functions that perform the same operation but on different data
3619types. This is most frequent with the integer types. Since LLVM can represent
3620over 8 million different integer types, there is a way to declare an intrinsic
3621that can be overloaded based on its arguments. Such intrinsics will have the
3622names of the arbitrary types encoded into the intrinsic function name, each
3623preceded by a period. For example, the <tt>llvm.ctpop</tt> function can take an
3624integer of any width. This leads to a family of functions such as
3625<tt>i32 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i32 @llvm.ctpop.i29(i29 %val)</tt>.
3626</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00003627
Reid Spencer4eefaab2007-04-01 08:04:23 +00003628
3629<p>To learn how to add an intrinsic function, please see the
3630<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00003631</p>
3632
Misha Brukman76307852003-11-08 01:05:38 +00003633</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003634
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003635<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00003636<div class="doc_subsection">
3637 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3638</div>
3639
Misha Brukman76307852003-11-08 01:05:38 +00003640<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003641
Misha Brukman76307852003-11-08 01:05:38 +00003642<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00003643 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00003644intrinsic functions. These functions are related to the similarly
3645named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003646
Chris Lattner48b383b02003-11-25 01:02:51 +00003647<p>All of these functions operate on arguments that use a
3648target-specific value type "<tt>va_list</tt>". The LLVM assembly
3649language reference manual does not define what this type is, so all
3650transformations should be prepared to handle intrinsics with any type
3651used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003652
Chris Lattner30b868d2006-05-15 17:26:46 +00003653<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00003654instruction and the variable argument handling intrinsic functions are
3655used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003656
Chris Lattnerfee11462004-02-12 17:01:32 +00003657<pre>
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003658define i32 @test(i32 %X, ...) {
Chris Lattnerfee11462004-02-12 17:01:32 +00003659 ; Initialize variable argument processing
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003660 %ap = alloca i8 *
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003661 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003662 call void @llvm.va_start(i8* %ap2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003663
3664 ; Read a single integer argument
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003665 %tmp = va_arg i8 ** %ap, i32
Chris Lattnerfee11462004-02-12 17:01:32 +00003666
3667 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003668 %aq = alloca i8 *
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003669 %aq2 = bitcast i8** %aq to i8*
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003670 call void @llvm.va_copy(i8 *%aq2, i8* %ap2)
3671 call void @llvm.va_end(i8* %aq2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003672
3673 ; Stop processing of arguments.
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003674 call void @llvm.va_end(i8* %ap2)
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003675 ret i32 %tmp
Chris Lattnerfee11462004-02-12 17:01:32 +00003676}
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003677
3678declare void @llvm.va_start(i8*)
3679declare void @llvm.va_copy(i8*, i8*)
3680declare void @llvm.va_end(i8*)
Chris Lattnerfee11462004-02-12 17:01:32 +00003681</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003682</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003683
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003684<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003685<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003686 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00003687</div>
3688
3689
Misha Brukman76307852003-11-08 01:05:38 +00003690<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003691<h5>Syntax:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003692<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003693<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003694<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3695<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3696href="#i_va_arg">va_arg</a></tt>.</p>
3697
3698<h5>Arguments:</h5>
3699
3700<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3701
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003702<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003703
3704<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3705macro available in C. In a target-dependent way, it initializes the
3706<tt>va_list</tt> element the argument points to, so that the next call to
3707<tt>va_arg</tt> will produce the first variable argument passed to the function.
3708Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
3709last argument of the function, the compiler can figure that out.</p>
3710
Misha Brukman76307852003-11-08 01:05:38 +00003711</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003712
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003713<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003714<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003715 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00003716</div>
3717
Misha Brukman76307852003-11-08 01:05:38 +00003718<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003719<h5>Syntax:</h5>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003720<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003721<h5>Overview:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003722
Chris Lattner48b383b02003-11-25 01:02:51 +00003723<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
Reid Spencer96a5f022007-04-04 02:42:35 +00003724which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00003725or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003726
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003727<h5>Arguments:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003728
Misha Brukman76307852003-11-08 01:05:38 +00003729<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003730
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003731<h5>Semantics:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003732
Misha Brukman76307852003-11-08 01:05:38 +00003733<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00003734macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
Reid Spencer96a5f022007-04-04 02:42:35 +00003735Calls to <a href="#int_va_start"><tt>llvm.va_start</tt></a> and <a
3736 href="#int_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
Chris Lattner48b383b02003-11-25 01:02:51 +00003737with calls to <tt>llvm.va_end</tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003738
Misha Brukman76307852003-11-08 01:05:38 +00003739</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003740
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003741<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003742<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003743 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00003744</div>
3745
Misha Brukman76307852003-11-08 01:05:38 +00003746<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003747
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003748<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003749
3750<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003751 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003752</pre>
3753
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003754<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003755
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003756<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
3757the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003758
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003759<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003760
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003761<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00003762The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003763
Chris Lattner757528b0b2004-05-23 21:06:01 +00003764
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003765<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003766
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003767<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
3768available in C. In a target-dependent way, it copies the source
3769<tt>va_list</tt> element into the destination list. This intrinsic is necessary
Reid Spencer96a5f022007-04-04 02:42:35 +00003770because the <tt><a href="#int_va_start">llvm.va_start</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00003771arbitrarily complex and require memory allocation, for example.</p>
3772
Misha Brukman76307852003-11-08 01:05:38 +00003773</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003774
Chris Lattnerfee11462004-02-12 17:01:32 +00003775<!-- ======================================================================= -->
3776<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003777 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
3778</div>
3779
3780<div class="doc_text">
3781
3782<p>
3783LLVM support for <a href="GarbageCollection.html">Accurate Garbage
3784Collection</a> requires the implementation and generation of these intrinsics.
Reid Spencer96a5f022007-04-04 02:42:35 +00003785These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
Chris Lattner757528b0b2004-05-23 21:06:01 +00003786stack</a>, as well as garbage collector implementations that require <a
Reid Spencer96a5f022007-04-04 02:42:35 +00003787href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
Chris Lattner757528b0b2004-05-23 21:06:01 +00003788Front-ends for type-safe garbage collected languages should generate these
3789intrinsics to make use of the LLVM garbage collectors. For more details, see <a
3790href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
3791</p>
3792</div>
3793
3794<!-- _______________________________________________________________________ -->
3795<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003796 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003797</div>
3798
3799<div class="doc_text">
3800
3801<h5>Syntax:</h5>
3802
3803<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003804 declare void @llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003805</pre>
3806
3807<h5>Overview:</h5>
3808
John Criswelldfe6a862004-12-10 15:51:16 +00003809<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00003810the code generator, and allows some metadata to be associated with it.</p>
3811
3812<h5>Arguments:</h5>
3813
3814<p>The first argument specifies the address of a stack object that contains the
3815root pointer. The second pointer (which must be either a constant or a global
3816value address) contains the meta-data to be associated with the root.</p>
3817
3818<h5>Semantics:</h5>
3819
3820<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
3821location. At compile-time, the code generator generates information to allow
3822the runtime to find the pointer at GC safe points.
3823</p>
3824
3825</div>
3826
3827
3828<!-- _______________________________________________________________________ -->
3829<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003830 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003831</div>
3832
3833<div class="doc_text">
3834
3835<h5>Syntax:</h5>
3836
3837<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003838 declare i8 * @llvm.gcread(i8 * %ObjPtr, i8 ** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003839</pre>
3840
3841<h5>Overview:</h5>
3842
3843<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3844locations, allowing garbage collector implementations that require read
3845barriers.</p>
3846
3847<h5>Arguments:</h5>
3848
Chris Lattnerf9228072006-03-14 20:02:51 +00003849<p>The second argument is the address to read from, which should be an address
3850allocated from the garbage collector. The first object is a pointer to the
3851start of the referenced object, if needed by the language runtime (otherwise
3852null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003853
3854<h5>Semantics:</h5>
3855
3856<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3857instruction, but may be replaced with substantially more complex code by the
3858garbage collector runtime, as needed.</p>
3859
3860</div>
3861
3862
3863<!-- _______________________________________________________________________ -->
3864<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003865 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003866</div>
3867
3868<div class="doc_text">
3869
3870<h5>Syntax:</h5>
3871
3872<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003873 declare void @llvm.gcwrite(i8 * %P1, i8 * %Obj, i8 ** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003874</pre>
3875
3876<h5>Overview:</h5>
3877
3878<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3879locations, allowing garbage collector implementations that require write
3880barriers (such as generational or reference counting collectors).</p>
3881
3882<h5>Arguments:</h5>
3883
Chris Lattnerf9228072006-03-14 20:02:51 +00003884<p>The first argument is the reference to store, the second is the start of the
3885object to store it to, and the third is the address of the field of Obj to
3886store to. If the runtime does not require a pointer to the object, Obj may be
3887null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003888
3889<h5>Semantics:</h5>
3890
3891<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3892instruction, but may be replaced with substantially more complex code by the
3893garbage collector runtime, as needed.</p>
3894
3895</div>
3896
3897
3898
3899<!-- ======================================================================= -->
3900<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00003901 <a name="int_codegen">Code Generator Intrinsics</a>
3902</div>
3903
3904<div class="doc_text">
3905<p>
3906These intrinsics are provided by LLVM to expose special features that may only
3907be implemented with code generator support.
3908</p>
3909
3910</div>
3911
3912<!-- _______________________________________________________________________ -->
3913<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003914 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003915</div>
3916
3917<div class="doc_text">
3918
3919<h5>Syntax:</h5>
3920<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003921 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003922</pre>
3923
3924<h5>Overview:</h5>
3925
3926<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003927The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
3928target-specific value indicating the return address of the current function
3929or one of its callers.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003930</p>
3931
3932<h5>Arguments:</h5>
3933
3934<p>
3935The argument to this intrinsic indicates which function to return the address
3936for. Zero indicates the calling function, one indicates its caller, etc. The
3937argument is <b>required</b> to be a constant integer value.
3938</p>
3939
3940<h5>Semantics:</h5>
3941
3942<p>
3943The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3944the return address of the specified call frame, or zero if it cannot be
3945identified. The value returned by this intrinsic is likely to be incorrect or 0
3946for arguments other than zero, so it should only be used for debugging purposes.
3947</p>
3948
3949<p>
3950Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003951aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003952source-language caller.
3953</p>
3954</div>
3955
3956
3957<!-- _______________________________________________________________________ -->
3958<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003959 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00003960</div>
3961
3962<div class="doc_text">
3963
3964<h5>Syntax:</h5>
3965<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00003966 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003967</pre>
3968
3969<h5>Overview:</h5>
3970
3971<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003972The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
3973target-specific frame pointer value for the specified stack frame.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003974</p>
3975
3976<h5>Arguments:</h5>
3977
3978<p>
3979The argument to this intrinsic indicates which function to return the frame
3980pointer for. Zero indicates the calling function, one indicates its caller,
3981etc. The argument is <b>required</b> to be a constant integer value.
3982</p>
3983
3984<h5>Semantics:</h5>
3985
3986<p>
3987The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3988the frame address of the specified call frame, or zero if it cannot be
3989identified. The value returned by this intrinsic is likely to be incorrect or 0
3990for arguments other than zero, so it should only be used for debugging purposes.
3991</p>
3992
3993<p>
3994Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003995aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003996source-language caller.
3997</p>
3998</div>
3999
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004000<!-- _______________________________________________________________________ -->
4001<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004002 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00004003</div>
4004
4005<div class="doc_text">
4006
4007<h5>Syntax:</h5>
4008<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004009 declare i8 *@llvm.stacksave()
Chris Lattner2f0f0012006-01-13 02:03:13 +00004010</pre>
4011
4012<h5>Overview:</h5>
4013
4014<p>
4015The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
Reid Spencer96a5f022007-04-04 02:42:35 +00004016the function stack, for use with <a href="#int_stackrestore">
Chris Lattner2f0f0012006-01-13 02:03:13 +00004017<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
4018features like scoped automatic variable sized arrays in C99.
4019</p>
4020
4021<h5>Semantics:</h5>
4022
4023<p>
4024This intrinsic returns a opaque pointer value that can be passed to <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004025href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
Chris Lattner2f0f0012006-01-13 02:03:13 +00004026<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
4027<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
4028state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
4029practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
4030that were allocated after the <tt>llvm.stacksave</tt> was executed.
4031</p>
4032
4033</div>
4034
4035<!-- _______________________________________________________________________ -->
4036<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004037 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00004038</div>
4039
4040<div class="doc_text">
4041
4042<h5>Syntax:</h5>
4043<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004044 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner2f0f0012006-01-13 02:03:13 +00004045</pre>
4046
4047<h5>Overview:</h5>
4048
4049<p>
4050The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
4051the function stack to the state it was in when the corresponding <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004052href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
Chris Lattner2f0f0012006-01-13 02:03:13 +00004053useful for implementing language features like scoped automatic variable sized
4054arrays in C99.
4055</p>
4056
4057<h5>Semantics:</h5>
4058
4059<p>
Reid Spencer96a5f022007-04-04 02:42:35 +00004060See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
Chris Lattner2f0f0012006-01-13 02:03:13 +00004061</p>
4062
4063</div>
4064
4065
4066<!-- _______________________________________________________________________ -->
4067<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004068 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004069</div>
4070
4071<div class="doc_text">
4072
4073<h5>Syntax:</h5>
4074<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004075 declare void @llvm.prefetch(i8 * &lt;address&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004076 i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004077</pre>
4078
4079<h5>Overview:</h5>
4080
4081
4082<p>
4083The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00004084a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
4085no
4086effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00004087characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004088</p>
4089
4090<h5>Arguments:</h5>
4091
4092<p>
4093<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
4094determining if the fetch should be for a read (0) or write (1), and
4095<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00004096locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004097<tt>locality</tt> arguments must be constant integers.
4098</p>
4099
4100<h5>Semantics:</h5>
4101
4102<p>
4103This intrinsic does not modify the behavior of the program. In particular,
4104prefetches cannot trap and do not produce a value. On targets that support this
4105intrinsic, the prefetch can provide hints to the processor cache for better
4106performance.
4107</p>
4108
4109</div>
4110
Andrew Lenharthb4427912005-03-28 20:05:49 +00004111<!-- _______________________________________________________________________ -->
4112<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004113 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharthb4427912005-03-28 20:05:49 +00004114</div>
4115
4116<div class="doc_text">
4117
4118<h5>Syntax:</h5>
4119<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004120 declare void @llvm.pcmarker( i32 &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00004121</pre>
4122
4123<h5>Overview:</h5>
4124
4125
4126<p>
John Criswell88190562005-05-16 16:17:45 +00004127The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4128(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00004129code to simulators and other tools. The method is target specific, but it is
4130expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00004131The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnere64d41d2005-11-15 06:07:55 +00004132after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb40261e2006-03-24 07:16:10 +00004133optimizations. The intended use is to be inserted after optimizations to allow
John Criswell88190562005-05-16 16:17:45 +00004134correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00004135</p>
4136
4137<h5>Arguments:</h5>
4138
4139<p>
4140<tt>id</tt> is a numerical id identifying the marker.
4141</p>
4142
4143<h5>Semantics:</h5>
4144
4145<p>
4146This intrinsic does not modify the behavior of the program. Backends that do not
4147support this intrinisic may ignore it.
4148</p>
4149
4150</div>
4151
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004152<!-- _______________________________________________________________________ -->
4153<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004154 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004155</div>
4156
4157<div class="doc_text">
4158
4159<h5>Syntax:</h5>
4160<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004161 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004162</pre>
4163
4164<h5>Overview:</h5>
4165
4166
4167<p>
4168The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4169counter register (or similar low latency, high accuracy clocks) on those targets
4170that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4171As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4172should only be used for small timings.
4173</p>
4174
4175<h5>Semantics:</h5>
4176
4177<p>
4178When directly supported, reading the cycle counter should not modify any memory.
4179Implementations are allowed to either return a application specific value or a
4180system wide value. On backends without support, this is lowered to a constant 0.
4181</p>
4182
4183</div>
4184
Chris Lattner3649c3a2004-02-14 04:08:35 +00004185<!-- ======================================================================= -->
4186<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00004187 <a name="int_libc">Standard C Library Intrinsics</a>
4188</div>
4189
4190<div class="doc_text">
4191<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004192LLVM provides intrinsics for a few important standard C library functions.
4193These intrinsics allow source-language front-ends to pass information about the
4194alignment of the pointer arguments to the code generator, providing opportunity
4195for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00004196</p>
4197
4198</div>
4199
4200<!-- _______________________________________________________________________ -->
4201<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004202 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattnerfee11462004-02-12 17:01:32 +00004203</div>
4204
4205<div class="doc_text">
4206
4207<h5>Syntax:</h5>
4208<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004209 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004210 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004211 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004212 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00004213</pre>
4214
4215<h5>Overview:</h5>
4216
4217<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004218The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004219location to the destination location.
4220</p>
4221
4222<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004223Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4224intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00004225</p>
4226
4227<h5>Arguments:</h5>
4228
4229<p>
4230The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004231the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00004232specifying the number of bytes to copy, and the fourth argument is the alignment
4233of the source and destination locations.
4234</p>
4235
Chris Lattner4c67c482004-02-12 21:18:15 +00004236<p>
4237If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004238the caller guarantees that both the source and destination pointers are aligned
4239to that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004240</p>
4241
Chris Lattnerfee11462004-02-12 17:01:32 +00004242<h5>Semantics:</h5>
4243
4244<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004245The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004246location to the destination location, which are not allowed to overlap. It
4247copies "len" bytes of memory over. If the argument is known to be aligned to
4248some boundary, this can be specified as the fourth argument, otherwise it should
4249be set to 0 or 1.
4250</p>
4251</div>
4252
4253
Chris Lattnerf30152e2004-02-12 18:10:10 +00004254<!-- _______________________________________________________________________ -->
4255<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004256 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattnerf30152e2004-02-12 18:10:10 +00004257</div>
4258
4259<div class="doc_text">
4260
4261<h5>Syntax:</h5>
4262<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004263 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004264 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004265 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004266 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00004267</pre>
4268
4269<h5>Overview:</h5>
4270
4271<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004272The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4273location to the destination location. It is similar to the
4274'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004275</p>
4276
4277<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004278Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4279intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004280</p>
4281
4282<h5>Arguments:</h5>
4283
4284<p>
4285The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004286the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00004287specifying the number of bytes to copy, and the fourth argument is the alignment
4288of the source and destination locations.
4289</p>
4290
Chris Lattner4c67c482004-02-12 21:18:15 +00004291<p>
4292If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004293the caller guarantees that the source and destination pointers are aligned to
4294that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004295</p>
4296
Chris Lattnerf30152e2004-02-12 18:10:10 +00004297<h5>Semantics:</h5>
4298
4299<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004300The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00004301location to the destination location, which may overlap. It
4302copies "len" bytes of memory over. If the argument is known to be aligned to
4303some boundary, this can be specified as the fourth argument, otherwise it should
4304be set to 0 or 1.
4305</p>
4306</div>
4307
Chris Lattner941515c2004-01-06 05:31:32 +00004308
Chris Lattner3649c3a2004-02-14 04:08:35 +00004309<!-- _______________________________________________________________________ -->
4310<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004311 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004312</div>
4313
4314<div class="doc_text">
4315
4316<h5>Syntax:</h5>
4317<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004318 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004319 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004320 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004321 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004322</pre>
4323
4324<h5>Overview:</h5>
4325
4326<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004327The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00004328byte value.
4329</p>
4330
4331<p>
4332Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4333does not return a value, and takes an extra alignment argument.
4334</p>
4335
4336<h5>Arguments:</h5>
4337
4338<p>
4339The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00004340byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00004341argument specifying the number of bytes to fill, and the fourth argument is the
4342known alignment of destination location.
4343</p>
4344
4345<p>
4346If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004347the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004348</p>
4349
4350<h5>Semantics:</h5>
4351
4352<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004353The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4354the
Chris Lattner3649c3a2004-02-14 04:08:35 +00004355destination location. If the argument is known to be aligned to some boundary,
4356this can be specified as the fourth argument, otherwise it should be set to 0 or
43571.
4358</p>
4359</div>
4360
4361
Chris Lattner3b4f4372004-06-11 02:28:03 +00004362<!-- _______________________________________________________________________ -->
4363<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004364 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004365</div>
4366
4367<div class="doc_text">
4368
4369<h5>Syntax:</h5>
4370<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004371 declare float @llvm.sqrt.f32(float %Val)
4372 declare double @llvm.sqrt.f64(double %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004373</pre>
4374
4375<h5>Overview:</h5>
4376
4377<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004378The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004379returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
4380<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
4381negative numbers (which allows for better optimization).
4382</p>
4383
4384<h5>Arguments:</h5>
4385
4386<p>
4387The argument and return value are floating point numbers of the same type.
4388</p>
4389
4390<h5>Semantics:</h5>
4391
4392<p>
4393This function returns the sqrt of the specified operand if it is a positive
4394floating point number.
4395</p>
4396</div>
4397
Chris Lattner33b73f92006-09-08 06:34:02 +00004398<!-- _______________________________________________________________________ -->
4399<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004400 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattner33b73f92006-09-08 06:34:02 +00004401</div>
4402
4403<div class="doc_text">
4404
4405<h5>Syntax:</h5>
4406<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004407 declare float @llvm.powi.f32(float %Val, i32 %power)
4408 declare double @llvm.powi.f64(double %Val, i32 %power)
Chris Lattner33b73f92006-09-08 06:34:02 +00004409</pre>
4410
4411<h5>Overview:</h5>
4412
4413<p>
4414The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4415specified (positive or negative) power. The order of evaluation of
4416multiplications is not defined.
4417</p>
4418
4419<h5>Arguments:</h5>
4420
4421<p>
4422The second argument is an integer power, and the first is a value to raise to
4423that power.
4424</p>
4425
4426<h5>Semantics:</h5>
4427
4428<p>
4429This function returns the first value raised to the second power with an
4430unspecified sequence of rounding operations.</p>
4431</div>
4432
4433
Andrew Lenharth1d463522005-05-03 18:01:48 +00004434<!-- ======================================================================= -->
4435<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004436 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004437</div>
4438
4439<div class="doc_text">
4440<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004441LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004442These allow efficient code generation for some algorithms.
4443</p>
4444
4445</div>
4446
4447<!-- _______________________________________________________________________ -->
4448<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004449 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004450</div>
4451
4452<div class="doc_text">
4453
4454<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004455<p>This is an overloaded intrinsic function. You can use bswap on any integer
4456type that is an even number of bytes (i.e. BitWidth % 16 == 0). Note the suffix
4457that includes the type for the result and the operand.
Nate Begeman0f223bb2006-01-13 23:26:38 +00004458<pre>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004459 declare i16 @llvm.bswap.i16.i16(i16 &lt;id&gt;)
4460 declare i32 @llvm.bswap.i32.i32(i32 &lt;id&gt;)
Reid Spencer403a1c42007-04-02 00:19:52 +00004461 declare i64 @llvm.bswap.i64.i64(i64 &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00004462</pre>
4463
4464<h5>Overview:</h5>
4465
4466<p>
Reid Spencerf361c4f2007-04-02 02:25:19 +00004467The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
Reid Spencer4eefaab2007-04-01 08:04:23 +00004468values with an even number of bytes (positive multiple of 16 bits). These are
4469useful for performing operations on data that is not in the target's native
4470byte order.
Nate Begeman0f223bb2006-01-13 23:26:38 +00004471</p>
4472
4473<h5>Semantics:</h5>
4474
4475<p>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004476The <tt>llvm.bswap.16.i16</tt> intrinsic returns an i16 value that has the high
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004477and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
4478intrinsic returns an i32 value that has the four bytes of the input i32
4479swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Reid Spencer4eefaab2007-04-01 08:04:23 +00004480i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48.i48</tt>,
4481<tt>llvm.bswap.i64.i64</tt> and other intrinsics extend this concept to
4482additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Nate Begeman0f223bb2006-01-13 23:26:38 +00004483</p>
4484
4485</div>
4486
4487<!-- _______________________________________________________________________ -->
4488<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004489 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004490</div>
4491
4492<div class="doc_text">
4493
4494<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004495<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
4496width. Not all targets support all bit widths however.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004497<pre>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004498 declare i32 @llvm.ctpop.i8 (i8 &lt;src&gt;)
4499 declare i32 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004500 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Reid Spencer4eefaab2007-04-01 08:04:23 +00004501 declare i32 @llvm.ctpop.i64(i64 &lt;src&gt;)
4502 declare i32 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004503</pre>
4504
4505<h5>Overview:</h5>
4506
4507<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004508The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4509value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004510</p>
4511
4512<h5>Arguments:</h5>
4513
4514<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004515The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004516integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004517</p>
4518
4519<h5>Semantics:</h5>
4520
4521<p>
4522The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4523</p>
4524</div>
4525
4526<!-- _______________________________________________________________________ -->
4527<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004528 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004529</div>
4530
4531<div class="doc_text">
4532
4533<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004534<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
4535integer bit width. Not all targets support all bit widths however.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004536<pre>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004537 declare i32 @llvm.ctlz.i8 (i8 &lt;src&gt;)
4538 declare i32 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004539 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Reid Spencer4eefaab2007-04-01 08:04:23 +00004540 declare i32 @llvm.ctlz.i64(i64 &lt;src&gt;)
4541 declare i32 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004542</pre>
4543
4544<h5>Overview:</h5>
4545
4546<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004547The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4548leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004549</p>
4550
4551<h5>Arguments:</h5>
4552
4553<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004554The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004555integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004556</p>
4557
4558<h5>Semantics:</h5>
4559
4560<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004561The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4562in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004563of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004564</p>
4565</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00004566
4567
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004568
4569<!-- _______________________________________________________________________ -->
4570<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004571 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004572</div>
4573
4574<div class="doc_text">
4575
4576<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004577<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
4578integer bit width. Not all targets support all bit widths however.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004579<pre>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004580 declare i32 @llvm.cttz.i8 (i8 &lt;src&gt;)
4581 declare i32 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004582 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Reid Spencer4eefaab2007-04-01 08:04:23 +00004583 declare i32 @llvm.cttz.i64(i64 &lt;src&gt;)
4584 declare i32 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004585</pre>
4586
4587<h5>Overview:</h5>
4588
4589<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004590The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
4591trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004592</p>
4593
4594<h5>Arguments:</h5>
4595
4596<p>
4597The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004598integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004599</p>
4600
4601<h5>Semantics:</h5>
4602
4603<p>
4604The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
4605in a variable. If the src == 0 then the result is the size in bits of the type
4606of src. For example, <tt>llvm.cttz(2) = 1</tt>.
4607</p>
4608</div>
4609
Reid Spencer8a5799f2007-04-01 08:27:01 +00004610<!-- _______________________________________________________________________ -->
4611<div class="doc_subsubsection">
Reid Spencerea2945e2007-04-10 02:51:31 +00004612 <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a>
Reid Spencer8bc7d952007-04-01 19:00:37 +00004613</div>
4614
4615<div class="doc_text">
4616
4617<h5>Syntax:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00004618<p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt>
Reid Spencer8bc7d952007-04-01 19:00:37 +00004619on any integer bit width.
4620<pre>
Reid Spencerea2945e2007-04-10 02:51:31 +00004621 declare i17 @llvm.part.select.i17.i17 (i17 %val, i32 %loBit, i32 %hiBit)
4622 declare i29 @llvm.part.select.i29.i29 (i29 %val, i32 %loBit, i32 %hiBit)
Reid Spencer8bc7d952007-04-01 19:00:37 +00004623</pre>
4624
4625<h5>Overview:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00004626<p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a
Reid Spencer8bc7d952007-04-01 19:00:37 +00004627range of bits from an integer value and returns them in the same bit width as
4628the original value.</p>
4629
4630<h5>Arguments:</h5>
4631<p>The first argument, <tt>%val</tt> and the result may be integer types of
4632any bit width but they must have the same bit width. The second and third
Reid Spencer96a5f022007-04-04 02:42:35 +00004633arguments must be <tt>i32</tt> type since they specify only a bit index.</p>
Reid Spencer8bc7d952007-04-01 19:00:37 +00004634
4635<h5>Semantics:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00004636<p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes
Reid Spencer96a5f022007-04-04 02:42:35 +00004637of operation: forwards and reverse. If <tt>%loBit</tt> is greater than
4638<tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it
4639operates in forward mode.</p>
4640<p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt>
4641right by <tt>%loBit</tt> bits and then ANDing it with a mask with
Reid Spencer8bc7d952007-04-01 19:00:37 +00004642only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p>
4643<ol>
4644 <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified
4645 by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li>
4646 <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value
4647 to determine the number of bits to retain.</li>
4648 <li>A mask of the retained bits is created by shifting a -1 value.</li>
4649 <li>The mask is ANDed with <tt>%val</tt> to produce the result.
4650</ol>
Reid Spencer96a5f022007-04-04 02:42:35 +00004651<p>In reverse mode, a similar computation is made except that:</p>
4652<ol>
4653 <li>The bits selected wrap around to include both the highest and lowest bits.
Reid Spencerea2945e2007-04-10 02:51:31 +00004654 For example, part.select(i16 X, 4, 7) selects bits from X with a mask of
4655 0x00F0 (forwards case) while part.select(i16 X, 8, 3) selects bits from X
Reid Spencer96a5f022007-04-04 02:42:35 +00004656 with a mask of 0xFF0F.</li>
4657 <li>The bits returned in the reverse case are reversed. So, if X has the value
Reid Spencerea2945e2007-04-10 02:51:31 +00004658 0x6ACF and we apply part.select(i16 X, 8, 3) to it, we get back the value
Reid Spencer96a5f022007-04-04 02:42:35 +00004659 0x0A6F.</li>
4660</ol>
Reid Spencer8bc7d952007-04-01 19:00:37 +00004661</div>
4662
Reid Spencer5bf54c82007-04-11 23:23:49 +00004663<div class="doc_subsubsection">
4664 <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a>
4665</div>
4666
4667<div class="doc_text">
4668
4669<h5>Syntax:</h5>
4670<p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt>
4671on any integer bit width.
4672<pre>
4673 declare i17 @llvm.part.set.i17.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi)
4674 declare i29 @llvm.part.set.i29.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi)
4675</pre>
4676
4677<h5>Overview:</h5>
4678<p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range
4679of bits in an integer value with another integer value. It returns the integer
4680with the replaced bits.</p>
4681
4682<h5>Arguments:</h5>
4683<p>The first argument, <tt>%val</tt> and the result may be integer types of
4684any bit width but they must have the same bit width. <tt>%val</tt> is the value
4685whose bits will be replaced. The second argument, <tt>%repl</tt> may be an
4686integer of any bit width. The third and fourth arguments must be <tt>i32</tt>
4687type since they specify only a bit index.</p>
4688
4689<h5>Semantics:</h5>
4690<p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes
4691of operation: forwards and reverse. If <tt>%lo</tt> is greater than
4692<tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it
4693operates in forward mode.</p>
4694<p>For both modes, the <tt>%repl</tt> value is prepared for use by either
4695truncating it down to the size of the replacement area or zero extending it
4696up to that size.</p>
4697<p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive)
4698are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit
4699in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up
4700to the <tt>%hi</tt>th bit.
4701<p>In reverse mode, a similar computation is made except that the bits replaced
4702wrap around to include both the highest and lowest bits. For example, if a
470316 bit value is being replaced then <tt>%lo=8</tt> and <tt>%hi=4</tt> would
Reid Spencer14194dc2007-04-11 23:46:06 +00004704cause these bits to be set: <tt>0xFF1F</tt>.</p>
Reid Spencer5bf54c82007-04-11 23:23:49 +00004705<h5>Examples:</h5>
4706<pre>
Reid Spencerc70afc32007-04-12 01:03:03 +00004707 llvm.part.set(0xFFFF, 0, 4, 7) -&gt; 0xFF0F
4708 llvm.part.set(0xFFFF, 0, 7, 4) -&gt; 0x0060
4709 llvm.part.set(0xFFFF, 0, 8, 3) -&gt; 0x00F0
4710 llvm.part.set(0xFFFF, 0, 3, 8) -&gt; 0xFE07
Reid Spencer7972c472007-04-11 23:49:50 +00004711</pre>
Reid Spencer5bf54c82007-04-11 23:23:49 +00004712</div>
4713
Chris Lattner941515c2004-01-06 05:31:32 +00004714<!-- ======================================================================= -->
4715<div class="doc_subsection">
4716 <a name="int_debugger">Debugger Intrinsics</a>
4717</div>
4718
4719<div class="doc_text">
4720<p>
4721The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
4722are described in the <a
4723href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
4724Debugging</a> document.
4725</p>
4726</div>
4727
4728
Jim Laskey2211f492007-03-14 19:31:19 +00004729<!-- ======================================================================= -->
4730<div class="doc_subsection">
4731 <a name="int_eh">Exception Handling Intrinsics</a>
4732</div>
4733
4734<div class="doc_text">
4735<p> The LLVM exception handling intrinsics (which all start with
4736<tt>llvm.eh.</tt> prefix), are described in the <a
4737href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
4738Handling</a> document. </p>
4739</div>
4740
4741
Chris Lattner2f7c9632001-06-06 20:29:01 +00004742<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00004743<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00004744<address>
4745 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
4746 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
4747 <a href="http://validator.w3.org/check/referer"><img
4748 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
4749
4750 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00004751 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00004752 Last modified: $Date$
4753</address>
Misha Brukman76307852003-11-08 01:05:38 +00004754</body>
4755</html>