blob: 910fc5c6514bfccf9f9d5a28477ed1863bccd993 [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>
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +000023 <li><a href="#linkage">Linkage Types</a>
24 <ol>
Bill Wendling8693ef82009-07-20 02:41:50 +000025 <li><a href="#linkage_private">'<tt>private</tt>' Linkage</a></li>
26 <li><a href="#linkage_linker_private">'<tt>linker_private</tt>' Linkage</a></li>
27 <li><a href="#linkage_internal">'<tt>internal</tt>' Linkage</a></li>
28 <li><a href="#linkage_available_externally">'<tt>available_externally</tt>' Linkage</a></li>
29 <li><a href="#linkage_linkonce">'<tt>linkonce</tt>' Linkage</a></li>
30 <li><a href="#linkage_common">'<tt>common</tt>' Linkage</a></li>
31 <li><a href="#linkage_weak">'<tt>weak</tt>' Linkage</a></li>
32 <li><a href="#linkage_appending">'<tt>appending</tt>' Linkage</a></li>
33 <li><a href="#linkage_externweak">'<tt>extern_weak</tt>' Linkage</a></li>
34 <li><a href="#linkage_linkonce">'<tt>linkonce_odr</tt>' Linkage</a></li>
35 <li><a href="#linkage_weak">'<tt>weak_odr</tt>' Linkage</a></li>
36 <li><a href="#linkage_external">'<tt>externally visible</tt>' Linkage</a></li>
37 <li><a href="#linkage_dllimport">'<tt>dllimport</tt>' Linkage</a></li>
38 <li><a href="#linkage_dllexport">'<tt>dllexport</tt>' Linkage</a></li>
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +000039 </ol>
40 </li>
Chris Lattner0132aff2005-05-06 22:57:40 +000041 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerbc088212009-01-11 20:53:49 +000042 <li><a href="#namedtypes">Named Types</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000043 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000044 <li><a href="#functionstructure">Functions</a></li>
Dan Gohmanef9462f2008-10-14 16:51:45 +000045 <li><a href="#aliasstructure">Aliases</a></li>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +000046 <li><a href="#paramattrs">Parameter Attributes</a></li>
Devang Patel9eb525d2008-09-26 23:51:19 +000047 <li><a href="#fnattrs">Function Attributes</a></li>
Gordon Henriksen71183b62007-12-10 03:18:06 +000048 <li><a href="#gc">Garbage Collector Names</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000049 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Reid Spencer50c723a2007-02-19 23:54:10 +000050 <li><a href="#datalayout">Data Layout</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000051 </ol>
52 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000053 <li><a href="#typesystem">Type System</a>
54 <ol>
Chris Lattner7824d182008-01-04 04:32:38 +000055 <li><a href="#t_classifications">Type Classifications</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000056 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000057 <ol>
Chris Lattner7824d182008-01-04 04:32:38 +000058 <li><a href="#t_floating">Floating Point Types</a></li>
59 <li><a href="#t_void">Void Type</a></li>
60 <li><a href="#t_label">Label Type</a></li>
Nick Lewyckyadbc2842009-05-30 05:06:04 +000061 <li><a href="#t_metadata">Metadata Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000062 </ol>
63 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000064 <li><a href="#t_derived">Derived Types</a>
65 <ol>
Chris Lattner9a2e3cb2007-12-18 06:18:21 +000066 <li><a href="#t_integer">Integer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000067 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000068 <li><a href="#t_function">Function Type</a></li>
69 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000070 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth8df88e22006-12-08 17:13:00 +000071 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer404a3252007-02-15 03:07:05 +000072 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000073 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000074 </ol>
75 </li>
Chris Lattnercf7a5842009-02-02 07:32:36 +000076 <li><a href="#t_uprefs">Type Up-references</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000079 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000080 <ol>
Dan Gohmanef9462f2008-10-14 16:51:45 +000081 <li><a href="#simpleconstants">Simple Constants</a></li>
Chris Lattner361bfcd2009-02-28 18:32:25 +000082 <li><a href="#complexconstants">Complex Constants</a></li>
Dan Gohmanef9462f2008-10-14 16:51:45 +000083 <li><a href="#globalconstants">Global Variable and Function Addresses</a></li>
84 <li><a href="#undefvalues">Undefined Values</a></li>
85 <li><a href="#constantexprs">Constant Expressions</a></li>
Nick Lewycky49f89192009-04-04 07:22:01 +000086 <li><a href="#metadata">Embedded Metadata</a></li>
Chris Lattner74d3f822004-12-09 17:30:23 +000087 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000088 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000089 <li><a href="#othervalues">Other Values</a>
90 <ol>
Dan Gohmanef9462f2008-10-14 16:51:45 +000091 <li><a href="#inlineasm">Inline Assembler Expressions</a></li>
Chris Lattner98f013c2006-01-25 23:47:57 +000092 </ol>
93 </li>
Chris Lattnerae76db52009-07-20 05:55:19 +000094 <li><a href="#intrinsic_globals">Intrinsic Global Variables</a>
95 <ol>
96 <li><a href="#intg_used">The '<tt>llvm.used</tt>' Global Variable</a></li>
97 <li><a href="#intg_global_ctors">The '<tt>llvm.global_ctors</tt>'
98 Global Variable</a></li>
99 <li><a href="#intg_global_dtors">The '<tt>llvm.global_dtors</tt>'
100 Global Variable</a></li>
101 </ol>
102 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000103 <li><a href="#instref">Instruction Reference</a>
104 <ol>
105 <li><a href="#terminators">Terminator Instructions</a>
106 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000107 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
108 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000109 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
110 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000111 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000112 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000113 </ol>
114 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000115 <li><a href="#binaryops">Binary Operations</a>
116 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000117 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000118 <li><a href="#i_fadd">'<tt>fadd</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000119 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000120 <li><a href="#i_fsub">'<tt>fsub</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000121 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000122 <li><a href="#i_fmul">'<tt>fmul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +0000123 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
124 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
125 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +0000126 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
127 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
128 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000129 </ol>
130 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000131 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
132 <ol>
Reid Spencer2ab01932007-02-02 13:57:07 +0000133 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
134 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
135 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000136 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000137 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000138 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000139 </ol>
140 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000141 <li><a href="#vectorops">Vector Operations</a>
142 <ol>
143 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
144 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
145 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000146 </ol>
147 </li>
Dan Gohmanb9d66602008-05-12 23:51:09 +0000148 <li><a href="#aggregateops">Aggregate Operations</a>
149 <ol>
150 <li><a href="#i_extractvalue">'<tt>extractvalue</tt>' Instruction</a></li>
151 <li><a href="#i_insertvalue">'<tt>insertvalue</tt>' Instruction</a></li>
152 </ol>
153 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000154 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000155 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000156 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
157 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
158 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000159 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
160 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
161 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000162 </ol>
163 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000164 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000165 <ol>
166 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
167 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
168 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
169 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
170 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000171 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
172 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
173 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
174 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000175 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
176 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000177 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000178 </ol>
Dan Gohmanef9462f2008-10-14 16:51:45 +0000179 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000180 <li><a href="#otherops">Other Operations</a>
181 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000182 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
183 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000184 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000185 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000186 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000187 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000188 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000189 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000190 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000191 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000192 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000193 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000194 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
195 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000196 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
197 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
198 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000199 </ol>
200 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000201 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
202 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000203 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
204 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
205 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000206 </ol>
207 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000208 <li><a href="#int_codegen">Code Generator Intrinsics</a>
209 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000210 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
211 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
212 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
213 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
214 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
215 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
216 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000217 </ol>
218 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000219 <li><a href="#int_libc">Standard C Library Intrinsics</a>
220 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000221 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
222 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
223 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
224 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
225 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Dan Gohmanb6324c12007-10-15 20:30:11 +0000226 <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li>
227 <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li>
228 <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000229 </ol>
230 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000231 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000232 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000233 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000234 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
235 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
236 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000237 </ol>
238 </li>
Bill Wendlingf4d70622009-02-08 01:40:31 +0000239 <li><a href="#int_overflow">Arithmetic with Overflow Intrinsics</a>
240 <ol>
Bill Wendlingfd2bd722009-02-08 04:04:40 +0000241 <li><a href="#int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt> Intrinsics</a></li>
242 <li><a href="#int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt> Intrinsics</a></li>
243 <li><a href="#int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt> Intrinsics</a></li>
244 <li><a href="#int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt> Intrinsics</a></li>
245 <li><a href="#int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendlingb9a73272009-02-08 23:00:09 +0000246 <li><a href="#int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendlingf4d70622009-02-08 01:40:31 +0000247 </ol>
248 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000249 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskey2211f492007-03-14 19:31:19 +0000250 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Duncan Sands86e01192007-09-11 14:10:23 +0000251 <li><a href="#int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +0000252 <ol>
253 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
Duncan Sands644f9172007-07-27 12:58:54 +0000254 </ol>
255 </li>
Bill Wendlingf85850f2008-11-18 22:10:53 +0000256 <li><a href="#int_atomics">Atomic intrinsics</a>
257 <ol>
258 <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
259 <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li>
260 <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
261 <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li>
262 <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li>
263 <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li>
264 <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li>
265 <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li>
266 <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li>
267 <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li>
268 <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li>
269 <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li>
270 <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li>
271 </ol>
272 </li>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000273 <li><a href="#int_general">General intrinsics</a>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000274 <ol>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000275 <li><a href="#int_var_annotation">
Bill Wendling14313312008-11-19 05:56:17 +0000276 '<tt>llvm.var.annotation</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000277 <li><a href="#int_annotation">
Bill Wendling14313312008-11-19 05:56:17 +0000278 '<tt>llvm.annotation.*</tt>' Intrinsic</a></li>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +0000279 <li><a href="#int_trap">
Bill Wendling14313312008-11-19 05:56:17 +0000280 '<tt>llvm.trap</tt>' Intrinsic</a></li>
281 <li><a href="#int_stackprotector">
282 '<tt>llvm.stackprotector</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000283 </ol>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000284 </li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000285 </ol>
286 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000287</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000288
289<div class="doc_author">
290 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
291 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000292</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000293
Chris Lattner2f7c9632001-06-06 20:29:01 +0000294<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000295<div class="doc_section"> <a name="abstract">Abstract </a></div>
296<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000297
Misha Brukman76307852003-11-08 01:05:38 +0000298<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000299
300<p>This document is a reference manual for the LLVM assembly language. LLVM is
301 a Static Single Assignment (SSA) based representation that provides type
302 safety, low-level operations, flexibility, and the capability of representing
303 'all' high-level languages cleanly. It is the common code representation
304 used throughout all phases of the LLVM compilation strategy.</p>
305
Misha Brukman76307852003-11-08 01:05:38 +0000306</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000307
Chris Lattner2f7c9632001-06-06 20:29:01 +0000308<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000309<div class="doc_section"> <a name="introduction">Introduction</a> </div>
310<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000311
Misha Brukman76307852003-11-08 01:05:38 +0000312<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000313
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000314<p>The LLVM code representation is designed to be used in three different forms:
315 as an in-memory compiler IR, as an on-disk bitcode representation (suitable
316 for fast loading by a Just-In-Time compiler), and as a human readable
317 assembly language representation. This allows LLVM to provide a powerful
318 intermediate representation for efficient compiler transformations and
319 analysis, while providing a natural means to debug and visualize the
320 transformations. The three different forms of LLVM are all equivalent. This
321 document describes the human readable representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000322
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000323<p>The LLVM representation aims to be light-weight and low-level while being
324 expressive, typed, and extensible at the same time. It aims to be a
325 "universal IR" of sorts, by being at a low enough level that high-level ideas
326 may be cleanly mapped to it (similar to how microprocessors are "universal
327 IR's", allowing many source languages to be mapped to them). By providing
328 type information, LLVM can be used as the target of optimizations: for
329 example, through pointer analysis, it can be proven that a C automatic
330 variable is never accessed outside of the current function... allowing it to
331 be promoted to a simple SSA value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000332
Misha Brukman76307852003-11-08 01:05:38 +0000333</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000334
Chris Lattner2f7c9632001-06-06 20:29:01 +0000335<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000336<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000337
Misha Brukman76307852003-11-08 01:05:38 +0000338<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000339
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000340<p>It is important to note that this document describes 'well formed' LLVM
341 assembly language. There is a difference between what the parser accepts and
342 what is considered 'well formed'. For example, the following instruction is
343 syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000344
Bill Wendling3716c5d2007-05-29 09:04:49 +0000345<div class="doc_code">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000346<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000347%x = <a href="#i_add">add</a> i32 1, %x
Chris Lattner757528b0b2004-05-23 21:06:01 +0000348</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000349</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000350
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000351<p>...because the definition of <tt>%x</tt> does not dominate all of its
352 uses. The LLVM infrastructure provides a verification pass that may be used
353 to verify that an LLVM module is well formed. This pass is automatically run
354 by the parser after parsing input assembly and by the optimizer before it
355 outputs bitcode. The violations pointed out by the verifier pass indicate
356 bugs in transformation passes or input to the parser.</p>
357
Bill Wendling3716c5d2007-05-29 09:04:49 +0000358</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000359
Chris Lattner87a3dbe2007-10-03 17:34:29 +0000360<!-- Describe the typesetting conventions here. -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000361
Chris Lattner2f7c9632001-06-06 20:29:01 +0000362<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000363<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000364<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000365
Misha Brukman76307852003-11-08 01:05:38 +0000366<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000367
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000368<p>LLVM identifiers come in two basic types: global and local. Global
369 identifiers (functions, global variables) begin with the <tt>'@'</tt>
370 character. Local identifiers (register names, types) begin with
371 the <tt>'%'</tt> character. Additionally, there are three different formats
372 for identifiers, for different purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000373
Chris Lattner2f7c9632001-06-06 20:29:01 +0000374<ol>
Reid Spencerb23b65f2007-08-07 14:34:28 +0000375 <li>Named values are represented as a string of characters with their prefix.
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000376 For example, <tt>%foo</tt>, <tt>@DivisionByZero</tt>,
377 <tt>%a.really.long.identifier</tt>. The actual regular expression used is
378 '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. Identifiers which require
379 other characters in their names can be surrounded with quotes. Special
380 characters may be escaped using <tt>"\xx"</tt> where <tt>xx</tt> is the
381 ASCII code for the character in hexadecimal. In this way, any character
382 can be used in a name value, even quotes themselves.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000383
Reid Spencerb23b65f2007-08-07 14:34:28 +0000384 <li>Unnamed values are represented as an unsigned numeric value with their
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000385 prefix. For example, <tt>%12</tt>, <tt>@2</tt>, <tt>%44</tt>.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000386
Reid Spencer8f08d802004-12-09 18:02:53 +0000387 <li>Constants, which are described in a <a href="#constants">section about
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000388 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000389</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000390
Reid Spencerb23b65f2007-08-07 14:34:28 +0000391<p>LLVM requires that values start with a prefix for two reasons: Compilers
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000392 don't need to worry about name clashes with reserved words, and the set of
393 reserved words may be expanded in the future without penalty. Additionally,
394 unnamed identifiers allow a compiler to quickly come up with a temporary
395 variable without having to avoid symbol table conflicts.</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000396
Chris Lattner48b383b02003-11-25 01:02:51 +0000397<p>Reserved words in LLVM are very similar to reserved words in other
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000398 languages. There are keywords for different opcodes
399 ('<tt><a href="#i_add">add</a></tt>',
400 '<tt><a href="#i_bitcast">bitcast</a></tt>',
401 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names
402 ('<tt><a href="#t_void">void</a></tt>',
403 '<tt><a href="#t_primitive">i32</a></tt>', etc...), and others. These
404 reserved words cannot conflict with variable names, because none of them
405 start with a prefix character (<tt>'%'</tt> or <tt>'@'</tt>).</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000406
407<p>Here is an example of LLVM code to multiply the integer variable
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000408 '<tt>%X</tt>' by 8:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000409
Misha Brukman76307852003-11-08 01:05:38 +0000410<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000411
Bill Wendling3716c5d2007-05-29 09:04:49 +0000412<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000413<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000414%result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnerd79749a2004-12-09 16:36:40 +0000415</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000416</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000417
Misha Brukman76307852003-11-08 01:05:38 +0000418<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000419
Bill Wendling3716c5d2007-05-29 09:04:49 +0000420<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000421<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000422%result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnerd79749a2004-12-09 16:36:40 +0000423</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000424</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000425
Misha Brukman76307852003-11-08 01:05:38 +0000426<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000427
Bill Wendling3716c5d2007-05-29 09:04:49 +0000428<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000429<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000430<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
431<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
432%result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnerd79749a2004-12-09 16:36:40 +0000433</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000434</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000435
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000436<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several important
437 lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000438
Chris Lattner2f7c9632001-06-06 20:29:01 +0000439<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000440 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000441 line.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000442
443 <li>Unnamed temporaries are created when the result of a computation is not
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000444 assigned to a named value.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000445
Misha Brukman76307852003-11-08 01:05:38 +0000446 <li>Unnamed temporaries are numbered sequentially</li>
447</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000448
John Criswell02fdc6f2005-05-12 16:52:32 +0000449<p>...and it also shows a convention that we follow in this document. When
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000450 demonstrating instructions, we will follow an instruction with a comment that
451 defines the type and name of value produced. Comments are shown in italic
452 text.</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000453
Misha Brukman76307852003-11-08 01:05:38 +0000454</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000455
456<!-- *********************************************************************** -->
457<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
458<!-- *********************************************************************** -->
459
460<!-- ======================================================================= -->
461<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
462</div>
463
464<div class="doc_text">
465
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000466<p>LLVM programs are composed of "Module"s, each of which is a translation unit
467 of the input programs. Each module consists of functions, global variables,
468 and symbol table entries. Modules may be combined together with the LLVM
469 linker, which merges function (and global variable) definitions, resolves
470 forward declarations, and merges symbol table entries. Here is an example of
471 the "hello world" module:</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000472
Bill Wendling3716c5d2007-05-29 09:04:49 +0000473<div class="doc_code">
Chris Lattner6af02f32004-12-09 16:11:40 +0000474<pre><i>; Declare the string constant as a global constant...</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000475<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
476 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 +0000477
478<i>; External declaration of the puts function</i>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000479<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000480
481<i>; Definition of main function</i>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000482define i32 @main() { <i>; i32()* </i>
Dan Gohman623806e2009-01-04 23:44:43 +0000483 <i>; Convert [13 x i8]* to i8 *...</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000484 %cast210 = <a
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000485 href="#i_getelementptr">getelementptr</a> [13 x i8]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000486
487 <i>; Call puts function to write out the string to stdout...</i>
488 <a
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000489 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000490 <a
Bill Wendling3716c5d2007-05-29 09:04:49 +0000491 href="#i_ret">ret</a> i32 0<br>}<br>
492</pre>
493</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000494
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000495<p>This example is made up of a <a href="#globalvars">global variable</a> named
496 "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" function, and
497 a <a href="#functionstructure">function definition</a> for
498 "<tt>main</tt>".</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000499
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000500<p>In general, a module is made up of a list of global values, where both
501 functions and global variables are global values. Global values are
502 represented by a pointer to a memory location (in this case, a pointer to an
503 array of char, and a pointer to a function), and have one of the
504 following <a href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000505
Chris Lattnerd79749a2004-12-09 16:36:40 +0000506</div>
507
508<!-- ======================================================================= -->
509<div class="doc_subsection">
510 <a name="linkage">Linkage Types</a>
511</div>
512
513<div class="doc_text">
514
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000515<p>All Global Variables and Functions have one of the following types of
516 linkage:</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000517
518<dl>
Rafael Espindola6de96a12009-01-15 20:18:42 +0000519 <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000520 <dd>Global values with private linkage are only directly accessible by objects
521 in the current module. In particular, linking code into a module with an
522 private global value may cause the private to be renamed as necessary to
523 avoid collisions. Because the symbol is private to the module, all
524 references can be updated. This doesn't show up in any symbol table in the
525 object file.</dd>
Rafael Espindola6de96a12009-01-15 20:18:42 +0000526
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +0000527 <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt>
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +0000528 <dd>Similar to private, but the symbol is passed through the assembler and
529 removed by the linker after evaluation.</dd>
530
Dale Johannesen4188aad2008-05-23 23:13:41 +0000531 <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000532 <dd>Similar to private, but the value shows as a local symbol
533 (<tt>STB_LOCAL</tt> in the case of ELF) in the object file. This
534 corresponds to the notion of the '<tt>static</tt>' keyword in C.</dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000535
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000536 <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>: </dt>
Chris Lattner184f1be2009-04-13 05:44:34 +0000537 <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000538 into the object file corresponding to the LLVM module. They exist to
539 allow inlining and other optimizations to take place given knowledge of
540 the definition of the global, which is known to be somewhere outside the
541 module. Globals with <tt>available_externally</tt> linkage are allowed to
542 be discarded at will, and are otherwise the same as <tt>linkonce_odr</tt>.
543 This linkage type is only allowed on definitions, not declarations.</dd>
Chris Lattner184f1be2009-04-13 05:44:34 +0000544
Chris Lattner6af02f32004-12-09 16:11:40 +0000545 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere20b4702007-01-14 06:51:48 +0000546 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000547 the same name when linkage occurs. This is typically used to implement
548 inline functions, templates, or other code which must be generated in each
549 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
550 allowed to be discarded.</dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000551
Dale Johannesen4188aad2008-05-23 23:13:41 +0000552 <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000553 <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
554 linkage, except that unreferenced <tt>common</tt> globals may not be
555 discarded. This is used for globals that may be emitted in multiple
556 translation units, but that are not guaranteed to be emitted into every
557 translation unit that uses them. One example of this is tentative
558 definitions in C, such as "<tt>int X;</tt>" at global scope.</dd>
Dale Johannesen4188aad2008-05-23 23:13:41 +0000559
Chris Lattner6af02f32004-12-09 16:11:40 +0000560 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Dale Johannesen4188aad2008-05-23 23:13:41 +0000561 <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000562 that some targets may choose to emit different assembly sequences for them
563 for target-dependent reasons. This is used for globals that are declared
564 "weak" in C source code.</dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000565
Chris Lattner6af02f32004-12-09 16:11:40 +0000566 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000567 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000568 pointer to array type. When two global variables with appending linkage
569 are linked together, the two global arrays are appended together. This is
570 the LLVM, typesafe, equivalent of having the system linker append together
571 "sections" with identical names when .o files are linked.</dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000572
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000573 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000574 <dd>The semantics of this linkage follow the ELF object file model: the symbol
575 is weak until linked, if not linked, the symbol becomes null instead of
576 being an undefined reference.</dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000577
Duncan Sands12da8ce2009-03-07 15:45:40 +0000578 <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt>
Duncan Sands12da8ce2009-03-07 15:45:40 +0000579 <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000580 <dd>Some languages allow differing globals to be merged, such as two functions
581 with different semantics. Other languages, such as <tt>C++</tt>, ensure
582 that only equivalent globals are ever merged (the "one definition rule" -
583 "ODR"). Such languages can use the <tt>linkonce_odr</tt>
584 and <tt>weak_odr</tt> linkage types to indicate that the global will only
585 be merged with equivalent globals. These linkage types are otherwise the
586 same as their non-<tt>odr</tt> versions.</dd>
Duncan Sands12da8ce2009-03-07 15:45:40 +0000587
Chris Lattner6af02f32004-12-09 16:11:40 +0000588 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000589 <dd>If none of the above identifiers are used, the global is externally
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000590 visible, meaning that it participates in linkage and can be used to
591 resolve external symbol references.</dd>
Reid Spencer7972c472007-04-11 23:49:50 +0000592</dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000593
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000594<p>The next two types of linkage are targeted for Microsoft Windows platform
595 only. They are designed to support importing (exporting) symbols from (to)
596 DLLs (Dynamic Link Libraries).</p>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000597
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000598<dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000599 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000600 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000601 or variable via a global pointer to a pointer that is set up by the DLL
602 exporting the symbol. On Microsoft Windows targets, the pointer name is
603 formed by combining <code>__imp_</code> and the function or variable
604 name.</dd>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000605
606 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000607 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000608 pointer to a pointer in a DLL, so that it can be referenced with the
609 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
610 name is formed by combining <code>__imp_</code> and the function or
611 variable name.</dd>
Chris Lattner6af02f32004-12-09 16:11:40 +0000612</dl>
613
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000614<p>For example, since the "<tt>.LC0</tt>" variable is defined to be internal, if
615 another module defined a "<tt>.LC0</tt>" variable and was linked with this
616 one, one of the two would be renamed, preventing a collision. Since
617 "<tt>main</tt>" and "<tt>puts</tt>" are external (i.e., lacking any linkage
618 declarations), they are accessible outside of the current module.</p>
619
620<p>It is illegal for a function <i>declaration</i> to have any linkage type
621 other than "externally visible", <tt>dllimport</tt>
622 or <tt>extern_weak</tt>.</p>
623
Duncan Sands12da8ce2009-03-07 15:45:40 +0000624<p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000625 or <tt>weak_odr</tt> linkages.</p>
626
Chris Lattner6af02f32004-12-09 16:11:40 +0000627</div>
628
629<!-- ======================================================================= -->
630<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000631 <a name="callingconv">Calling Conventions</a>
632</div>
633
634<div class="doc_text">
635
636<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000637 and <a href="#i_invoke">invokes</a> can all have an optional calling
638 convention specified for the call. The calling convention of any pair of
639 dynamic caller/callee must match, or the behavior of the program is
640 undefined. The following calling conventions are supported by LLVM, and more
641 may be added in the future:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +0000642
643<dl>
644 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000645 <dd>This calling convention (the default if no other calling convention is
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000646 specified) matches the target C calling conventions. This calling
647 convention supports varargs function calls and tolerates some mismatch in
648 the declared prototype and implemented declaration of the function (as
649 does normal C).</dd>
Chris Lattner0132aff2005-05-06 22:57:40 +0000650
651 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000652 <dd>This calling convention attempts to make calls as fast as possible
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000653 (e.g. by passing things in registers). This calling convention allows the
654 target to use whatever tricks it wants to produce fast code for the
655 target, without having to conform to an externally specified ABI
656 (Application Binary Interface). Implementations of this convention should
657 allow arbitrary <a href="CodeGenerator.html#tailcallopt">tail call
658 optimization</a> to be supported. This calling convention does not
659 support varargs and requires the prototype of all callees to exactly match
660 the prototype of the function definition.</dd>
Chris Lattner0132aff2005-05-06 22:57:40 +0000661
662 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000663 <dd>This calling convention attempts to make code in the caller as efficient
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000664 as possible under the assumption that the call is not commonly executed.
665 As such, these calls often preserve all registers so that the call does
666 not break any live ranges in the caller side. This calling convention
667 does not support varargs and requires the prototype of all callees to
668 exactly match the prototype of the function definition.</dd>
Chris Lattner0132aff2005-05-06 22:57:40 +0000669
Chris Lattner573f64e2005-05-07 01:46:40 +0000670 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000671 <dd>Any calling convention may be specified by number, allowing
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000672 target-specific calling conventions to be used. Target specific calling
673 conventions start at 64.</dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000674</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000675
676<p>More calling conventions can be added/defined on an as-needed basis, to
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000677 support Pascal conventions or any other well-known target-independent
678 convention.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +0000679
680</div>
681
682<!-- ======================================================================= -->
683<div class="doc_subsection">
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000684 <a name="visibility">Visibility Styles</a>
685</div>
686
687<div class="doc_text">
688
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000689<p>All Global Variables and Functions have one of the following visibility
690 styles:</p>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000691
692<dl>
693 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
Chris Lattner67c37d12008-08-05 18:29:16 +0000694 <dd>On targets that use the ELF object file format, default visibility means
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000695 that the declaration is visible to other modules and, in shared libraries,
696 means that the declared entity may be overridden. On Darwin, default
697 visibility means that the declaration is visible to other modules. Default
698 visibility corresponds to "external linkage" in the language.</dd>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000699
700 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000701 <dd>Two declarations of an object with hidden visibility refer to the same
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000702 object if they are in the same shared object. Usually, hidden visibility
703 indicates that the symbol will not be placed into the dynamic symbol
704 table, so no other module (executable or shared library) can reference it
705 directly.</dd>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000706
Anton Korobeynikov39f3cff2007-04-29 18:35:00 +0000707 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
Anton Korobeynikov39f3cff2007-04-29 18:35:00 +0000708 <dd>On ELF, protected visibility indicates that the symbol will be placed in
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000709 the dynamic symbol table, but that references within the defining module
710 will bind to the local symbol. That is, the symbol cannot be overridden by
711 another module.</dd>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000712</dl>
713
714</div>
715
716<!-- ======================================================================= -->
717<div class="doc_subsection">
Chris Lattnerbc088212009-01-11 20:53:49 +0000718 <a name="namedtypes">Named Types</a>
719</div>
720
721<div class="doc_text">
722
723<p>LLVM IR allows you to specify name aliases for certain types. This can make
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000724 it easier to read the IR and make the IR more condensed (particularly when
725 recursive types are involved). An example of a name specification is:</p>
Chris Lattnerbc088212009-01-11 20:53:49 +0000726
727<div class="doc_code">
728<pre>
729%mytype = type { %mytype*, i32 }
730</pre>
731</div>
732
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000733<p>You may give a name to any <a href="#typesystem">type</a> except
734 "<a href="t_void">void</a>". Type name aliases may be used anywhere a type
735 is expected with the syntax "%mytype".</p>
Chris Lattnerbc088212009-01-11 20:53:49 +0000736
737<p>Note that type names are aliases for the structural type that they indicate,
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000738 and that you can therefore specify multiple names for the same type. This
739 often leads to confusing behavior when dumping out a .ll file. Since LLVM IR
740 uses structural typing, the name is not part of the type. When printing out
741 LLVM IR, the printer will pick <em>one name</em> to render all types of a
742 particular shape. This means that if you have code where two different
743 source types end up having the same LLVM type, that the dumper will sometimes
744 print the "wrong" or unexpected type. This is an important design point and
745 isn't going to change.</p>
Chris Lattnerbc088212009-01-11 20:53:49 +0000746
747</div>
748
Chris Lattnerbc088212009-01-11 20:53:49 +0000749<!-- ======================================================================= -->
750<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000751 <a name="globalvars">Global Variables</a>
752</div>
753
754<div class="doc_text">
755
Chris Lattner5d5aede2005-02-12 19:30:21 +0000756<p>Global variables define regions of memory allocated at compilation time
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000757 instead of run-time. Global variables may optionally be initialized, may
758 have an explicit section to be placed in, and may have an optional explicit
759 alignment specified. A variable may be defined as "thread_local", which
760 means that it will not be shared by threads (each thread will have a
761 separated copy of the variable). A variable may be defined as a global
762 "constant," which indicates that the contents of the variable
763 will <b>never</b> be modified (enabling better optimization, allowing the
764 global data to be placed in the read-only section of an executable, etc).
765 Note that variables that need runtime initialization cannot be marked
766 "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000767
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000768<p>LLVM explicitly allows <em>declarations</em> of global variables to be marked
769 constant, even if the final definition of the global is not. This capability
770 can be used to enable slightly better optimization of the program, but
771 requires the language definition to guarantee that optimizations based on the
772 'constantness' are valid for the translation units that do not include the
773 definition.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000774
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000775<p>As SSA values, global variables define pointer values that are in scope
776 (i.e. they dominate) all basic blocks in the program. Global variables
777 always define a pointer to their "content" type because they describe a
778 region of memory, and all memory objects in LLVM are accessed through
779 pointers.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000780
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000781<p>A global variable may be declared to reside in a target-specific numbered
782 address space. For targets that support them, address spaces may affect how
783 optimizations are performed and/or what target instructions are used to
784 access the variable. The default address space is zero. The address space
785 qualifier must precede any other attributes.</p>
Christopher Lamb308121c2007-12-11 09:31:00 +0000786
Chris Lattner662c8722005-11-12 00:45:07 +0000787<p>LLVM allows an explicit section to be specified for globals. If the target
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000788 supports it, it will emit globals to the section specified.</p>
Chris Lattner662c8722005-11-12 00:45:07 +0000789
Chris Lattner54611b42005-11-06 08:02:57 +0000790<p>An explicit alignment may be specified for a global. If not present, or if
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000791 the alignment is set to zero, the alignment of the global is set by the
792 target to whatever it feels convenient. If an explicit alignment is
793 specified, the global is forced to have at least that much alignment. All
794 alignments must be a power of 2.</p>
Chris Lattner54611b42005-11-06 08:02:57 +0000795
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000796<p>For example, the following defines a global in a numbered address space with
797 an initializer, section, and alignment:</p>
Chris Lattner5760c502007-01-14 00:27:09 +0000798
Bill Wendling3716c5d2007-05-29 09:04:49 +0000799<div class="doc_code">
Chris Lattner5760c502007-01-14 00:27:09 +0000800<pre>
Dan Gohmanaaa679b2009-01-11 00:40:00 +0000801@G = addrspace(5) constant float 1.0, section "foo", align 4
Chris Lattner5760c502007-01-14 00:27:09 +0000802</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000803</div>
Chris Lattner5760c502007-01-14 00:27:09 +0000804
Chris Lattner6af02f32004-12-09 16:11:40 +0000805</div>
806
807
808<!-- ======================================================================= -->
809<div class="doc_subsection">
810 <a name="functionstructure">Functions</a>
811</div>
812
813<div class="doc_text">
814
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000815<p>LLVM function definitions consist of the "<tt>define</tt>" keyord, an
816 optional <a href="#linkage">linkage type</a>, an optional
817 <a href="#visibility">visibility style</a>, an optional
818 <a href="#callingconv">calling convention</a>, a return type, an optional
819 <a href="#paramattrs">parameter attribute</a> for the return type, a function
820 name, a (possibly empty) argument list (each with optional
821 <a href="#paramattrs">parameter attributes</a>), optional
822 <a href="#fnattrs">function attributes</a>, an optional section, an optional
823 alignment, an optional <a href="#gc">garbage collector name</a>, an opening
824 curly brace, a list of basic blocks, and a closing curly brace.</p>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000825
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000826<p>LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
827 optional <a href="#linkage">linkage type</a>, an optional
828 <a href="#visibility">visibility style</a>, an optional
829 <a href="#callingconv">calling convention</a>, a return type, an optional
830 <a href="#paramattrs">parameter attribute</a> for the return type, a function
831 name, a possibly empty list of arguments, an optional alignment, and an
832 optional <a href="#gc">garbage collector name</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000833
Chris Lattner67c37d12008-08-05 18:29:16 +0000834<p>A function definition contains a list of basic blocks, forming the CFG
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000835 (Control Flow Graph) for the function. Each basic block may optionally start
836 with a label (giving the basic block a symbol table entry), contains a list
837 of instructions, and ends with a <a href="#terminators">terminator</a>
838 instruction (such as a branch or function return).</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000839
Chris Lattnera59fb102007-06-08 16:52:14 +0000840<p>The first basic block in a function is special in two ways: it is immediately
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000841 executed on entrance to the function, and it is not allowed to have
842 predecessor basic blocks (i.e. there can not be any branches to the entry
843 block of a function). Because the block can have no predecessors, it also
844 cannot have any <a href="#i_phi">PHI nodes</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000845
Chris Lattner662c8722005-11-12 00:45:07 +0000846<p>LLVM allows an explicit section to be specified for functions. If the target
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000847 supports it, it will emit functions to the section specified.</p>
Chris Lattner662c8722005-11-12 00:45:07 +0000848
Chris Lattner54611b42005-11-06 08:02:57 +0000849<p>An explicit alignment may be specified for a function. If not present, or if
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000850 the alignment is set to zero, the alignment of the function is set by the
851 target to whatever it feels convenient. If an explicit alignment is
852 specified, the function is forced to have at least that much alignment. All
853 alignments must be a power of 2.</p>
Chris Lattner54611b42005-11-06 08:02:57 +0000854
Bill Wendling30235112009-07-20 02:39:26 +0000855<h5>Syntax:</h5>
Devang Patel02256232008-10-07 17:48:33 +0000856<div class="doc_code">
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000857<pre>
Chris Lattner0ae02092008-10-13 16:55:18 +0000858define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>]
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000859 [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>]
860 &lt;ResultType&gt; @&lt;FunctionName&gt; ([argument list])
861 [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N]
862 [<a href="#gc">gc</a>] { ... }
863</pre>
Devang Patel02256232008-10-07 17:48:33 +0000864</div>
865
Chris Lattner6af02f32004-12-09 16:11:40 +0000866</div>
867
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000868<!-- ======================================================================= -->
869<div class="doc_subsection">
870 <a name="aliasstructure">Aliases</a>
871</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000872
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000873<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000874
875<p>Aliases act as "second name" for the aliasee value (which can be either
876 function, global variable, another alias or bitcast of global value). Aliases
877 may have an optional <a href="#linkage">linkage type</a>, and an
878 optional <a href="#visibility">visibility style</a>.</p>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000879
Bill Wendling30235112009-07-20 02:39:26 +0000880<h5>Syntax:</h5>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000881<div class="doc_code">
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000882<pre>
Duncan Sands7e99a942008-09-12 20:48:21 +0000883@&lt;Name&gt; = alias [Linkage] [Visibility] &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000884</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000885</div>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000886
887</div>
888
Chris Lattner91c15c42006-01-23 23:23:47 +0000889<!-- ======================================================================= -->
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000890<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000891
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000892<div class="doc_text">
893
894<p>The return type and each parameter of a function type may have a set of
895 <i>parameter attributes</i> associated with them. Parameter attributes are
896 used to communicate additional information about the result or parameters of
897 a function. Parameter attributes are considered to be part of the function,
898 not of the function type, so functions with different parameter attributes
899 can have the same function type.</p>
900
901<p>Parameter attributes are simple keywords that follow the type specified. If
902 multiple parameter attributes are needed, they are space separated. For
903 example:</p>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000904
905<div class="doc_code">
906<pre>
Nick Lewyckydac78d82009-02-15 23:06:14 +0000907declare i32 @printf(i8* noalias nocapture, ...)
Chris Lattnerd2597d72008-10-04 18:33:34 +0000908declare i32 @atoi(i8 zeroext)
909declare signext i8 @returns_signed_char()
Bill Wendling3716c5d2007-05-29 09:04:49 +0000910</pre>
911</div>
912
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000913<p>Note that any attributes for the function result (<tt>nounwind</tt>,
914 <tt>readonly</tt>) come immediately after the argument list.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000915
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000916<p>Currently, only the following parameter attributes are defined:</p>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000917
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000918<dl>
919 <dt><tt>zeroext</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000920 <dd>This indicates to the code generator that the parameter or return value
921 should be zero-extended to a 32-bit value by the caller (for a parameter)
922 or the callee (for a return value).</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000923
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000924 <dt><tt>signext</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000925 <dd>This indicates to the code generator that the parameter or return value
926 should be sign-extended to a 32-bit value by the caller (for a parameter)
927 or the callee (for a return value).</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000928
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000929 <dt><tt>inreg</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000930 <dd>This indicates that this parameter or return value should be treated in a
931 special target-dependent fashion during while emitting code for a function
932 call or return (usually, by putting it in a register as opposed to memory,
933 though some targets use it to distinguish between two different kinds of
934 registers). Use of this attribute is target-specific.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000935
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000936 <dt><tt><a name="byval">byval</a></tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000937 <dd>This indicates that the pointer parameter should really be passed by value
938 to the function. The attribute implies that a hidden copy of the pointee
939 is made between the caller and the callee, so the callee is unable to
940 modify the value in the callee. This attribute is only valid on LLVM
941 pointer arguments. It is generally used to pass structs and arrays by
942 value, but is also valid on pointers to scalars. The copy is considered
943 to belong to the caller not the callee (for example,
944 <tt><a href="#readonly">readonly</a></tt> functions should not write to
945 <tt>byval</tt> parameters). This is not a valid attribute for return
946 values. The byval attribute also supports specifying an alignment with
947 the align attribute. This has a target-specific effect on the code
948 generator that usually indicates a desired alignment for the synthesized
949 stack slot.</dd>
950
951 <dt><tt>sret</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000952 <dd>This indicates that the pointer parameter specifies the address of a
953 structure that is the return value of the function in the source program.
954 This pointer must be guaranteed by the caller to be valid: loads and
955 stores to the structure may be assumed by the callee to not to trap. This
956 may only be applied to the first parameter. This is not a valid attribute
957 for return values. </dd>
958
959 <dt><tt>noalias</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000960 <dd>This indicates that the pointer does not alias any global or any other
961 parameter. The caller is responsible for ensuring that this is the
962 case. On a function return value, <tt>noalias</tt> additionally indicates
963 that the pointer does not alias any other pointers visible to the
964 caller. For further details, please see the discussion of the NoAlias
965 response in
966 <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
967 analysis</a>.</dd>
968
969 <dt><tt>nocapture</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000970 <dd>This indicates that the callee does not make any copies of the pointer
971 that outlive the callee itself. This is not a valid attribute for return
972 values.</dd>
973
974 <dt><tt>nest</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000975 <dd>This indicates that the pointer parameter can be excised using the
976 <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid
977 attribute for return values.</dd>
978</dl>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000979
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000980</div>
981
982<!-- ======================================================================= -->
Chris Lattner91c15c42006-01-23 23:23:47 +0000983<div class="doc_subsection">
Gordon Henriksen71183b62007-12-10 03:18:06 +0000984 <a name="gc">Garbage Collector Names</a>
985</div>
986
987<div class="doc_text">
Gordon Henriksen71183b62007-12-10 03:18:06 +0000988
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000989<p>Each function may specify a garbage collector name, which is simply a
990 string:</p>
991
992<div class="doc_code">
993<pre>
994define void @f() gc "name" { ...
995</pre>
996</div>
Gordon Henriksen71183b62007-12-10 03:18:06 +0000997
998<p>The compiler declares the supported values of <i>name</i>. Specifying a
Bill Wendlingd9a66f72009-07-20 02:29:24 +0000999 collector which will cause the compiler to alter its output in order to
1000 support the named garbage collection algorithm.</p>
1001
Gordon Henriksen71183b62007-12-10 03:18:06 +00001002</div>
1003
1004<!-- ======================================================================= -->
1005<div class="doc_subsection">
Devang Patel9eb525d2008-09-26 23:51:19 +00001006 <a name="fnattrs">Function Attributes</a>
Devang Patelcaacdba2008-09-04 23:05:13 +00001007</div>
1008
1009<div class="doc_text">
Devang Patel9eb525d2008-09-26 23:51:19 +00001010
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001011<p>Function attributes are set to communicate additional information about a
1012 function. Function attributes are considered to be part of the function, not
1013 of the function type, so functions with different parameter attributes can
1014 have the same function type.</p>
Devang Patel9eb525d2008-09-26 23:51:19 +00001015
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001016<p>Function attributes are simple keywords that follow the type specified. If
1017 multiple attributes are needed, they are space separated. For example:</p>
Devang Patelcaacdba2008-09-04 23:05:13 +00001018
1019<div class="doc_code">
Bill Wendlingb175fa42008-09-07 10:26:33 +00001020<pre>
Devang Patel9eb525d2008-09-26 23:51:19 +00001021define void @f() noinline { ... }
1022define void @f() alwaysinline { ... }
1023define void @f() alwaysinline optsize { ... }
1024define void @f() optsize
Bill Wendlingb175fa42008-09-07 10:26:33 +00001025</pre>
Devang Patelcaacdba2008-09-04 23:05:13 +00001026</div>
1027
Bill Wendlingb175fa42008-09-07 10:26:33 +00001028<dl>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001029 <dt><tt>alwaysinline</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001030 <dd>This attribute indicates that the inliner should attempt to inline this
1031 function into callers whenever possible, ignoring any active inlining size
1032 threshold for this caller.</dd>
Bill Wendlingb175fa42008-09-07 10:26:33 +00001033
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001034 <dt><tt>noinline</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001035 <dd>This attribute indicates that the inliner should never inline this
1036 function in any situation. This attribute may not be used together with
1037 the <tt>alwaysinline</tt> attribute.</dd>
Devang Patel9eb525d2008-09-26 23:51:19 +00001038
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001039 <dt><tt>optsize</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001040 <dd>This attribute suggests that optimization passes and code generator passes
1041 make choices that keep the code size of this function low, and otherwise
1042 do optimizations specifically to reduce code size.</dd>
Devang Patel9eb525d2008-09-26 23:51:19 +00001043
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001044 <dt><tt>noreturn</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001045 <dd>This function attribute indicates that the function never returns
1046 normally. This produces undefined behavior at runtime if the function
1047 ever does dynamically return.</dd>
Bill Wendlinga8130172008-11-13 01:02:51 +00001048
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001049 <dt><tt>nounwind</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001050 <dd>This function attribute indicates that the function never returns with an
1051 unwind or exceptional control flow. If the function does unwind, its
1052 runtime behavior is undefined.</dd>
Bill Wendling0f5541e2008-11-26 19:07:40 +00001053
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001054 <dt><tt>readnone</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001055 <dd>This attribute indicates that the function computes its result (or decides
1056 to unwind an exception) based strictly on its arguments, without
1057 dereferencing any pointer arguments or otherwise accessing any mutable
1058 state (e.g. memory, control registers, etc) visible to caller functions.
1059 It does not write through any pointer arguments
1060 (including <tt><a href="#byval">byval</a></tt> arguments) and never
1061 changes any state visible to callers. This means that it cannot unwind
1062 exceptions by calling the <tt>C++</tt> exception throwing methods, but
1063 could use the <tt>unwind</tt> instruction.</dd>
Devang Patel310fd4a2009-06-12 19:45:19 +00001064
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001065 <dt><tt><a name="readonly">readonly</a></tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001066 <dd>This attribute indicates that the function does not write through any
1067 pointer arguments (including <tt><a href="#byval">byval</a></tt>
1068 arguments) or otherwise modify any state (e.g. memory, control registers,
1069 etc) visible to caller functions. It may dereference pointer arguments
1070 and read state that may be set in the caller. A readonly function always
1071 returns the same value (or unwinds an exception identically) when called
1072 with the same set of arguments and global state. It cannot unwind an
1073 exception by calling the <tt>C++</tt> exception throwing methods, but may
1074 use the <tt>unwind</tt> instruction.</dd>
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +00001075
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001076 <dt><tt><a name="ssp">ssp</a></tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001077 <dd>This attribute indicates that the function should emit a stack smashing
1078 protector. It is in the form of a "canary"&mdash;a random value placed on
1079 the stack before the local variables that's checked upon return from the
1080 function to see if it has been overwritten. A heuristic is used to
1081 determine if a function needs stack protectors or not.<br>
1082<br>
1083 If a function that has an <tt>ssp</tt> attribute is inlined into a
1084 function that doesn't have an <tt>ssp</tt> attribute, then the resulting
1085 function will have an <tt>ssp</tt> attribute.</dd>
1086
1087 <dt><tt>sspreq</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001088 <dd>This attribute indicates that the function should <em>always</em> emit a
1089 stack smashing protector. This overrides
Bill Wendling30235112009-07-20 02:39:26 +00001090 the <tt><a href="#ssp">ssp</a></tt> function attribute.<br>
1091<br>
1092 If a function that has an <tt>sspreq</tt> attribute is inlined into a
1093 function that doesn't have an <tt>sspreq</tt> attribute or which has
1094 an <tt>ssp</tt> attribute, then the resulting function will have
1095 an <tt>sspreq</tt> attribute.</dd>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001096
1097 <dt><tt>noredzone</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001098 <dd>This attribute indicates that the code generator should not use a red
1099 zone, even if the target-specific ABI normally permits it.</dd>
1100
1101 <dt><tt>noimplicitfloat</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001102 <dd>This attributes disables implicit floating point instructions.</dd>
1103
1104 <dt><tt>naked</tt></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001105 <dd>This attribute disables prologue / epilogue emission for the function.
1106 This can have very system-specific consequences.</dd>
Bill Wendlingb175fa42008-09-07 10:26:33 +00001107</dl>
1108
Devang Patelcaacdba2008-09-04 23:05:13 +00001109</div>
1110
1111<!-- ======================================================================= -->
1112<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +00001113 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +00001114</div>
1115
1116<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001117
1118<p>Modules may contain "module-level inline asm" blocks, which corresponds to
1119 the GCC "file scope inline asm" blocks. These blocks are internally
1120 concatenated by LLVM and treated as a single unit, but may be separated in
1121 the <tt>.ll</tt> file if desired. The syntax is very simple:</p>
Chris Lattner91c15c42006-01-23 23:23:47 +00001122
Bill Wendling3716c5d2007-05-29 09:04:49 +00001123<div class="doc_code">
1124<pre>
1125module asm "inline asm code goes here"
1126module asm "more can go here"
1127</pre>
1128</div>
Chris Lattner91c15c42006-01-23 23:23:47 +00001129
1130<p>The strings can contain any character by escaping non-printable characters.
1131 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001132 for the number.</p>
Chris Lattner91c15c42006-01-23 23:23:47 +00001133
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001134<p>The inline asm code is simply printed to the machine code .s file when
1135 assembly code is generated.</p>
1136
Chris Lattner91c15c42006-01-23 23:23:47 +00001137</div>
Chris Lattner6af02f32004-12-09 16:11:40 +00001138
Reid Spencer50c723a2007-02-19 23:54:10 +00001139<!-- ======================================================================= -->
1140<div class="doc_subsection">
1141 <a name="datalayout">Data Layout</a>
1142</div>
1143
1144<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001145
Reid Spencer50c723a2007-02-19 23:54:10 +00001146<p>A module may specify a target specific data layout string that specifies how
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001147 data is to be laid out in memory. The syntax for the data layout is
1148 simply:</p>
1149
1150<div class="doc_code">
1151<pre>
1152target datalayout = "<i>layout specification</i>"
1153</pre>
1154</div>
1155
1156<p>The <i>layout specification</i> consists of a list of specifications
1157 separated by the minus sign character ('-'). Each specification starts with
1158 a letter and may include other information after the letter to define some
1159 aspect of the data layout. The specifications accepted are as follows:</p>
1160
Reid Spencer50c723a2007-02-19 23:54:10 +00001161<dl>
1162 <dt><tt>E</tt></dt>
1163 <dd>Specifies that the target lays out data in big-endian form. That is, the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001164 bits with the most significance have the lowest address location.</dd>
1165
Reid Spencer50c723a2007-02-19 23:54:10 +00001166 <dt><tt>e</tt></dt>
Chris Lattner67c37d12008-08-05 18:29:16 +00001167 <dd>Specifies that the target lays out data in little-endian form. That is,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001168 the bits with the least significance have the lowest address
1169 location.</dd>
1170
Reid Spencer50c723a2007-02-19 23:54:10 +00001171 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1172 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001173 <i>preferred</i> alignments. All sizes are in bits. Specifying
1174 the <i>pref</i> alignment is optional. If omitted, the
1175 preceding <tt>:</tt> should be omitted too.</dd>
1176
Reid Spencer50c723a2007-02-19 23:54:10 +00001177 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1178 <dd>This specifies the alignment for an integer type of a given bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001179 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
1180
Reid Spencer50c723a2007-02-19 23:54:10 +00001181 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1182 <dd>This specifies the alignment for a vector type of a given bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001183 <i>size</i>.</dd>
1184
Reid Spencer50c723a2007-02-19 23:54:10 +00001185 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1186 <dd>This specifies the alignment for a floating point type of a given bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001187 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
1188 (double).</dd>
1189
Reid Spencer50c723a2007-02-19 23:54:10 +00001190 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1191 <dd>This specifies the alignment for an aggregate type of a given bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001192 <i>size</i>.</dd>
1193
Daniel Dunbar7921a592009-06-08 22:17:53 +00001194 <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1195 <dd>This specifies the alignment for a stack object of a given bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001196 <i>size</i>.</dd>
Reid Spencer50c723a2007-02-19 23:54:10 +00001197</dl>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001198
Reid Spencer50c723a2007-02-19 23:54:10 +00001199<p>When constructing the data layout for a given target, LLVM starts with a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001200 default set of specifications which are then (possibly) overriden by the
1201 specifications in the <tt>datalayout</tt> keyword. The default specifications
1202 are given in this list:</p>
1203
Reid Spencer50c723a2007-02-19 23:54:10 +00001204<ul>
1205 <li><tt>E</tt> - big endian</li>
1206 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
1207 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
1208 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
1209 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
1210 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
Chris Lattner67c37d12008-08-05 18:29:16 +00001211 <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred
Reid Spencer50c723a2007-02-19 23:54:10 +00001212 alignment of 64-bits</li>
1213 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
1214 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
1215 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
1216 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
1217 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
Daniel Dunbar7921a592009-06-08 22:17:53 +00001218 <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li>
Reid Spencer50c723a2007-02-19 23:54:10 +00001219</ul>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001220
1221<p>When LLVM is determining the alignment for a given type, it uses the
1222 following rules:</p>
1223
Reid Spencer50c723a2007-02-19 23:54:10 +00001224<ol>
1225 <li>If the type sought is an exact match for one of the specifications, that
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001226 specification is used.</li>
1227
Reid Spencer50c723a2007-02-19 23:54:10 +00001228 <li>If no match is found, and the type sought is an integer type, then the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001229 smallest integer type that is larger than the bitwidth of the sought type
1230 is used. If none of the specifications are larger than the bitwidth then
1231 the the largest integer type is used. For example, given the default
1232 specifications above, the i7 type will use the alignment of i8 (next
1233 largest) while both i65 and i256 will use the alignment of i64 (largest
1234 specified).</li>
1235
Reid Spencer50c723a2007-02-19 23:54:10 +00001236 <li>If no match is found, and the type sought is a vector type, then the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001237 largest vector type that is smaller than the sought vector type will be
1238 used as a fall back. This happens because &lt;128 x double&gt; can be
1239 implemented in terms of 64 &lt;2 x double&gt;, for example.</li>
Reid Spencer50c723a2007-02-19 23:54:10 +00001240</ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001241
Reid Spencer50c723a2007-02-19 23:54:10 +00001242</div>
Chris Lattner6af02f32004-12-09 16:11:40 +00001243
Chris Lattner2f7c9632001-06-06 20:29:01 +00001244<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001245<div class="doc_section"> <a name="typesystem">Type System</a> </div>
1246<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +00001247
Misha Brukman76307852003-11-08 01:05:38 +00001248<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +00001249
Misha Brukman76307852003-11-08 01:05:38 +00001250<p>The LLVM type system is one of the most important features of the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001251 intermediate representation. Being typed enables a number of optimizations
1252 to be performed on the intermediate representation directly, without having
1253 to do extra analyses on the side before the transformation. A strong type
1254 system makes it easier to read the generated code and enables novel analyses
1255 and transformations that are not feasible to perform on normal three address
1256 code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +00001257
1258</div>
1259
Chris Lattner2f7c9632001-06-06 20:29:01 +00001260<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001261<div class="doc_subsection"> <a name="t_classifications">Type
Chris Lattner48b383b02003-11-25 01:02:51 +00001262Classifications</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001263
Misha Brukman76307852003-11-08 01:05:38 +00001264<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001265
1266<p>The types fall into a few useful classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001267
1268<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001269 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001270 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001271 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001272 <td><a href="#t_integer">integer</a></td>
Reid Spencer138249b2007-05-16 18:44:01 +00001273 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001274 </tr>
1275 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001276 <td><a href="#t_floating">floating point</a></td>
1277 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001278 </tr>
1279 <tr>
1280 <td><a name="t_firstclass">first class</a></td>
Chris Lattner7824d182008-01-04 04:32:38 +00001281 <td><a href="#t_integer">integer</a>,
1282 <a href="#t_floating">floating point</a>,
1283 <a href="#t_pointer">pointer</a>,
Dan Gohman08783a882008-06-18 18:42:13 +00001284 <a href="#t_vector">vector</a>,
Dan Gohmanb9d66602008-05-12 23:51:09 +00001285 <a href="#t_struct">structure</a>,
1286 <a href="#t_array">array</a>,
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001287 <a href="#t_label">label</a>,
1288 <a href="#t_metadata">metadata</a>.
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001289 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001290 </tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001291 <tr>
1292 <td><a href="#t_primitive">primitive</a></td>
1293 <td><a href="#t_label">label</a>,
1294 <a href="#t_void">void</a>,
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001295 <a href="#t_floating">floating point</a>,
1296 <a href="#t_metadata">metadata</a>.</td>
Chris Lattner7824d182008-01-04 04:32:38 +00001297 </tr>
1298 <tr>
1299 <td><a href="#t_derived">derived</a></td>
1300 <td><a href="#t_integer">integer</a>,
1301 <a href="#t_array">array</a>,
1302 <a href="#t_function">function</a>,
1303 <a href="#t_pointer">pointer</a>,
1304 <a href="#t_struct">structure</a>,
1305 <a href="#t_pstruct">packed structure</a>,
1306 <a href="#t_vector">vector</a>,
1307 <a href="#t_opaque">opaque</a>.
Dan Gohman93bf60d2008-10-14 16:32:04 +00001308 </td>
Chris Lattner7824d182008-01-04 04:32:38 +00001309 </tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001310 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +00001311</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001312
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001313<p>The <a href="#t_firstclass">first class</a> types are perhaps the most
1314 important. Values of these types are the only ones which can be produced by
1315 instructions, passed as arguments, or used as operands to instructions.</p>
1316
Misha Brukman76307852003-11-08 01:05:38 +00001317</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001318
Chris Lattner2f7c9632001-06-06 20:29:01 +00001319<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001320<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner43542b32008-01-04 04:34:14 +00001321
Chris Lattner7824d182008-01-04 04:32:38 +00001322<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001323
Chris Lattner7824d182008-01-04 04:32:38 +00001324<p>The primitive types are the fundamental building blocks of the LLVM
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001325 system.</p>
Chris Lattner7824d182008-01-04 04:32:38 +00001326
Chris Lattner43542b32008-01-04 04:34:14 +00001327</div>
1328
Chris Lattner7824d182008-01-04 04:32:38 +00001329<!-- _______________________________________________________________________ -->
1330<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1331
1332<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001333
1334<table>
1335 <tbody>
1336 <tr><th>Type</th><th>Description</th></tr>
1337 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1338 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1339 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1340 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1341 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1342 </tbody>
1343</table>
1344
Chris Lattner7824d182008-01-04 04:32:38 +00001345</div>
1346
1347<!-- _______________________________________________________________________ -->
1348<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1349
1350<div class="doc_text">
Bill Wendling30235112009-07-20 02:39:26 +00001351
Chris Lattner7824d182008-01-04 04:32:38 +00001352<h5>Overview:</h5>
1353<p>The void type does not represent any value and has no size.</p>
1354
1355<h5>Syntax:</h5>
Chris Lattner7824d182008-01-04 04:32:38 +00001356<pre>
1357 void
1358</pre>
Bill Wendling30235112009-07-20 02:39:26 +00001359
Chris Lattner7824d182008-01-04 04:32:38 +00001360</div>
1361
1362<!-- _______________________________________________________________________ -->
1363<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1364
1365<div class="doc_text">
Bill Wendling30235112009-07-20 02:39:26 +00001366
Chris Lattner7824d182008-01-04 04:32:38 +00001367<h5>Overview:</h5>
1368<p>The label type represents code labels.</p>
1369
1370<h5>Syntax:</h5>
Chris Lattner7824d182008-01-04 04:32:38 +00001371<pre>
1372 label
1373</pre>
Bill Wendling30235112009-07-20 02:39:26 +00001374
Chris Lattner7824d182008-01-04 04:32:38 +00001375</div>
1376
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001377<!-- _______________________________________________________________________ -->
1378<div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div>
1379
1380<div class="doc_text">
Bill Wendling30235112009-07-20 02:39:26 +00001381
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001382<h5>Overview:</h5>
1383<p>The metadata type represents embedded metadata. The only derived type that
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001384 may contain metadata is <tt>metadata*</tt> or a function type that returns or
1385 takes metadata typed parameters, but not pointer to metadata types.</p>
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001386
1387<h5>Syntax:</h5>
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001388<pre>
1389 metadata
1390</pre>
Bill Wendling30235112009-07-20 02:39:26 +00001391
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001392</div>
1393
Chris Lattner7824d182008-01-04 04:32:38 +00001394
1395<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001396<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001397
Misha Brukman76307852003-11-08 01:05:38 +00001398<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001399
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001400<p>The real power in LLVM comes from the derived types in the system. This is
1401 what allows a programmer to represent arrays, functions, pointers, and other
1402 useful types. Note that these derived types may be recursive: For example,
1403 it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001404
Misha Brukman76307852003-11-08 01:05:38 +00001405</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001406
Chris Lattner2f7c9632001-06-06 20:29:01 +00001407<!-- _______________________________________________________________________ -->
Reid Spencer138249b2007-05-16 18:44:01 +00001408<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1409
1410<div class="doc_text">
1411
1412<h5>Overview:</h5>
1413<p>The integer type is a very simple derived type that simply specifies an
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001414 arbitrary bit width for the integer type desired. Any bit width from 1 bit to
1415 2^23-1 (about 8 million) can be specified.</p>
Reid Spencer138249b2007-05-16 18:44:01 +00001416
1417<h5>Syntax:</h5>
Reid Spencer138249b2007-05-16 18:44:01 +00001418<pre>
1419 iN
1420</pre>
1421
1422<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001423 value.</p>
Reid Spencer138249b2007-05-16 18:44:01 +00001424
1425<h5>Examples:</h5>
1426<table class="layout">
Nick Lewyckyaab930a2009-05-24 02:46:06 +00001427 <tr class="layout">
1428 <td class="left"><tt>i1</tt></td>
1429 <td class="left">a single-bit integer.</td>
Reid Spencer138249b2007-05-16 18:44:01 +00001430 </tr>
Nick Lewyckyaab930a2009-05-24 02:46:06 +00001431 <tr class="layout">
1432 <td class="left"><tt>i32</tt></td>
1433 <td class="left">a 32-bit integer.</td>
1434 </tr>
1435 <tr class="layout">
1436 <td class="left"><tt>i1942652</tt></td>
1437 <td class="left">a really big integer of over 1 million bits.</td>
1438 </tr>
Reid Spencer138249b2007-05-16 18:44:01 +00001439</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001440
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001441<p>Note that the code generator does not yet support large integer types to be
1442 used as function return types. The specific limit on how large a return type
1443 the code generator can currently handle is target-dependent; currently it's
1444 often 64 bits for 32-bit targets and 128 bits for 64-bit targets.</p>
Dan Gohman142ccc02009-01-24 15:58:40 +00001445
Bill Wendling3716c5d2007-05-29 09:04:49 +00001446</div>
Reid Spencer138249b2007-05-16 18:44:01 +00001447
1448<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001449<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001450
Misha Brukman76307852003-11-08 01:05:38 +00001451<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001452
Chris Lattner2f7c9632001-06-06 20:29:01 +00001453<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001454<p>The array type is a very simple derived type that arranges elements
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001455 sequentially in memory. The array type requires a size (number of elements)
1456 and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001457
Chris Lattner590645f2002-04-14 06:13:44 +00001458<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +00001459<pre>
1460 [&lt;# elements&gt; x &lt;elementtype&gt;]
1461</pre>
1462
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001463<p>The number of elements is a constant integer value; <tt>elementtype</tt> may
1464 be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001465
Chris Lattner590645f2002-04-14 06:13:44 +00001466<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001467<table class="layout">
1468 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001469 <td class="left"><tt>[40 x i32]</tt></td>
1470 <td class="left">Array of 40 32-bit integer values.</td>
1471 </tr>
1472 <tr class="layout">
1473 <td class="left"><tt>[41 x i32]</tt></td>
1474 <td class="left">Array of 41 32-bit integer values.</td>
1475 </tr>
1476 <tr class="layout">
1477 <td class="left"><tt>[4 x i8]</tt></td>
1478 <td class="left">Array of 4 8-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001479 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001480</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001481<p>Here are some examples of multidimensional arrays:</p>
1482<table class="layout">
1483 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001484 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1485 <td class="left">3x4 array of 32-bit integer values.</td>
1486 </tr>
1487 <tr class="layout">
1488 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1489 <td class="left">12x10 array of single precision floating point values.</td>
1490 </tr>
1491 <tr class="layout">
1492 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1493 <td class="left">2x3x4 array of 16-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001494 </tr>
1495</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001496
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001497<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1498 length array. Normally, accesses past the end of an array are undefined in
1499 LLVM (e.g. it is illegal to access the 5th element of a 3 element array). As
1500 a special case, however, zero length arrays are recognized to be variable
1501 length. This allows implementation of 'pascal style arrays' with the LLVM
1502 type "<tt>{ i32, [0 x float]}</tt>", for example.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001503
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001504<p>Note that the code generator does not yet support large aggregate types to be
1505 used as function return types. The specific limit on how large an aggregate
1506 return type the code generator can currently handle is target-dependent, and
1507 also dependent on the aggregate element types.</p>
Dan Gohman142ccc02009-01-24 15:58:40 +00001508
Misha Brukman76307852003-11-08 01:05:38 +00001509</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001510
Chris Lattner2f7c9632001-06-06 20:29:01 +00001511<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001512<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001513
Misha Brukman76307852003-11-08 01:05:38 +00001514<div class="doc_text">
Chris Lattnerda508ac2008-04-23 04:59:35 +00001515
Chris Lattner2f7c9632001-06-06 20:29:01 +00001516<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001517<p>The function type can be thought of as a function signature. It consists of
1518 a return type and a list of formal parameter types. The return type of a
1519 function type is a scalar type, a void type, or a struct type. If the return
1520 type is a struct type then all struct elements must be of first class types,
1521 and the struct must have at least one element.</p>
Devang Pateld6cff512008-03-10 20:49:15 +00001522
Chris Lattner2f7c9632001-06-06 20:29:01 +00001523<h5>Syntax:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00001524<pre>
1525 &lt;returntype list&gt; (&lt;parameter list&gt;)
1526</pre>
1527
John Criswell4c0cf7f2005-10-24 16:17:18 +00001528<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001529 specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
1530 which indicates that the function takes a variable number of arguments.
1531 Variable argument functions can access their arguments with
1532 the <a href="#int_varargs">variable argument handling intrinsic</a>
1533 functions. '<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1534 <a href="#t_firstclass">first class</a> type specifiers.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00001535
Chris Lattner2f7c9632001-06-06 20:29:01 +00001536<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001537<table class="layout">
1538 <tr class="layout">
Reid Spencer58c08712006-12-31 07:18:34 +00001539 <td class="left"><tt>i32 (i32)</tt></td>
1540 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001541 </td>
Reid Spencer58c08712006-12-31 07:18:34 +00001542 </tr><tr class="layout">
Reid Spencer314e1cb2007-07-19 23:13:04 +00001543 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencer655dcc62006-12-31 07:20:23 +00001544 </tt></td>
Reid Spencer58c08712006-12-31 07:18:34 +00001545 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1546 an <tt>i16</tt> that should be sign extended and a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001547 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer58c08712006-12-31 07:18:34 +00001548 <tt>float</tt>.
1549 </td>
1550 </tr><tr class="layout">
1551 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1552 <td class="left">A vararg function that takes at least one
Reid Spencer3e628eb92007-01-04 16:43:23 +00001553 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer58c08712006-12-31 07:18:34 +00001554 which returns an integer. This is the signature for <tt>printf</tt> in
1555 LLVM.
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001556 </td>
Devang Patele3dfc1c2008-03-24 05:35:41 +00001557 </tr><tr class="layout">
1558 <td class="left"><tt>{i32, i32} (i32)</tt></td>
Misha Brukmanc9813bd2008-11-27 06:41:20 +00001559 <td class="left">A function taking an <tt>i32</tt>, returning two
1560 <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
Devang Patele3dfc1c2008-03-24 05:35:41 +00001561 </td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001562 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001563</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001564
Misha Brukman76307852003-11-08 01:05:38 +00001565</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001566
Chris Lattner2f7c9632001-06-06 20:29:01 +00001567<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001568<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001569
Misha Brukman76307852003-11-08 01:05:38 +00001570<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001571
Chris Lattner2f7c9632001-06-06 20:29:01 +00001572<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001573<p>The structure type is used to represent a collection of data members together
1574 in memory. The packing of the field types is defined to match the ABI of the
1575 underlying processor. The elements of a structure may be any type that has a
1576 size.</p>
1577
1578<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1579 '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1580 the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1581
Chris Lattner2f7c9632001-06-06 20:29:01 +00001582<h5>Syntax:</h5>
Bill Wendling30235112009-07-20 02:39:26 +00001583<pre>
1584 { &lt;type list&gt; }
1585</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001586
Chris Lattner2f7c9632001-06-06 20:29:01 +00001587<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001588<table class="layout">
1589 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001590 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1591 <td class="left">A triple of three <tt>i32</tt> values</td>
1592 </tr><tr class="layout">
1593 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1594 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1595 second element is a <a href="#t_pointer">pointer</a> to a
1596 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1597 an <tt>i32</tt>.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001598 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001599</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001600
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001601<p>Note that the code generator does not yet support large aggregate types to be
1602 used as function return types. The specific limit on how large an aggregate
1603 return type the code generator can currently handle is target-dependent, and
1604 also dependent on the aggregate element types.</p>
Dan Gohman142ccc02009-01-24 15:58:40 +00001605
Misha Brukman76307852003-11-08 01:05:38 +00001606</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001607
Chris Lattner2f7c9632001-06-06 20:29:01 +00001608<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001609<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1610</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001611
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001612<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001613
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001614<h5>Overview:</h5>
1615<p>The packed structure type is used to represent a collection of data members
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001616 together in memory. There is no padding between fields. Further, the
1617 alignment of a packed structure is 1 byte. The elements of a packed
1618 structure may be any type that has a size.</p>
1619
1620<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> and
1621 '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a field with
1622 the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
1623
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001624<h5>Syntax:</h5>
Bill Wendling30235112009-07-20 02:39:26 +00001625<pre>
1626 &lt; { &lt;type list&gt; } &gt;
1627</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001628
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001629<h5>Examples:</h5>
1630<table class="layout">
1631 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001632 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1633 <td class="left">A triple of three <tt>i32</tt> values</td>
1634 </tr><tr class="layout">
Bill Wendlingb175fa42008-09-07 10:26:33 +00001635 <td class="left">
1636<tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)*&nbsp;}&nbsp;&gt;</tt></td>
Jeff Cohen5819f182007-04-22 01:17:39 +00001637 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1638 second element is a <a href="#t_pointer">pointer</a> to a
1639 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1640 an <tt>i32</tt>.</td>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001641 </tr>
1642</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001643
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001644</div>
1645
1646<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001647<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Chris Lattner4a67c912009-02-08 19:53:29 +00001648
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001649<div class="doc_text">
1650
1651<h5>Overview:</h5>
1652<p>As in many languages, the pointer type represents a pointer or reference to
1653 another object, which must live in memory. Pointer types may have an optional
1654 address space attribute defining the target-specific numbered address space
1655 where the pointed-to object resides. The default address space is zero.</p>
1656
1657<p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does it
1658 permit pointers to labels (<tt>label*</tt>). Use <tt>i8*</tt> instead.</p>
Chris Lattner4a67c912009-02-08 19:53:29 +00001659
Chris Lattner590645f2002-04-14 06:13:44 +00001660<h5>Syntax:</h5>
Bill Wendling30235112009-07-20 02:39:26 +00001661<pre>
1662 &lt;type&gt; *
1663</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001664
Chris Lattner590645f2002-04-14 06:13:44 +00001665<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001666<table class="layout">
1667 <tr class="layout">
Dan Gohman623806e2009-01-04 23:44:43 +00001668 <td class="left"><tt>[4 x i32]*</tt></td>
Chris Lattner747359f2007-12-19 05:04:11 +00001669 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1670 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1671 </tr>
1672 <tr class="layout">
1673 <td class="left"><tt>i32 (i32 *) *</tt></td>
1674 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001675 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner747359f2007-12-19 05:04:11 +00001676 <tt>i32</tt>.</td>
1677 </tr>
1678 <tr class="layout">
1679 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1680 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1681 that resides in address space #5.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001682 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001683</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001684
Misha Brukman76307852003-11-08 01:05:38 +00001685</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001686
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001687<!-- _______________________________________________________________________ -->
Reid Spencer404a3252007-02-15 03:07:05 +00001688<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001689
Misha Brukman76307852003-11-08 01:05:38 +00001690<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001691
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001692<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001693<p>A vector type is a simple derived type that represents a vector of elements.
1694 Vector types are used when multiple primitive data are operated in parallel
1695 using a single instruction (SIMD). A vector type requires a size (number of
1696 elements) and an underlying primitive data type. Vectors must have a power
1697 of two length (1, 2, 4, 8, 16 ...). Vector types are considered
1698 <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001699
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001700<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001701<pre>
1702 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1703</pre>
1704
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001705<p>The number of elements is a constant integer value; elementtype may be any
1706 integer or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001707
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001708<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001709<table class="layout">
1710 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001711 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1712 <td class="left">Vector of 4 32-bit integer values.</td>
1713 </tr>
1714 <tr class="layout">
1715 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1716 <td class="left">Vector of 8 32-bit floating-point values.</td>
1717 </tr>
1718 <tr class="layout">
1719 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1720 <td class="left">Vector of 2 64-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001721 </tr>
1722</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001723
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001724<p>Note that the code generator does not yet support large vector types to be
1725 used as function return types. The specific limit on how large a vector
1726 return type codegen can currently handle is target-dependent; currently it's
1727 often a few times longer than a hardware vector register.</p>
Dan Gohman142ccc02009-01-24 15:58:40 +00001728
Misha Brukman76307852003-11-08 01:05:38 +00001729</div>
1730
Chris Lattner37b6b092005-04-25 17:34:15 +00001731<!-- _______________________________________________________________________ -->
1732<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1733<div class="doc_text">
1734
1735<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001736<p>Opaque types are used to represent unknown types in the system. This
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001737 corresponds (for example) to the C notion of a forward declared structure
1738 type. In LLVM, opaque types can eventually be resolved to any type (not just
1739 a structure type).</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001740
1741<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001742<pre>
1743 opaque
1744</pre>
1745
1746<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001747<table class="layout">
1748 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001749 <td class="left"><tt>opaque</tt></td>
1750 <td class="left">An opaque type.</td>
Chris Lattner37b6b092005-04-25 17:34:15 +00001751 </tr>
1752</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001753
Chris Lattner37b6b092005-04-25 17:34:15 +00001754</div>
1755
Chris Lattnercf7a5842009-02-02 07:32:36 +00001756<!-- ======================================================================= -->
1757<div class="doc_subsection">
1758 <a name="t_uprefs">Type Up-references</a>
1759</div>
1760
1761<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001762
Chris Lattnercf7a5842009-02-02 07:32:36 +00001763<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001764<p>An "up reference" allows you to refer to a lexically enclosing type without
1765 requiring it to have a name. For instance, a structure declaration may
1766 contain a pointer to any of the types it is lexically a member of. Example
1767 of up references (with their equivalent as named type declarations)
1768 include:</p>
Chris Lattnercf7a5842009-02-02 07:32:36 +00001769
1770<pre>
Chris Lattnerbf1d5452009-02-09 10:00:56 +00001771 { \2 * } %x = type { %x* }
Chris Lattnercf7a5842009-02-02 07:32:36 +00001772 { \2 }* %y = type { %y }*
1773 \1* %z = type %z*
1774</pre>
1775
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001776<p>An up reference is needed by the asmprinter for printing out cyclic types
1777 when there is no declared name for a type in the cycle. Because the
1778 asmprinter does not want to print out an infinite type string, it needs a
1779 syntax to handle recursive types that have no names (all names are optional
1780 in llvm IR).</p>
Chris Lattnercf7a5842009-02-02 07:32:36 +00001781
1782<h5>Syntax:</h5>
1783<pre>
1784 \&lt;level&gt;
1785</pre>
1786
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001787<p>The level is the count of the lexical type that is being referred to.</p>
Chris Lattnercf7a5842009-02-02 07:32:36 +00001788
1789<h5>Examples:</h5>
Chris Lattnercf7a5842009-02-02 07:32:36 +00001790<table class="layout">
1791 <tr class="layout">
1792 <td class="left"><tt>\1*</tt></td>
1793 <td class="left">Self-referential pointer.</td>
1794 </tr>
1795 <tr class="layout">
1796 <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td>
1797 <td class="left">Recursive structure where the upref refers to the out-most
1798 structure.</td>
1799 </tr>
1800</table>
Chris Lattnercf7a5842009-02-02 07:32:36 +00001801
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001802</div>
Chris Lattner37b6b092005-04-25 17:34:15 +00001803
Chris Lattner74d3f822004-12-09 17:30:23 +00001804<!-- *********************************************************************** -->
1805<div class="doc_section"> <a name="constants">Constants</a> </div>
1806<!-- *********************************************************************** -->
1807
1808<div class="doc_text">
1809
1810<p>LLVM has several different basic types of constants. This section describes
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001811 them all and their syntax.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001812
1813</div>
1814
1815<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001816<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001817
1818<div class="doc_text">
1819
1820<dl>
1821 <dt><b>Boolean constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001822 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001823 constants of the <tt><a href="#t_primitive">i1</a></tt> type.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001824
1825 <dt><b>Integer constants</b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001826 <dd>Standard integers (such as '4') are constants of
1827 the <a href="#t_integer">integer</a> type. Negative numbers may be used
1828 with integer types.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001829
1830 <dt><b>Floating point constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001831 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001832 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
1833 notation (see below). The assembler requires the exact decimal value of a
1834 floating-point constant. For example, the assembler accepts 1.25 but
1835 rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point
1836 constants must have a <a href="#t_floating">floating point</a> type. </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001837
1838 <dt><b>Null pointer constants</b></dt>
John Criswelldfe6a862004-12-10 15:51:16 +00001839 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001840 and must be of <a href="#t_pointer">pointer type</a>.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001841</dl>
1842
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001843<p>The one non-intuitive notation for constants is the hexadecimal form of
1844 floating point constants. For example, the form '<tt>double
1845 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than)
1846 '<tt>double 4.5e+15</tt>'. The only time hexadecimal floating point
1847 constants are required (and the only time that they are generated by the
1848 disassembler) is when a floating point constant must be emitted but it cannot
1849 be represented as a decimal floating point number in a reasonable number of
1850 digits. For example, NaN's, infinities, and other special values are
1851 represented in their IEEE hexadecimal format so that assembly and disassembly
1852 do not cause any bits to change in the constants.</p>
1853
Dale Johannesencd4a3012009-02-11 22:14:51 +00001854<p>When using the hexadecimal form, constants of types float and double are
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001855 represented using the 16-digit form shown above (which matches the IEEE754
1856 representation for double); float values must, however, be exactly
1857 representable as IEE754 single precision. Hexadecimal format is always used
1858 for long double, and there are three forms of long double. The 80-bit format
1859 used by x86 is represented as <tt>0xK</tt> followed by 20 hexadecimal digits.
1860 The 128-bit format used by PowerPC (two adjacent doubles) is represented
1861 by <tt>0xM</tt> followed by 32 hexadecimal digits. The IEEE 128-bit format
1862 is represented by <tt>0xL</tt> followed by 32 hexadecimal digits; no
1863 currently supported target uses this format. Long doubles will only work if
1864 they match the long double format on your target. All hexadecimal formats
1865 are big-endian (sign bit at the left).</p>
1866
Chris Lattner74d3f822004-12-09 17:30:23 +00001867</div>
1868
1869<!-- ======================================================================= -->
Chris Lattner361bfcd2009-02-28 18:32:25 +00001870<div class="doc_subsection">
Bill Wendling972b7202009-07-20 02:32:41 +00001871<a name="aggregateconstants"></a> <!-- old anchor -->
1872<a name="complexconstants">Complex Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +00001873</div>
1874
1875<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001876
Chris Lattner361bfcd2009-02-28 18:32:25 +00001877<p>Complex constants are a (potentially recursive) combination of simple
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001878 constants and smaller complex constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001879
1880<dl>
1881 <dt><b>Structure constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001882 <dd>Structure constants are represented with notation similar to structure
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001883 type definitions (a comma separated list of elements, surrounded by braces
1884 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1885 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>".
1886 Structure constants must have <a href="#t_struct">structure type</a>, and
1887 the number and types of elements must match those specified by the
1888 type.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001889
1890 <dt><b>Array constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001891 <dd>Array constants are represented with notation similar to array type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001892 definitions (a comma separated list of elements, surrounded by square
1893 brackets (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74
1894 ]</tt>". Array constants must have <a href="#t_array">array type</a>, and
1895 the number and types of elements must match those specified by the
1896 type.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001897
Reid Spencer404a3252007-02-15 03:07:05 +00001898 <dt><b>Vector constants</b></dt>
Reid Spencer404a3252007-02-15 03:07:05 +00001899 <dd>Vector constants are represented with notation similar to vector type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001900 definitions (a comma separated list of elements, surrounded by
1901 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32
1902 42, i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must
1903 have <a href="#t_vector">vector type</a>, and the number and types of
1904 elements must match those specified by the type.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001905
1906 <dt><b>Zero initialization</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001907 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001908 value to zero of <em>any</em> type, including scalar and aggregate types.
1909 This is often used to avoid having to print large zero initializers
1910 (e.g. for large arrays) and is always exactly equivalent to using explicit
1911 zero initializers.</dd>
Nick Lewycky49f89192009-04-04 07:22:01 +00001912
1913 <dt><b>Metadata node</b></dt>
Nick Lewycky8e2c4f42009-05-30 16:08:30 +00001914 <dd>A metadata node is a structure-like constant with
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001915 <a href="#t_metadata">metadata type</a>. For example: "<tt>metadata !{
1916 i32 0, metadata !"test" }</tt>". Unlike other constants that are meant to
1917 be interpreted as part of the instruction stream, metadata is a place to
1918 attach additional information such as debug info.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001919</dl>
1920
1921</div>
1922
1923<!-- ======================================================================= -->
1924<div class="doc_subsection">
1925 <a name="globalconstants">Global Variable and Function Addresses</a>
1926</div>
1927
1928<div class="doc_text">
1929
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001930<p>The addresses of <a href="#globalvars">global variables</a>
1931 and <a href="#functionstructure">functions</a> are always implicitly valid
1932 (link-time) constants. These constants are explicitly referenced when
1933 the <a href="#identifiers">identifier for the global</a> is used and always
1934 have <a href="#t_pointer">pointer</a> type. For example, the following is a
1935 legal LLVM file:</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001936
Bill Wendling3716c5d2007-05-29 09:04:49 +00001937<div class="doc_code">
Chris Lattner74d3f822004-12-09 17:30:23 +00001938<pre>
Chris Lattner00538a12007-06-06 18:28:13 +00001939@X = global i32 17
1940@Y = global i32 42
1941@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
Chris Lattner74d3f822004-12-09 17:30:23 +00001942</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001943</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001944
1945</div>
1946
1947<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001948<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001949<div class="doc_text">
1950
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001951<p>The string '<tt>undef</tt>' is recognized as a type-less constant that has no
1952 specific value. Undefined values may be of any type and be used anywhere a
1953 constant is permitted.</p>
1954
1955<p>Undefined values indicate to the compiler that the program is well defined no
1956 matter what value is used, giving the compiler more freedom to optimize.</p>
1957
Chris Lattner74d3f822004-12-09 17:30:23 +00001958</div>
1959
1960<!-- ======================================================================= -->
1961<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1962</div>
1963
1964<div class="doc_text">
1965
1966<p>Constant expressions are used to allow expressions involving other constants
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001967 to be used as constants. Constant expressions may be of
1968 any <a href="#t_firstclass">first class</a> type and may involve any LLVM
1969 operation that does not have side effects (e.g. load and call are not
1970 supported). The following is the syntax for constant expressions:</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001971
1972<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001973 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001974 <dd>Truncate a constant to another type. The bit size of CST must be larger
1975 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001976
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001977 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001978 <dd>Zero extend a constant to another type. The bit size of CST must be
1979 smaller or equal to the bit size of TYPE. Both types must be
1980 integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001981
1982 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001983 <dd>Sign extend a constant to another type. The bit size of CST must be
1984 smaller or equal to the bit size of TYPE. Both types must be
1985 integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001986
1987 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001988 <dd>Truncate a floating point constant to another floating point type. The
1989 size of CST must be larger than the size of TYPE. Both types must be
1990 floating point.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001991
1992 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001993 <dd>Floating point extend a constant to another type. The size of CST must be
1994 smaller or equal to the size of TYPE. Both types must be floating
1995 point.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001996
Reid Spencer753163d2007-07-31 14:40:14 +00001997 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001998 <dd>Convert a floating point constant to the corresponding unsigned integer
Bill Wendlingd9a66f72009-07-20 02:29:24 +00001999 constant. TYPE must be a scalar or vector integer type. CST must be of
2000 scalar or vector floating point type. Both CST and TYPE must be scalars,
2001 or vectors of the same number of elements. If the value won't fit in the
2002 integer type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002003
Reid Spencer51b07252006-11-09 23:03:26 +00002004 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002005 <dd>Convert a floating point constant to the corresponding signed integer
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002006 constant. TYPE must be a scalar or vector integer type. CST must be of
2007 scalar or vector floating point type. Both CST and TYPE must be scalars,
2008 or vectors of the same number of elements. If the value won't fit in the
2009 integer type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002010
Reid Spencer51b07252006-11-09 23:03:26 +00002011 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002012 <dd>Convert an unsigned integer constant to the corresponding floating point
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002013 constant. TYPE must be a scalar or vector floating point type. CST must be
2014 of scalar or vector integer type. Both CST and TYPE must be scalars, or
2015 vectors of the same number of elements. If the value won't fit in the
2016 floating point type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002017
Reid Spencer51b07252006-11-09 23:03:26 +00002018 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002019 <dd>Convert a signed integer constant to the corresponding floating point
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002020 constant. TYPE must be a scalar or vector floating point type. CST must be
2021 of scalar or vector integer type. Both CST and TYPE must be scalars, or
2022 vectors of the same number of elements. If the value won't fit in the
2023 floating point type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002024
Reid Spencer5b950642006-11-11 23:08:07 +00002025 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
2026 <dd>Convert a pointer typed constant to the corresponding integer constant
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002027 <tt>TYPE</tt> must be an integer type. <tt>CST</tt> must be of pointer
2028 type. The <tt>CST</tt> value is zero extended, truncated, or unchanged to
2029 make it fit in <tt>TYPE</tt>.</dd>
Reid Spencer5b950642006-11-11 23:08:07 +00002030
2031 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002032 <dd>Convert a integer constant to a pointer constant. TYPE must be a pointer
2033 type. CST must be of integer type. The CST value is zero extended,
2034 truncated, or unchanged to make it fit in a pointer size. This one is
2035 <i>really</i> dangerous!</dd>
Reid Spencer5b950642006-11-11 23:08:07 +00002036
2037 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Chris Lattner789dee32009-02-28 18:27:03 +00002038 <dd>Convert a constant, CST, to another TYPE. The constraints of the operands
2039 are the same as those for the <a href="#i_bitcast">bitcast
2040 instruction</a>.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00002041
2042 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00002043 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002044 constants. As with the <a href="#i_getelementptr">getelementptr</a>
2045 instruction, the index list may have zero or more indexes, which are
2046 required to make sense for the type of "CSTPTR".</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00002047
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002048 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002049 <dd>Perform the <a href="#i_select">select operation</a> on constants.</dd>
Reid Spencer9965ee72006-12-04 19:23:19 +00002050
2051 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
2052 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
2053
2054 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
2055 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002056
2057 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002058 <dd>Perform the <a href="#i_extractelement">extractelement operation</a> on
2059 constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002060
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00002061 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002062 <dd>Perform the <a href="#i_insertelement">insertelement operation</a> on
2063 constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00002064
2065 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002066 <dd>Perform the <a href="#i_shufflevector">shufflevector operation</a> on
2067 constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00002068
Chris Lattner74d3f822004-12-09 17:30:23 +00002069 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002070 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
2071 be any of the <a href="#binaryops">binary</a>
2072 or <a href="#bitwiseops">bitwise binary</a> operations. The constraints
2073 on operands are the same as those for the corresponding instruction
2074 (e.g. no bitwise operations on floating point values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00002075</dl>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002076
Chris Lattner74d3f822004-12-09 17:30:23 +00002077</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00002078
Nick Lewycky49f89192009-04-04 07:22:01 +00002079<!-- ======================================================================= -->
2080<div class="doc_subsection"><a name="metadata">Embedded Metadata</a>
2081</div>
2082
2083<div class="doc_text">
2084
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002085<p>Embedded metadata provides a way to attach arbitrary data to the instruction
2086 stream without affecting the behaviour of the program. There are two
2087 metadata primitives, strings and nodes. All metadata has the
2088 <tt>metadata</tt> type and is identified in syntax by a preceding exclamation
2089 point ('<tt>!</tt>').</p>
Nick Lewycky49f89192009-04-04 07:22:01 +00002090
2091<p>A metadata string is a string surrounded by double quotes. It can contain
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002092 any character by escaping non-printable characters with "\xx" where "xx" is
2093 the two digit hex code. For example: "<tt>!"test\00"</tt>".</p>
Nick Lewycky49f89192009-04-04 07:22:01 +00002094
2095<p>Metadata nodes are represented with notation similar to structure constants
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002096 (a comma separated list of elements, surrounded by braces and preceeded by an
2097 exclamation point). For example: "<tt>!{ metadata !"test\00", i32
2098 10}</tt>".</p>
Nick Lewycky49f89192009-04-04 07:22:01 +00002099
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002100<p>A metadata node will attempt to track changes to the values it holds. In the
2101 event that a value is deleted, it will be replaced with a typeless
2102 "<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +00002103
Nick Lewycky49f89192009-04-04 07:22:01 +00002104<p>Optimizations may rely on metadata to provide additional information about
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002105 the program that isn't available in the instructions, or that isn't easily
2106 computable. Similarly, the code generator may expect a certain metadata
2107 format to be used to express debugging information.</p>
2108
Nick Lewycky49f89192009-04-04 07:22:01 +00002109</div>
2110
Chris Lattner2f7c9632001-06-06 20:29:01 +00002111<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00002112<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
2113<!-- *********************************************************************** -->
2114
2115<!-- ======================================================================= -->
2116<div class="doc_subsection">
2117<a name="inlineasm">Inline Assembler Expressions</a>
2118</div>
2119
2120<div class="doc_text">
2121
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002122<p>LLVM supports inline assembler expressions (as opposed
2123 to <a href="#moduleasm"> Module-Level Inline Assembly</a>) through the use of
2124 a special value. This value represents the inline assembler as a string
2125 (containing the instructions to emit), a list of operand constraints (stored
2126 as a string), and a flag that indicates whether or not the inline asm
2127 expression has side effects. An example inline assembler expression is:</p>
Chris Lattner98f013c2006-01-25 23:47:57 +00002128
Bill Wendling3716c5d2007-05-29 09:04:49 +00002129<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002130<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002131i32 (i32) asm "bswap $0", "=r,r"
Chris Lattner98f013c2006-01-25 23:47:57 +00002132</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002133</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002134
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002135<p>Inline assembler expressions may <b>only</b> be used as the callee operand of
2136 a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we
2137 have:</p>
Chris Lattner98f013c2006-01-25 23:47:57 +00002138
Bill Wendling3716c5d2007-05-29 09:04:49 +00002139<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002140<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002141%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattner98f013c2006-01-25 23:47:57 +00002142</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002143</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002144
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002145<p>Inline asms with side effects not visible in the constraint list must be
2146 marked as having side effects. This is done through the use of the
2147 '<tt>sideeffect</tt>' keyword, like so:</p>
Chris Lattner98f013c2006-01-25 23:47:57 +00002148
Bill Wendling3716c5d2007-05-29 09:04:49 +00002149<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002150<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002151call void asm sideeffect "eieio", ""()
Chris Lattner98f013c2006-01-25 23:47:57 +00002152</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002153</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002154
2155<p>TODO: The format of the asm and constraints string still need to be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002156 documented here. Constraints on what can be done (e.g. duplication, moving,
2157 etc need to be documented). This is probably best done by reference to
2158 another document that covers inline asm from a holistic perspective.</p>
Chris Lattner98f013c2006-01-25 23:47:57 +00002159
2160</div>
2161
Chris Lattnerae76db52009-07-20 05:55:19 +00002162
2163<!-- *********************************************************************** -->
2164<div class="doc_section">
2165 <a name="intrinsic_globals">Intrinsic Global Variables</a>
2166</div>
2167<!-- *********************************************************************** -->
2168
2169<p>LLVM has a number of "magic" global variables that contain data that affect
2170code generation or other IR semantics. These are documented here. All globals
2171of this sort should have a section specified as "llvm.metadata". This section
2172and all globals that start with "llvm." are reserved for LLVM.</p>
2173
2174<!-- ======================================================================= -->
2175<div class="doc_subsection">
2176<a name="intg_used">The '<tt>llvm.used</tt>' Global Variable</a>
2177</div>
2178
2179<div class="doc_text">
2180
2181<p>The <tt>@llvm.used</tt> global is an array with i8* element type which has <a
2182href="#linkage_appending">appending linkage</a>. This array contains a list of
2183pointers to global variables and functions which may optionally have a pointer
2184cast formed of bitcast or getelementptr. For example, a legal use of it is:</p>
2185
2186<pre>
2187 @X = global i8 4
2188 @Y = global i32 123
2189
2190 @llvm.used = appending global [2 x i8*] [
2191 i8* @X,
2192 i8* bitcast (i32* @Y to i8*)
2193 ], section "llvm.metadata"
2194</pre>
2195
2196<p>If a global variable appears in the <tt>@llvm.used</tt> list, then the
2197compiler, assembler, and linker are required to treat the symbol as if there is
2198a reference to the global that it cannot see. For example, if a variable has
2199internal linkage and no references other than that from the <tt>@llvm.used</tt>
2200list, it cannot be deleted. This is commonly used to represent references from
2201inline asms and other things the compiler cannot "see", and corresponds to
2202"attribute((used))" in GNU C.</p>
2203
2204<p>On some targets, the code generator must emit a directive to the assembler or
2205object file to prevent the assembler and linker from molesting the symbol.</p>
2206
2207</div>
2208
2209<!-- ======================================================================= -->
2210<div class="doc_subsection">
2211<a name="intg_global_ctors">The '<tt>llvm.global_ctors</tt>' Global Variable</a>
2212</div>
2213
2214<div class="doc_text">
2215
2216<p>TODO: Describe this.</p>
2217
2218</div>
2219
2220<!-- ======================================================================= -->
2221<div class="doc_subsection">
2222<a name="intg_global_dtors">The '<tt>llvm.global_dtors</tt>' Global Variable</a>
2223</div>
2224
2225<div class="doc_text">
2226
2227<p>TODO: Describe this.</p>
2228
2229</div>
2230
2231
Chris Lattner98f013c2006-01-25 23:47:57 +00002232<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002233<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
2234<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00002235
Misha Brukman76307852003-11-08 01:05:38 +00002236<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00002237
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002238<p>The LLVM instruction set consists of several different classifications of
2239 instructions: <a href="#terminators">terminator
2240 instructions</a>, <a href="#binaryops">binary instructions</a>,
2241 <a href="#bitwiseops">bitwise binary instructions</a>,
2242 <a href="#memoryops">memory instructions</a>, and
2243 <a href="#otherops">other instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00002244
Misha Brukman76307852003-11-08 01:05:38 +00002245</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002246
Chris Lattner2f7c9632001-06-06 20:29:01 +00002247<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002248<div class="doc_subsection"> <a name="terminators">Terminator
2249Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002250
Misha Brukman76307852003-11-08 01:05:38 +00002251<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00002252
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002253<p>As mentioned <a href="#functionstructure">previously</a>, every basic block
2254 in a program ends with a "Terminator" instruction, which indicates which
2255 block should be executed after the current block is finished. These
2256 terminator instructions typically yield a '<tt>void</tt>' value: they produce
2257 control flow, not values (the one exception being the
2258 '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
2259
2260<p>There are six different terminator instructions: the
2261 '<a href="#i_ret"><tt>ret</tt></a>' instruction, the
2262 '<a href="#i_br"><tt>br</tt></a>' instruction, the
2263 '<a href="#i_switch"><tt>switch</tt></a>' instruction, the
2264 '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the
2265 '<a href="#i_unwind"><tt>unwind</tt></a>' instruction, and the
2266 '<a href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00002267
Misha Brukman76307852003-11-08 01:05:38 +00002268</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002269
Chris Lattner2f7c9632001-06-06 20:29:01 +00002270<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002271<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
2272Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002273
Misha Brukman76307852003-11-08 01:05:38 +00002274<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002275
Chris Lattner2f7c9632001-06-06 20:29:01 +00002276<h5>Syntax:</h5>
Dan Gohmancc3132e2008-10-04 19:00:07 +00002277<pre>
2278 ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002279 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002280</pre>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002281
Chris Lattner2f7c9632001-06-06 20:29:01 +00002282<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002283<p>The '<tt>ret</tt>' instruction is used to return control flow (and optionally
2284 a value) from a function back to the caller.</p>
2285
2286<p>There are two forms of the '<tt>ret</tt>' instruction: one that returns a
2287 value and then causes control flow, and one that just causes control flow to
2288 occur.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002289
Chris Lattner2f7c9632001-06-06 20:29:01 +00002290<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002291<p>The '<tt>ret</tt>' instruction optionally accepts a single argument, the
2292 return value. The type of the return value must be a
2293 '<a href="#t_firstclass">first class</a>' type.</p>
Dan Gohmancc3132e2008-10-04 19:00:07 +00002294
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002295<p>A function is not <a href="#wellformed">well formed</a> if it it has a
2296 non-void return type and contains a '<tt>ret</tt>' instruction with no return
2297 value or a return value with a type that does not match its type, or if it
2298 has a void return type and contains a '<tt>ret</tt>' instruction with a
2299 return value.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002300
Chris Lattner2f7c9632001-06-06 20:29:01 +00002301<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002302<p>When the '<tt>ret</tt>' instruction is executed, control flow returns back to
2303 the calling function's context. If the caller is a
2304 "<a href="#i_call"><tt>call</tt></a>" instruction, execution continues at the
2305 instruction after the call. If the caller was an
2306 "<a href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues at
2307 the beginning of the "normal" destination block. If the instruction returns
2308 a value, that value shall set the call or invoke instruction's return
2309 value.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002310
Chris Lattner2f7c9632001-06-06 20:29:01 +00002311<h5>Example:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002312<pre>
2313 ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002314 ret void <i>; Return from a void function</i>
Bill Wendling050ee8f2009-02-28 22:12:54 +00002315 ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002316</pre>
Dan Gohman3065b612009-01-12 23:12:39 +00002317
Dan Gohman142ccc02009-01-24 15:58:40 +00002318<p>Note that the code generator does not yet fully support large
2319 return values. The specific sizes that are currently supported are
2320 dependent on the target. For integers, on 32-bit targets the limit
2321 is often 64 bits, and on 64-bit targets the limit is often 128 bits.
2322 For aggregate types, the current limits are dependent on the element
2323 types; for example targets are often limited to 2 total integer
2324 elements and 2 total floating-point elements.</p>
Dan Gohman3065b612009-01-12 23:12:39 +00002325
Misha Brukman76307852003-11-08 01:05:38 +00002326</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002327<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002328<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002329
Misha Brukman76307852003-11-08 01:05:38 +00002330<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002331
Chris Lattner2f7c9632001-06-06 20:29:01 +00002332<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002333<pre>
2334 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 +00002335</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002336
Chris Lattner2f7c9632001-06-06 20:29:01 +00002337<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002338<p>The '<tt>br</tt>' instruction is used to cause control flow to transfer to a
2339 different basic block in the current function. There are two forms of this
2340 instruction, corresponding to a conditional branch and an unconditional
2341 branch.</p>
2342
Chris Lattner2f7c9632001-06-06 20:29:01 +00002343<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002344<p>The conditional branch form of the '<tt>br</tt>' instruction takes a single
2345 '<tt>i1</tt>' value and two '<tt>label</tt>' values. The unconditional form
2346 of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' value as a
2347 target.</p>
2348
Chris Lattner2f7c9632001-06-06 20:29:01 +00002349<h5>Semantics:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00002350<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002351 argument is evaluated. If the value is <tt>true</tt>, control flows to the
2352 '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
2353 control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
2354
Chris Lattner2f7c9632001-06-06 20:29:01 +00002355<h5>Example:</h5>
Bill Wendling30235112009-07-20 02:39:26 +00002356<pre>
2357Test:
2358 %cond = <a href="#i_icmp">icmp</a> eq i32 %a, %b
2359 br i1 %cond, label %IfEqual, label %IfUnequal
2360IfEqual:
2361 <a href="#i_ret">ret</a> i32 1
2362IfUnequal:
2363 <a href="#i_ret">ret</a> i32 0
2364</pre>
2365
Misha Brukman76307852003-11-08 01:05:38 +00002366</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002367
Chris Lattner2f7c9632001-06-06 20:29:01 +00002368<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002369<div class="doc_subsubsection">
2370 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
2371</div>
2372
Misha Brukman76307852003-11-08 01:05:38 +00002373<div class="doc_text">
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002374
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002375<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002376<pre>
2377 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
2378</pre>
2379
Chris Lattner2f7c9632001-06-06 20:29:01 +00002380<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002381<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002382 several different places. It is a generalization of the '<tt>br</tt>'
2383 instruction, allowing a branch to occur to one of many possible
2384 destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002385
Chris Lattner2f7c9632001-06-06 20:29:01 +00002386<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002387<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002388 comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination,
2389 and an array of pairs of comparison value constants and '<tt>label</tt>'s.
2390 The table is not allowed to contain duplicate constant entries.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002391
Chris Lattner2f7c9632001-06-06 20:29:01 +00002392<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002393<p>The <tt>switch</tt> instruction specifies a table of values and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002394 destinations. When the '<tt>switch</tt>' instruction is executed, this table
2395 is searched for the given value. If the value is found, control flow is
2396 transfered to the corresponding destination; otherwise, control flow is
2397 transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002398
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002399<h5>Implementation:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002400<p>Depending on properties of the target machine and the particular
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002401 <tt>switch</tt> instruction, this instruction may be code generated in
2402 different ways. For example, it could be generated as a series of chained
2403 conditional branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002404
2405<h5>Example:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002406<pre>
2407 <i>; Emulate a conditional br instruction</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002408 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Dan Gohman623806e2009-01-04 23:44:43 +00002409 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002410
2411 <i>; Emulate an unconditional br instruction</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002412 switch i32 0, label %dest [ ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002413
2414 <i>; Implement a jump table:</i>
Dan Gohman623806e2009-01-04 23:44:43 +00002415 switch i32 %val, label %otherwise [ i32 0, label %onzero
2416 i32 1, label %onone
2417 i32 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00002418</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002419
Misha Brukman76307852003-11-08 01:05:38 +00002420</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00002421
Chris Lattner2f7c9632001-06-06 20:29:01 +00002422<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00002423<div class="doc_subsubsection">
2424 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
2425</div>
2426
Misha Brukman76307852003-11-08 01:05:38 +00002427<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00002428
Chris Lattner2f7c9632001-06-06 20:29:01 +00002429<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002430<pre>
Devang Patel02256232008-10-07 17:48:33 +00002431 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] &lt;ptr to function ty&gt; &lt;function ptr val&gt;(&lt;function args&gt;) [<a href="#fnattrs">fn attrs</a>]
Chris Lattner6b7a0082006-05-14 18:23:06 +00002432 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00002433</pre>
2434
Chris Lattnera8292f32002-05-06 22:08:29 +00002435<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002436<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002437 function, with the possibility of control flow transfer to either the
2438 '<tt>normal</tt>' label or the '<tt>exception</tt>' label. If the callee
2439 function returns with the "<tt><a href="#i_ret">ret</a></tt>" instruction,
2440 control flow will return to the "normal" label. If the callee (or any
2441 indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>"
2442 instruction, control is interrupted and continued at the dynamically nearest
2443 "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002444
Chris Lattner2f7c9632001-06-06 20:29:01 +00002445<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002446<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002447
Chris Lattner2f7c9632001-06-06 20:29:01 +00002448<ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002449 <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
2450 convention</a> the call should use. If none is specified, the call
2451 defaults to using C calling conventions.</li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00002452
2453 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002454 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
2455 '<tt>inreg</tt>' attributes are valid here.</li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00002456
Chris Lattner0132aff2005-05-06 22:57:40 +00002457 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002458 function value being invoked. In most cases, this is a direct function
2459 invocation, but indirect <tt>invoke</tt>s are just as possible, branching
2460 off an arbitrary pointer to function value.</li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002461
2462 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002463 function to be invoked. </li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002464
2465 <li>'<tt>function args</tt>': argument list whose types match the function
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002466 signature argument types. If the function signature indicates the
2467 function accepts a variable number of arguments, the extra arguments can
2468 be specified.</li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002469
2470 <li>'<tt>normal label</tt>': the label reached when the called function
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002471 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002472
2473 <li>'<tt>exception label</tt>': the label reached when a callee returns with
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002474 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
Chris Lattner0132aff2005-05-06 22:57:40 +00002475
Devang Patel02256232008-10-07 17:48:33 +00002476 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002477 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
2478 '<tt>readnone</tt>' attributes are valid here.</li>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002479</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00002480
Chris Lattner2f7c9632001-06-06 20:29:01 +00002481<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002482<p>This instruction is designed to operate as a standard
2483 '<tt><a href="#i_call">call</a></tt>' instruction in most regards. The
2484 primary difference is that it establishes an association with a label, which
2485 is used by the runtime library to unwind the stack.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002486
2487<p>This instruction is used in languages with destructors to ensure that proper
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002488 cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2489 exception. Additionally, this is important for implementation of
2490 '<tt>catch</tt>' clauses in high-level languages that support them.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002491
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002492<p>For the purposes of the SSA form, the definition of the value returned by the
2493 '<tt>invoke</tt>' instruction is deemed to occur on the edge from the current
2494 block to the "normal" label. If the callee unwinds then no return value is
2495 available.</p>
Dan Gohman9069d892009-05-22 21:47:08 +00002496
Chris Lattner2f7c9632001-06-06 20:29:01 +00002497<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002498<pre>
Nick Lewycky084ab472008-03-16 07:18:12 +00002499 %retval = invoke i32 @Test(i32 15) to label %Continue
Jeff Cohen5819f182007-04-22 01:17:39 +00002500 unwind label %TestCleanup <i>; {i32}:retval set</i>
Nick Lewycky084ab472008-03-16 07:18:12 +00002501 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
Jeff Cohen5819f182007-04-22 01:17:39 +00002502 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002503</pre>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002504
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002505</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002506
Chris Lattner5ed60612003-09-03 00:41:47 +00002507<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002508
Chris Lattner48b383b02003-11-25 01:02:51 +00002509<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2510Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002511
Misha Brukman76307852003-11-08 01:05:38 +00002512<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002513
Chris Lattner5ed60612003-09-03 00:41:47 +00002514<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002515<pre>
2516 unwind
2517</pre>
2518
Chris Lattner5ed60612003-09-03 00:41:47 +00002519<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002520<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002521 at the first callee in the dynamic call stack which used
2522 an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.
2523 This is primarily used to implement exception handling.</p>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002524
Chris Lattner5ed60612003-09-03 00:41:47 +00002525<h5>Semantics:</h5>
Chris Lattnerfe8519c2008-04-19 21:01:16 +00002526<p>The '<tt>unwind</tt>' instruction causes execution of the current function to
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002527 immediately halt. The dynamic call stack is then searched for the
2528 first <a href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.
2529 Once found, execution continues at the "exceptional" destination block
2530 specified by the <tt>invoke</tt> instruction. If there is no <tt>invoke</tt>
2531 instruction in the dynamic call chain, undefined behavior results.</p>
2532
Misha Brukman76307852003-11-08 01:05:38 +00002533</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002534
2535<!-- _______________________________________________________________________ -->
2536
2537<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2538Instruction</a> </div>
2539
2540<div class="doc_text">
2541
2542<h5>Syntax:</h5>
2543<pre>
2544 unreachable
2545</pre>
2546
2547<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002548<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002549 instruction is used to inform the optimizer that a particular portion of the
2550 code is not reachable. This can be used to indicate that the code after a
2551 no-return function cannot be reached, and other facts.</p>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002552
2553<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002554<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002555
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002556</div>
2557
Chris Lattner2f7c9632001-06-06 20:29:01 +00002558<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002559<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002560
Misha Brukman76307852003-11-08 01:05:38 +00002561<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002562
2563<p>Binary operators are used to do most of the computation in a program. They
2564 require two operands of the same type, execute an operation on them, and
2565 produce a single value. The operands might represent multiple data, as is
2566 the case with the <a href="#t_vector">vector</a> data type. The result value
2567 has the same type as its operands.</p>
2568
Misha Brukman76307852003-11-08 01:05:38 +00002569<p>There are several different binary operators:</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002570
Misha Brukman76307852003-11-08 01:05:38 +00002571</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002572
Chris Lattner2f7c9632001-06-06 20:29:01 +00002573<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002574<div class="doc_subsubsection">
2575 <a name="i_add">'<tt>add</tt>' Instruction</a>
2576</div>
2577
Misha Brukman76307852003-11-08 01:05:38 +00002578<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002579
Chris Lattner2f7c9632001-06-06 20:29:01 +00002580<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002581<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002582 &lt;result&gt; = add &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002583</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002584
Chris Lattner2f7c9632001-06-06 20:29:01 +00002585<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002586<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002587
Chris Lattner2f7c9632001-06-06 20:29:01 +00002588<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002589<p>The two arguments to the '<tt>add</tt>' instruction must
2590 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2591 integer values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002592
Chris Lattner2f7c9632001-06-06 20:29:01 +00002593<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002594<p>The value produced is the integer sum of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002595
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002596<p>If the sum has unsigned overflow, the result returned is the mathematical
2597 result modulo 2<sup>n</sup>, where n is the bit width of the result.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002598
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002599<p>Because LLVM integers use a two's complement representation, this instruction
2600 is appropriate for both signed and unsigned integers.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002601
Chris Lattner2f7c9632001-06-06 20:29:01 +00002602<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002603<pre>
2604 &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002605</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002606
Misha Brukman76307852003-11-08 01:05:38 +00002607</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002608
Chris Lattner2f7c9632001-06-06 20:29:01 +00002609<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002610<div class="doc_subsubsection">
Dan Gohmana5b96452009-06-04 22:49:04 +00002611 <a name="i_fadd">'<tt>fadd</tt>' Instruction</a>
2612</div>
2613
2614<div class="doc_text">
2615
2616<h5>Syntax:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002617<pre>
2618 &lt;result&gt; = fadd &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2619</pre>
2620
2621<h5>Overview:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002622<p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p>
2623
2624<h5>Arguments:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002625<p>The two arguments to the '<tt>fadd</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002626 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2627 floating point values. Both arguments must have identical types.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002628
2629<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002630<p>The value produced is the floating point sum of the two operands.</p>
2631
2632<h5>Example:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002633<pre>
2634 &lt;result&gt; = fadd float 4.0, %var <i>; yields {float}:result = 4.0 + %var</i>
2635</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002636
Dan Gohmana5b96452009-06-04 22:49:04 +00002637</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002638
Dan Gohmana5b96452009-06-04 22:49:04 +00002639<!-- _______________________________________________________________________ -->
2640<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002641 <a name="i_sub">'<tt>sub</tt>' Instruction</a>
2642</div>
2643
Misha Brukman76307852003-11-08 01:05:38 +00002644<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002645
Chris Lattner2f7c9632001-06-06 20:29:01 +00002646<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002647<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002648 &lt;result&gt; = sub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002649</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002650
Chris Lattner2f7c9632001-06-06 20:29:01 +00002651<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002652<p>The '<tt>sub</tt>' instruction returns the difference of its two
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002653 operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002654
2655<p>Note that the '<tt>sub</tt>' instruction is used to represent the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002656 '<tt>neg</tt>' instruction present in most other intermediate
2657 representations.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002658
Chris Lattner2f7c9632001-06-06 20:29:01 +00002659<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002660<p>The two arguments to the '<tt>sub</tt>' instruction must
2661 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2662 integer values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002663
Chris Lattner2f7c9632001-06-06 20:29:01 +00002664<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002665<p>The value produced is the integer difference of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002666
Dan Gohmana5b96452009-06-04 22:49:04 +00002667<p>If the difference has unsigned overflow, the result returned is the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002668 mathematical result modulo 2<sup>n</sup>, where n is the bit width of the
2669 result.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002670
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002671<p>Because LLVM integers use a two's complement representation, this instruction
2672 is appropriate for both signed and unsigned integers.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002673
Chris Lattner2f7c9632001-06-06 20:29:01 +00002674<h5>Example:</h5>
Bill Wendling2d8b9a82007-05-29 09:42:13 +00002675<pre>
2676 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002677 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002678</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002679
Misha Brukman76307852003-11-08 01:05:38 +00002680</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002681
Chris Lattner2f7c9632001-06-06 20:29:01 +00002682<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002683<div class="doc_subsubsection">
Dan Gohmana5b96452009-06-04 22:49:04 +00002684 <a name="i_fsub">'<tt>fsub</tt>' Instruction</a>
2685</div>
2686
2687<div class="doc_text">
2688
2689<h5>Syntax:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002690<pre>
2691 &lt;result&gt; = fsub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2692</pre>
2693
2694<h5>Overview:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002695<p>The '<tt>fsub</tt>' instruction returns the difference of its two
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002696 operands.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002697
2698<p>Note that the '<tt>fsub</tt>' instruction is used to represent the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002699 '<tt>fneg</tt>' instruction present in most other intermediate
2700 representations.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002701
2702<h5>Arguments:</h5>
Bill Wendling972b7202009-07-20 02:32:41 +00002703<p>The two arguments to the '<tt>fsub</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002704 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2705 floating point values. Both arguments must have identical types.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002706
2707<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002708<p>The value produced is the floating point difference of the two operands.</p>
2709
2710<h5>Example:</h5>
2711<pre>
2712 &lt;result&gt; = fsub float 4.0, %var <i>; yields {float}:result = 4.0 - %var</i>
2713 &lt;result&gt; = fsub float -0.0, %val <i>; yields {float}:result = -%var</i>
2714</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002715
Dan Gohmana5b96452009-06-04 22:49:04 +00002716</div>
2717
2718<!-- _______________________________________________________________________ -->
2719<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002720 <a name="i_mul">'<tt>mul</tt>' Instruction</a>
2721</div>
2722
Misha Brukman76307852003-11-08 01:05:38 +00002723<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002724
Chris Lattner2f7c9632001-06-06 20:29:01 +00002725<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002726<pre>
2727 &lt;result&gt; = mul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002728</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002729
Chris Lattner2f7c9632001-06-06 20:29:01 +00002730<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002731<p>The '<tt>mul</tt>' instruction returns the product of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002732
Chris Lattner2f7c9632001-06-06 20:29:01 +00002733<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002734<p>The two arguments to the '<tt>mul</tt>' instruction must
2735 be <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2736 integer values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002737
Chris Lattner2f7c9632001-06-06 20:29:01 +00002738<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002739<p>The value produced is the integer product of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002740
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002741<p>If the result of the multiplication has unsigned overflow, the result
2742 returned is the mathematical result modulo 2<sup>n</sup>, where n is the bit
2743 width of the result.</p>
2744
2745<p>Because LLVM integers use a two's complement representation, and the result
2746 is the same width as the operands, this instruction returns the correct
2747 result for both signed and unsigned integers. If a full product
2748 (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands should
2749 be sign-extended or zero-extended as appropriate to the width of the full
2750 product.</p>
2751
Chris Lattner2f7c9632001-06-06 20:29:01 +00002752<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002753<pre>
2754 &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002755</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002756
Misha Brukman76307852003-11-08 01:05:38 +00002757</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002758
Chris Lattner2f7c9632001-06-06 20:29:01 +00002759<!-- _______________________________________________________________________ -->
Dan Gohmana5b96452009-06-04 22:49:04 +00002760<div class="doc_subsubsection">
2761 <a name="i_fmul">'<tt>fmul</tt>' Instruction</a>
2762</div>
2763
2764<div class="doc_text">
2765
2766<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002767<pre>
2768 &lt;result&gt; = fmul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Dan Gohmana5b96452009-06-04 22:49:04 +00002769</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002770
Dan Gohmana5b96452009-06-04 22:49:04 +00002771<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002772<p>The '<tt>fmul</tt>' instruction returns the product of its two operands.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002773
2774<h5>Arguments:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002775<p>The two arguments to the '<tt>fmul</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002776 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2777 floating point values. Both arguments must have identical types.</p>
Dan Gohmana5b96452009-06-04 22:49:04 +00002778
2779<h5>Semantics:</h5>
Dan Gohmana5b96452009-06-04 22:49:04 +00002780<p>The value produced is the floating point product of the two operands.</p>
2781
2782<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002783<pre>
2784 &lt;result&gt; = fmul float 4.0, %var <i>; yields {float}:result = 4.0 * %var</i>
Dan Gohmana5b96452009-06-04 22:49:04 +00002785</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002786
Dan Gohmana5b96452009-06-04 22:49:04 +00002787</div>
2788
2789<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002790<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2791</a></div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002792
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002793<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002794
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002795<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002796<pre>
2797 &lt;result&gt; = udiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002798</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002799
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002800<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002801<p>The '<tt>udiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002802
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002803<h5>Arguments:</h5>
2804<p>The two arguments to the '<tt>udiv</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002805 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2806 values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002807
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002808<h5>Semantics:</h5>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002809<p>The value produced is the unsigned integer quotient of the two operands.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002810
Chris Lattner2f2427e2008-01-28 00:36:27 +00002811<p>Note that unsigned integer division and signed integer division are distinct
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002812 operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2813
Chris Lattner2f2427e2008-01-28 00:36:27 +00002814<p>Division by zero leads to undefined behavior.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002815
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002816<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002817<pre>
2818 &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002819</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002820
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002821</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002822
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002823<!-- _______________________________________________________________________ -->
2824<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2825</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002826
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002827<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002828
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002829<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002830<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002831 &lt;result&gt; = sdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002832</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002833
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002834<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002835<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002836
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002837<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002838<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002839 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2840 values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002841
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002842<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002843<p>The value produced is the signed integer quotient of the two operands rounded
2844 towards zero.</p>
2845
Chris Lattner2f2427e2008-01-28 00:36:27 +00002846<p>Note that signed integer division and unsigned integer division are distinct
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002847 operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2848
Chris Lattner2f2427e2008-01-28 00:36:27 +00002849<p>Division by zero leads to undefined behavior. Overflow also leads to
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002850 undefined behavior; this is a rare case, but can occur, for example, by doing
2851 a 32-bit division of -2147483648 by -1.</p>
2852
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002853<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002854<pre>
2855 &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002856</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002857
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002858</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002859
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002860<!-- _______________________________________________________________________ -->
2861<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002862Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002863
Misha Brukman76307852003-11-08 01:05:38 +00002864<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002865
Chris Lattner2f7c9632001-06-06 20:29:01 +00002866<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002867<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002868 &lt;result&gt; = fdiv &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002869</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002870
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002871<h5>Overview:</h5>
2872<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002873
Chris Lattner48b383b02003-11-25 01:02:51 +00002874<h5>Arguments:</h5>
Jeff Cohen5819f182007-04-22 01:17:39 +00002875<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002876 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2877 floating point values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002878
Chris Lattner48b383b02003-11-25 01:02:51 +00002879<h5>Semantics:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002880<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002881
Chris Lattner48b383b02003-11-25 01:02:51 +00002882<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002883<pre>
2884 &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002885</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002886
Chris Lattner48b383b02003-11-25 01:02:51 +00002887</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002888
Chris Lattner48b383b02003-11-25 01:02:51 +00002889<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00002890<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2891</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002892
Reid Spencer7eb55b32006-11-02 01:53:59 +00002893<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002894
Reid Spencer7eb55b32006-11-02 01:53:59 +00002895<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002896<pre>
2897 &lt;result&gt; = urem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002898</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002899
Reid Spencer7eb55b32006-11-02 01:53:59 +00002900<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002901<p>The '<tt>urem</tt>' instruction returns the remainder from the unsigned
2902 division of its two arguments.</p>
2903
Reid Spencer7eb55b32006-11-02 01:53:59 +00002904<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002905<p>The two arguments to the '<tt>urem</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002906 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2907 values. Both arguments must have identical types.</p>
2908
Reid Spencer7eb55b32006-11-02 01:53:59 +00002909<h5>Semantics:</h5>
2910<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002911 This instruction always performs an unsigned division to get the
2912 remainder.</p>
2913
Chris Lattner2f2427e2008-01-28 00:36:27 +00002914<p>Note that unsigned integer remainder and signed integer remainder are
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002915 distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2916
Chris Lattner2f2427e2008-01-28 00:36:27 +00002917<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002918
Reid Spencer7eb55b32006-11-02 01:53:59 +00002919<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002920<pre>
2921 &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002922</pre>
2923
2924</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002925
Reid Spencer7eb55b32006-11-02 01:53:59 +00002926<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002927<div class="doc_subsubsection">
2928 <a name="i_srem">'<tt>srem</tt>' Instruction</a>
2929</div>
2930
Chris Lattner48b383b02003-11-25 01:02:51 +00002931<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002932
Chris Lattner48b383b02003-11-25 01:02:51 +00002933<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002934<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002935 &lt;result&gt; = srem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002936</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002937
Chris Lattner48b383b02003-11-25 01:02:51 +00002938<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002939<p>The '<tt>srem</tt>' instruction returns the remainder from the signed
2940 division of its two operands. This instruction can also take
2941 <a href="#t_vector">vector</a> versions of the values in which case the
2942 elements must be integers.</p>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00002943
Chris Lattner48b383b02003-11-25 01:02:51 +00002944<h5>Arguments:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002945<p>The two arguments to the '<tt>srem</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002946 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2947 values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002948
Chris Lattner48b383b02003-11-25 01:02:51 +00002949<h5>Semantics:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002950<p>This instruction returns the <i>remainder</i> of a division (where the result
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002951 has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i>
2952 operator (where the result has the same sign as the divisor, <tt>op2</tt>) of
2953 a value. For more information about the difference,
2954 see <a href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
2955 Math Forum</a>. For a table of how this is implemented in various languages,
2956 please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
2957 Wikipedia: modulo operation</a>.</p>
2958
Chris Lattner2f2427e2008-01-28 00:36:27 +00002959<p>Note that signed integer remainder and unsigned integer remainder are
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002960 distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2961
Chris Lattner2f2427e2008-01-28 00:36:27 +00002962<p>Taking the remainder of a division by zero leads to undefined behavior.
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002963 Overflow also leads to undefined behavior; this is a rare case, but can
2964 occur, for example, by taking the remainder of a 32-bit division of
2965 -2147483648 by -1. (The remainder doesn't actually overflow, but this rule
2966 lets srem be implemented using instructions that return both the result of
2967 the division and the remainder.)</p>
2968
Chris Lattner48b383b02003-11-25 01:02:51 +00002969<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002970<pre>
2971 &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002972</pre>
2973
2974</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002975
Reid Spencer7eb55b32006-11-02 01:53:59 +00002976<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002977<div class="doc_subsubsection">
2978 <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div>
2979
Reid Spencer7eb55b32006-11-02 01:53:59 +00002980<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002981
Reid Spencer7eb55b32006-11-02 01:53:59 +00002982<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002983<pre>
2984 &lt;result&gt; = frem &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002985</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002986
Reid Spencer7eb55b32006-11-02 01:53:59 +00002987<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002988<p>The '<tt>frem</tt>' instruction returns the remainder from the division of
2989 its two operands.</p>
2990
Reid Spencer7eb55b32006-11-02 01:53:59 +00002991<h5>Arguments:</h5>
2992<p>The two arguments to the '<tt>frem</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002993 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2994 floating point values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002995
Reid Spencer7eb55b32006-11-02 01:53:59 +00002996<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00002997<p>This instruction returns the <i>remainder</i> of a division. The remainder
2998 has the same sign as the dividend.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002999
Reid Spencer7eb55b32006-11-02 01:53:59 +00003000<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003001<pre>
3002 &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00003003</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003004
Misha Brukman76307852003-11-08 01:05:38 +00003005</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00003006
Reid Spencer2ab01932007-02-02 13:57:07 +00003007<!-- ======================================================================= -->
3008<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
3009Operations</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003010
Reid Spencer2ab01932007-02-02 13:57:07 +00003011<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003012
3013<p>Bitwise binary operators are used to do various forms of bit-twiddling in a
3014 program. They are generally very efficient instructions and can commonly be
3015 strength reduced from other instructions. They require two operands of the
3016 same type, execute an operation on them, and produce a single value. The
3017 resulting value is the same type as its operands.</p>
3018
Reid Spencer2ab01932007-02-02 13:57:07 +00003019</div>
3020
Reid Spencer04e259b2007-01-31 21:39:12 +00003021<!-- _______________________________________________________________________ -->
3022<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
3023Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003024
Reid Spencer04e259b2007-01-31 21:39:12 +00003025<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003026
Reid Spencer04e259b2007-01-31 21:39:12 +00003027<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003028<pre>
3029 &lt;result&gt; = shl &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003030</pre>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003031
Reid Spencer04e259b2007-01-31 21:39:12 +00003032<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003033<p>The '<tt>shl</tt>' instruction returns the first operand shifted to the left
3034 a specified number of bits.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003035
Reid Spencer04e259b2007-01-31 21:39:12 +00003036<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003037<p>Both arguments to the '<tt>shl</tt>' instruction must be the
3038 same <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
3039 integer type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003040
Reid Spencer04e259b2007-01-31 21:39:12 +00003041<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003042<p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod
3043 2<sup>n</sup>, where <tt>n</tt> is the width of the result. If <tt>op2</tt>
3044 is (statically or dynamically) negative or equal to or larger than the number
3045 of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3046 vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3047 shift amount in <tt>op2</tt>.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003048
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003049<h5>Example:</h5>
3050<pre>
Reid Spencer04e259b2007-01-31 21:39:12 +00003051 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
3052 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
3053 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003054 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00003055 &lt;result&gt; = shl &lt;2 x i32&gt; &lt; i32 1, i32 1&gt;, &lt; i32 1, i32 2&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 2, i32 4&gt;</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003056</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003057
Reid Spencer04e259b2007-01-31 21:39:12 +00003058</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003059
Reid Spencer04e259b2007-01-31 21:39:12 +00003060<!-- _______________________________________________________________________ -->
3061<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
3062Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003063
Reid Spencer04e259b2007-01-31 21:39:12 +00003064<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003065
Reid Spencer04e259b2007-01-31 21:39:12 +00003066<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003067<pre>
3068 &lt;result&gt; = lshr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003069</pre>
3070
3071<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003072<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
3073 operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003074
3075<h5>Arguments:</h5>
3076<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003077 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3078 type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003079
3080<h5>Semantics:</h5>
3081<p>This instruction always performs a logical shift right operation. The most
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003082 significant bits of the result will be filled with zero bits after the shift.
3083 If <tt>op2</tt> is (statically or dynamically) equal to or larger than the
3084 number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3085 vectors, each vector element of <tt>op1</tt> is shifted by the corresponding
3086 shift amount in <tt>op2</tt>.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003087
3088<h5>Example:</h5>
3089<pre>
3090 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
3091 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
3092 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
3093 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003094 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00003095 &lt;result&gt; = lshr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 2&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 0x7FFFFFFF, i32 1&gt;</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003096</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003097
Reid Spencer04e259b2007-01-31 21:39:12 +00003098</div>
3099
Reid Spencer2ab01932007-02-02 13:57:07 +00003100<!-- _______________________________________________________________________ -->
Reid Spencer04e259b2007-01-31 21:39:12 +00003101<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
3102Instruction</a> </div>
3103<div class="doc_text">
3104
3105<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003106<pre>
3107 &lt;result&gt; = ashr &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003108</pre>
3109
3110<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003111<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
3112 operand shifted to the right a specified number of bits with sign
3113 extension.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003114
3115<h5>Arguments:</h5>
3116<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003117 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3118 type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003119
3120<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003121<p>This instruction always performs an arithmetic shift right operation, The
3122 most significant bits of the result will be filled with the sign bit
3123 of <tt>op1</tt>. If <tt>op2</tt> is (statically or dynamically) equal to or
3124 larger than the number of bits in <tt>op1</tt>, the result is undefined. If
3125 the arguments are vectors, each vector element of <tt>op1</tt> is shifted by
3126 the corresponding shift amount in <tt>op2</tt>.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003127
3128<h5>Example:</h5>
3129<pre>
3130 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
3131 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
3132 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
3133 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003134 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00003135 &lt;result&gt; = ashr &lt;2 x i32&gt; &lt; i32 -2, i32 4&gt;, &lt; i32 1, i32 3&gt; <i>; yields: result=&lt;2 x i32&gt; &lt; i32 -1, i32 0&gt;</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00003136</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003137
Reid Spencer04e259b2007-01-31 21:39:12 +00003138</div>
3139
Chris Lattner2f7c9632001-06-06 20:29:01 +00003140<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003141<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
3142Instruction</a> </div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003143
Misha Brukman76307852003-11-08 01:05:38 +00003144<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003145
Chris Lattner2f7c9632001-06-06 20:29:01 +00003146<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003147<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00003148 &lt;result&gt; = and &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003149</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003150
Chris Lattner2f7c9632001-06-06 20:29:01 +00003151<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003152<p>The '<tt>and</tt>' instruction returns the bitwise logical and of its two
3153 operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003154
Chris Lattner2f7c9632001-06-06 20:29:01 +00003155<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003156<p>The two arguments to the '<tt>and</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003157 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3158 values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003159
Chris Lattner2f7c9632001-06-06 20:29:01 +00003160<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003161<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003162
Misha Brukman76307852003-11-08 01:05:38 +00003163<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00003164 <tbody>
3165 <tr>
3166 <td>In0</td>
3167 <td>In1</td>
3168 <td>Out</td>
3169 </tr>
3170 <tr>
3171 <td>0</td>
3172 <td>0</td>
3173 <td>0</td>
3174 </tr>
3175 <tr>
3176 <td>0</td>
3177 <td>1</td>
3178 <td>0</td>
3179 </tr>
3180 <tr>
3181 <td>1</td>
3182 <td>0</td>
3183 <td>0</td>
3184 </tr>
3185 <tr>
3186 <td>1</td>
3187 <td>1</td>
3188 <td>1</td>
3189 </tr>
3190 </tbody>
3191</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003192
Chris Lattner2f7c9632001-06-06 20:29:01 +00003193<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003194<pre>
3195 &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003196 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
3197 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003198</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003199</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003200<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003201<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003202
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003203<div class="doc_text">
3204
3205<h5>Syntax:</h5>
3206<pre>
3207 &lt;result&gt; = or &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
3208</pre>
3209
3210<h5>Overview:</h5>
3211<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive or of its
3212 two operands.</p>
3213
3214<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003215<p>The two arguments to the '<tt>or</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003216 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3217 values. Both arguments must have identical types.</p>
3218
Chris Lattner2f7c9632001-06-06 20:29:01 +00003219<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003220<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003221
Chris Lattner48b383b02003-11-25 01:02:51 +00003222<table border="1" cellspacing="0" cellpadding="4">
3223 <tbody>
3224 <tr>
3225 <td>In0</td>
3226 <td>In1</td>
3227 <td>Out</td>
3228 </tr>
3229 <tr>
3230 <td>0</td>
3231 <td>0</td>
3232 <td>0</td>
3233 </tr>
3234 <tr>
3235 <td>0</td>
3236 <td>1</td>
3237 <td>1</td>
3238 </tr>
3239 <tr>
3240 <td>1</td>
3241 <td>0</td>
3242 <td>1</td>
3243 </tr>
3244 <tr>
3245 <td>1</td>
3246 <td>1</td>
3247 <td>1</td>
3248 </tr>
3249 </tbody>
3250</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003251
Chris Lattner2f7c9632001-06-06 20:29:01 +00003252<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003253<pre>
3254 &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003255 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
3256 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003257</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003258
Misha Brukman76307852003-11-08 01:05:38 +00003259</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003260
Chris Lattner2f7c9632001-06-06 20:29:01 +00003261<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003262<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
3263Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003264
Misha Brukman76307852003-11-08 01:05:38 +00003265<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003266
Chris Lattner2f7c9632001-06-06 20:29:01 +00003267<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003268<pre>
3269 &lt;result&gt; = xor &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003270</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003271
Chris Lattner2f7c9632001-06-06 20:29:01 +00003272<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003273<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive or of
3274 its two operands. The <tt>xor</tt> is used to implement the "one's
3275 complement" operation, which is the "~" operator in C.</p>
3276
Chris Lattner2f7c9632001-06-06 20:29:01 +00003277<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003278<p>The two arguments to the '<tt>xor</tt>' instruction must be
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003279 <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3280 values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003281
Chris Lattner2f7c9632001-06-06 20:29:01 +00003282<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003283<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003284
Chris Lattner48b383b02003-11-25 01:02:51 +00003285<table border="1" cellspacing="0" cellpadding="4">
3286 <tbody>
3287 <tr>
3288 <td>In0</td>
3289 <td>In1</td>
3290 <td>Out</td>
3291 </tr>
3292 <tr>
3293 <td>0</td>
3294 <td>0</td>
3295 <td>0</td>
3296 </tr>
3297 <tr>
3298 <td>0</td>
3299 <td>1</td>
3300 <td>1</td>
3301 </tr>
3302 <tr>
3303 <td>1</td>
3304 <td>0</td>
3305 <td>1</td>
3306 </tr>
3307 <tr>
3308 <td>1</td>
3309 <td>1</td>
3310 <td>0</td>
3311 </tr>
3312 </tbody>
3313</table>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003314
Chris Lattner2f7c9632001-06-06 20:29:01 +00003315<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003316<pre>
3317 &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003318 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
3319 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
3320 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003321</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003322
Misha Brukman76307852003-11-08 01:05:38 +00003323</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003324
Chris Lattner2f7c9632001-06-06 20:29:01 +00003325<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00003326<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00003327 <a name="vectorops">Vector Operations</a>
3328</div>
3329
3330<div class="doc_text">
3331
3332<p>LLVM supports several instructions to represent vector operations in a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003333 target-independent manner. These instructions cover the element-access and
3334 vector-specific operations needed to process vectors effectively. While LLVM
3335 does directly support these vector operations, many sophisticated algorithms
3336 will want to use target-specific intrinsics to take full advantage of a
3337 specific target.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003338
3339</div>
3340
3341<!-- _______________________________________________________________________ -->
3342<div class="doc_subsubsection">
3343 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
3344</div>
3345
3346<div class="doc_text">
3347
3348<h5>Syntax:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003349<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003350 &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 +00003351</pre>
3352
3353<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003354<p>The '<tt>extractelement</tt>' instruction extracts a single scalar element
3355 from a vector at a specified index.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003356
3357
3358<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003359<p>The first operand of an '<tt>extractelement</tt>' instruction is a value
3360 of <a href="#t_vector">vector</a> type. The second operand is an index
3361 indicating the position from which to extract the element. The index may be
3362 a variable.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003363
3364<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003365<p>The result is a scalar of the same type as the element type of
3366 <tt>val</tt>. Its value is the value at position <tt>idx</tt> of
3367 <tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3368 results are undefined.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003369
3370<h5>Example:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003371<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003372 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003373</pre>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003374
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003375</div>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003376
3377<!-- _______________________________________________________________________ -->
3378<div class="doc_subsubsection">
3379 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
3380</div>
3381
3382<div class="doc_text">
3383
3384<h5>Syntax:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003385<pre>
Dan Gohman43ba0672008-05-12 23:38:42 +00003386 &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 +00003387</pre>
3388
3389<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003390<p>The '<tt>insertelement</tt>' instruction inserts a scalar element into a
3391 vector at a specified index.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003392
3393<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003394<p>The first operand of an '<tt>insertelement</tt>' instruction is a value
3395 of <a href="#t_vector">vector</a> type. The second operand is a scalar value
3396 whose type must equal the element type of the first operand. The third
3397 operand is an index indicating the position at which to insert the value.
3398 The index may be a variable.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003399
3400<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003401<p>The result is a vector of the same type as <tt>val</tt>. Its element values
3402 are those of <tt>val</tt> except at position <tt>idx</tt>, where it gets the
3403 value <tt>elt</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3404 results are undefined.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003405
3406<h5>Example:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003407<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003408 %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 +00003409</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003410
Chris Lattnerce83bff2006-04-08 23:07:04 +00003411</div>
3412
3413<!-- _______________________________________________________________________ -->
3414<div class="doc_subsubsection">
3415 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
3416</div>
3417
3418<div class="doc_text">
3419
3420<h5>Syntax:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003421<pre>
Mon P Wang25f01062008-11-10 04:46:22 +00003422 &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;m x i32&gt; &lt;mask&gt; <i>; yields &lt;m x &lt;ty&gt;&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003423</pre>
3424
3425<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003426<p>The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
3427 from two input vectors, returning a vector with the same element type as the
3428 input and length that is the same as the shuffle mask.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003429
3430<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003431<p>The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
3432 with types that match each other. The third argument is a shuffle mask whose
3433 element type is always 'i32'. The result of the instruction is a vector
3434 whose length is the same as the shuffle mask and whose element type is the
3435 same as the element type of the first two operands.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003436
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003437<p>The shuffle mask operand is required to be a constant vector with either
3438 constant integer or undef values.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003439
3440<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003441<p>The elements of the two input vectors are numbered from left to right across
3442 both of the vectors. The shuffle mask operand specifies, for each element of
3443 the result vector, which element of the two input vectors the result element
3444 gets. The element selector may be undef (meaning "don't care") and the
3445 second operand may be undef if performing a shuffle from only one vector.</p>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003446
3447<h5>Example:</h5>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003448<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003449 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen5819f182007-04-22 01:17:39 +00003450 &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 +00003451 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
3452 &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.
Mon P Wang25f01062008-11-10 04:46:22 +00003453 %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef,
3454 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i>
3455 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3456 &lt;8 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 &gt; <i>; yields &lt;8 x i32&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003457</pre>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003458
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003459</div>
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00003460
Chris Lattnerce83bff2006-04-08 23:07:04 +00003461<!-- ======================================================================= -->
3462<div class="doc_subsection">
Dan Gohmanb9d66602008-05-12 23:51:09 +00003463 <a name="aggregateops">Aggregate Operations</a>
3464</div>
3465
3466<div class="doc_text">
3467
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003468<p>LLVM supports several instructions for working with aggregate values.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003469
3470</div>
3471
3472<!-- _______________________________________________________________________ -->
3473<div class="doc_subsubsection">
3474 <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a>
3475</div>
3476
3477<div class="doc_text">
3478
3479<h5>Syntax:</h5>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003480<pre>
3481 &lt;result&gt; = extractvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;idx&gt;{, &lt;idx&gt;}*
3482</pre>
3483
3484<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003485<p>The '<tt>extractvalue</tt>' instruction extracts the value of a struct field
3486 or array element from an aggregate value.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003487
3488<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003489<p>The first operand of an '<tt>extractvalue</tt>' instruction is a value
3490 of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. The
3491 operands are constant indices to specify which value to extract in a similar
3492 manner as indices in a
3493 '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003494
3495<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003496<p>The result is the value at the position in the aggregate specified by the
3497 index operands.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003498
3499<h5>Example:</h5>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003500<pre>
Dan Gohman1ecaf452008-05-31 00:58:22 +00003501 %result = extractvalue {i32, float} %agg, 0 <i>; yields i32</i>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003502</pre>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003503
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003504</div>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003505
3506<!-- _______________________________________________________________________ -->
3507<div class="doc_subsubsection">
3508 <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a>
3509</div>
3510
3511<div class="doc_text">
3512
3513<h5>Syntax:</h5>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003514<pre>
Dan Gohman1ecaf452008-05-31 00:58:22 +00003515 &lt;result&gt; = insertvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;ty&gt; &lt;val&gt;, &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003516</pre>
3517
3518<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003519<p>The '<tt>insertvalue</tt>' instruction inserts a value into a struct field or
3520 array element in an aggregate.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003521
3522
3523<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003524<p>The first operand of an '<tt>insertvalue</tt>' instruction is a value
3525 of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. The
3526 second operand is a first-class value to insert. The following operands are
3527 constant indices indicating the position at which to insert the value in a
3528 similar manner as indices in a
3529 '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. The
3530 value to insert must have the same type as the value identified by the
3531 indices.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003532
3533<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003534<p>The result is an aggregate of the same type as <tt>val</tt>. Its value is
3535 that of <tt>val</tt> except that the value at the position specified by the
3536 indices is that of <tt>elt</tt>.</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003537
3538<h5>Example:</h5>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003539<pre>
Dan Gohman88ce1a52008-06-23 15:26:37 +00003540 %result = insertvalue {i32, float} %agg, i32 1, 0 <i>; yields {i32, float}</i>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003541</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003542
Dan Gohmanb9d66602008-05-12 23:51:09 +00003543</div>
3544
3545
3546<!-- ======================================================================= -->
3547<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00003548 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00003549</div>
3550
Misha Brukman76307852003-11-08 01:05:38 +00003551<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003552
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003553<p>A key design point of an SSA-based representation is how it represents
3554 memory. In LLVM, no memory locations are in SSA form, which makes things
3555 very simple. This section describes how to read, write, allocate, and free
3556 memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003557
Misha Brukman76307852003-11-08 01:05:38 +00003558</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003559
Chris Lattner2f7c9632001-06-06 20:29:01 +00003560<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003561<div class="doc_subsubsection">
3562 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
3563</div>
3564
Misha Brukman76307852003-11-08 01:05:38 +00003565<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003566
Chris Lattner2f7c9632001-06-06 20:29:01 +00003567<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003568<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003569 &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 +00003570</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003571
Chris Lattner2f7c9632001-06-06 20:29:01 +00003572<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003573<p>The '<tt>malloc</tt>' instruction allocates memory from the system heap and
3574 returns a pointer to it. The object is always allocated in the generic
3575 address space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003576
Chris Lattner2f7c9632001-06-06 20:29:01 +00003577<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003578<p>The '<tt>malloc</tt>' instruction allocates
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003579 <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory from the operating
3580 system and returns a pointer of the appropriate type to the program. If
3581 "NumElements" is specified, it is the number of elements allocated, otherwise
3582 "NumElements" is defaulted to be one. If a constant alignment is specified,
3583 the value result of the allocation is guaranteed to be aligned to at least
3584 that boundary. If not specified, or if zero, the target can choose to align
3585 the allocation on any convenient boundary compatible with the type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003586
Misha Brukman76307852003-11-08 01:05:38 +00003587<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003588
Chris Lattner2f7c9632001-06-06 20:29:01 +00003589<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003590<p>Memory is allocated using the system "<tt>malloc</tt>" function, and a
3591 pointer is returned. The result of a zero byte allocation is undefined. The
3592 result is null if there is insufficient memory available.</p>
Misha Brukman76307852003-11-08 01:05:38 +00003593
Chris Lattner54611b42005-11-06 08:02:57 +00003594<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003595<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003596 %array = malloc [4 x i8] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner54611b42005-11-06 08:02:57 +00003597
Bill Wendling2d8b9a82007-05-29 09:42:13 +00003598 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
3599 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
3600 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
3601 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
3602 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003603</pre>
Dan Gohman3065b612009-01-12 23:12:39 +00003604
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003605<p>Note that the code generator does not yet respect the alignment value.</p>
Dan Gohman3065b612009-01-12 23:12:39 +00003606
Misha Brukman76307852003-11-08 01:05:38 +00003607</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003608
Chris Lattner2f7c9632001-06-06 20:29:01 +00003609<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003610<div class="doc_subsubsection">
3611 <a name="i_free">'<tt>free</tt>' Instruction</a>
3612</div>
3613
Misha Brukman76307852003-11-08 01:05:38 +00003614<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003615
Chris Lattner2f7c9632001-06-06 20:29:01 +00003616<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003617<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003618 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003619</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003620
Chris Lattner2f7c9632001-06-06 20:29:01 +00003621<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003622<p>The '<tt>free</tt>' instruction returns memory back to the unused memory heap
3623 to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003624
Chris Lattner2f7c9632001-06-06 20:29:01 +00003625<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003626<p>'<tt>value</tt>' shall be a pointer value that points to a value that was
3627 allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003628
Chris Lattner2f7c9632001-06-06 20:29:01 +00003629<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003630<p>Access to the memory pointed to by the pointer is no longer defined after
3631 this instruction executes. If the pointer is null, the operation is a
3632 noop.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003633
Chris Lattner2f7c9632001-06-06 20:29:01 +00003634<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003635<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003636 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003637 free [4 x i8]* %array
Chris Lattner2f7c9632001-06-06 20:29:01 +00003638</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003639
Misha Brukman76307852003-11-08 01:05:38 +00003640</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003641
Chris Lattner2f7c9632001-06-06 20:29:01 +00003642<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003643<div class="doc_subsubsection">
3644 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
3645</div>
3646
Misha Brukman76307852003-11-08 01:05:38 +00003647<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003648
Chris Lattner2f7c9632001-06-06 20:29:01 +00003649<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003650<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003651 &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 +00003652</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003653
Chris Lattner2f7c9632001-06-06 20:29:01 +00003654<h5>Overview:</h5>
Jeff Cohen5819f182007-04-22 01:17:39 +00003655<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003656 currently executing function, to be automatically released when this function
3657 returns to its caller. The object is always allocated in the generic address
3658 space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003659
Chris Lattner2f7c9632001-06-06 20:29:01 +00003660<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003661<p>The '<tt>alloca</tt>' instruction
3662 allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt> bytes of memory on the
3663 runtime stack, returning a pointer of the appropriate type to the program.
3664 If "NumElements" is specified, it is the number of elements allocated,
3665 otherwise "NumElements" is defaulted to be one. If a constant alignment is
3666 specified, the value result of the allocation is guaranteed to be aligned to
3667 at least that boundary. If not specified, or if zero, the target can choose
3668 to align the allocation on any convenient boundary compatible with the
3669 type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003670
Misha Brukman76307852003-11-08 01:05:38 +00003671<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003672
Chris Lattner2f7c9632001-06-06 20:29:01 +00003673<h5>Semantics:</h5>
Bill Wendling9ee6a312009-05-08 20:49:29 +00003674<p>Memory is allocated; a pointer is returned. The operation is undefined if
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003675 there is insufficient stack space for the allocation. '<tt>alloca</tt>'d
3676 memory is automatically released when the function returns. The
3677 '<tt>alloca</tt>' instruction is commonly used to represent automatic
3678 variables that must have an address available. When the function returns
3679 (either with the <tt><a href="#i_ret">ret</a></tt>
3680 or <tt><a href="#i_unwind">unwind</a></tt> instructions), the memory is
3681 reclaimed. Allocating zero bytes is legal, but the result is undefined.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003682
Chris Lattner2f7c9632001-06-06 20:29:01 +00003683<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003684<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003685 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
3686 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
3687 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
3688 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003689</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003690
Misha Brukman76307852003-11-08 01:05:38 +00003691</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003692
Chris Lattner2f7c9632001-06-06 20:29:01 +00003693<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003694<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
3695Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003696
Misha Brukman76307852003-11-08 01:05:38 +00003697<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003698
Chris Lattner095735d2002-05-06 03:03:22 +00003699<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003700<pre>
3701 &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3702 &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]
3703</pre>
3704
Chris Lattner095735d2002-05-06 03:03:22 +00003705<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003706<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003707
Chris Lattner095735d2002-05-06 03:03:22 +00003708<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003709<p>The argument to the '<tt>load</tt>' instruction specifies the memory address
3710 from which to load. The pointer must point to
3711 a <a href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
3712 marked as <tt>volatile</tt>, then the optimizer is not allowed to modify the
3713 number or order of execution of this <tt>load</tt> with other
3714 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3715 instructions. </p>
3716
3717<p>The optional constant "align" argument specifies the alignment of the
3718 operation (that is, the alignment of the memory address). A value of 0 or an
3719 omitted "align" argument means that the operation has the preferential
3720 alignment for the target. It is the responsibility of the code emitter to
3721 ensure that the alignment information is correct. Overestimating the
3722 alignment results in an undefined behavior. Underestimating the alignment may
3723 produce less efficient code. An alignment of 1 is always safe.</p>
3724
Chris Lattner095735d2002-05-06 03:03:22 +00003725<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003726<p>The location of memory pointed to is loaded. If the value being loaded is of
3727 scalar type then the number of bytes read does not exceed the minimum number
3728 of bytes needed to hold all bits of the type. For example, loading an
3729 <tt>i24</tt> reads at most three bytes. When loading a value of a type like
3730 <tt>i20</tt> with a size that is not an integral number of bytes, the result
3731 is undefined if the value was not originally written using a store of the
3732 same type.</p>
3733
Chris Lattner095735d2002-05-06 03:03:22 +00003734<h5>Examples:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003735<pre>
3736 %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
3737 <a href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003738 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00003739</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003740
Misha Brukman76307852003-11-08 01:05:38 +00003741</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003742
Chris Lattner095735d2002-05-06 03:03:22 +00003743<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003744<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
3745Instruction</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003746
Reid Spencera89fb182006-11-09 21:18:01 +00003747<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003748
Chris Lattner095735d2002-05-06 03:03:22 +00003749<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003750<pre>
3751 store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
Christopher Lambbff50202007-04-21 08:16:25 +00003752 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 +00003753</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003754
Chris Lattner095735d2002-05-06 03:03:22 +00003755<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003756<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003757
Chris Lattner095735d2002-05-06 03:03:22 +00003758<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003759<p>There are two arguments to the '<tt>store</tt>' instruction: a value to store
3760 and an address at which to store it. The type of the
3761 '<tt>&lt;pointer&gt;</tt>' operand must be a pointer to
3762 the <a href="#t_firstclass">first class</a> type of the
3763 '<tt>&lt;value&gt;</tt>' operand. If the <tt>store</tt> is marked
3764 as <tt>volatile</tt>, then the optimizer is not allowed to modify the number
3765 or order of execution of this <tt>store</tt> with other
3766 volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3767 instructions.</p>
3768
3769<p>The optional constant "align" argument specifies the alignment of the
3770 operation (that is, the alignment of the memory address). A value of 0 or an
3771 omitted "align" argument means that the operation has the preferential
3772 alignment for the target. It is the responsibility of the code emitter to
3773 ensure that the alignment information is correct. Overestimating the
3774 alignment results in an undefined behavior. Underestimating the alignment may
3775 produce less efficient code. An alignment of 1 is always safe.</p>
3776
Chris Lattner48b383b02003-11-25 01:02:51 +00003777<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003778<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>' at the
3779 location specified by the '<tt>&lt;pointer&gt;</tt>' operand. If
3780 '<tt>&lt;value&gt;</tt>' is of scalar type then the number of bytes written
3781 does not exceed the minimum number of bytes needed to hold all bits of the
3782 type. For example, storing an <tt>i24</tt> writes at most three bytes. When
3783 writing a value of a type like <tt>i20</tt> with a size that is not an
3784 integral number of bytes, it is unspecified what happens to the extra bits
3785 that do not belong to the type, but they will typically be overwritten.</p>
3786
Chris Lattner095735d2002-05-06 03:03:22 +00003787<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003788<pre>
3789 %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling8830ffe2007-10-22 05:10:05 +00003790 store i32 3, i32* %ptr <i>; yields {void}</i>
3791 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00003792</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003793
Reid Spencer443460a2006-11-09 21:15:49 +00003794</div>
3795
Chris Lattner095735d2002-05-06 03:03:22 +00003796<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00003797<div class="doc_subsubsection">
3798 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3799</div>
3800
Misha Brukman76307852003-11-08 01:05:38 +00003801<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003802
Chris Lattner590645f2002-04-14 06:13:44 +00003803<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003804<pre>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003805 &lt;result&gt; = getelementptr &lt;pty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
Chris Lattner33fd7022004-04-05 01:30:49 +00003806</pre>
3807
Chris Lattner590645f2002-04-14 06:13:44 +00003808<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003809<p>The '<tt>getelementptr</tt>' instruction is used to get the address of a
3810 subelement of an aggregate data structure. It performs address calculation
3811 only and does not access memory.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003812
Chris Lattner590645f2002-04-14 06:13:44 +00003813<h5>Arguments:</h5>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003814<p>The first argument is always a pointer, and forms the basis of the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003815 calculation. The remaining arguments are indices, that indicate which of the
3816 elements of the aggregate object are indexed. The interpretation of each
3817 index is dependent on the type being indexed into. The first index always
3818 indexes the pointer value given as the first argument, the second index
3819 indexes a value of the type pointed to (not necessarily the value directly
3820 pointed to, since the first index can be non-zero), etc. The first type
3821 indexed into must be a pointer value, subsequent types can be arrays, vectors
3822 and structs. Note that subsequent types being indexed into can never be
3823 pointers, since that would require loading the pointer before continuing
3824 calculation.</p>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003825
3826<p>The type of each index argument depends on the type it is indexing into.
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003827 When indexing into a (packed) structure, only <tt>i32</tt> integer
3828 <b>constants</b> are allowed. When indexing into an array, pointer or
3829 vector, integers of any width are allowed (also non-constants).</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003830
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003831<p>For example, let's consider a C code fragment and how it gets compiled to
3832 LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003833
Bill Wendling3716c5d2007-05-29 09:04:49 +00003834<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00003835<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003836struct RT {
3837 char A;
Chris Lattnera446f1b2007-05-29 15:43:56 +00003838 int B[10][20];
Bill Wendling3716c5d2007-05-29 09:04:49 +00003839 char C;
3840};
3841struct ST {
Chris Lattnera446f1b2007-05-29 15:43:56 +00003842 int X;
Bill Wendling3716c5d2007-05-29 09:04:49 +00003843 double Y;
3844 struct RT Z;
3845};
Chris Lattner33fd7022004-04-05 01:30:49 +00003846
Chris Lattnera446f1b2007-05-29 15:43:56 +00003847int *foo(struct ST *s) {
Bill Wendling3716c5d2007-05-29 09:04:49 +00003848 return &amp;s[1].Z.B[5][13];
3849}
Chris Lattner33fd7022004-04-05 01:30:49 +00003850</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003851</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003852
Misha Brukman76307852003-11-08 01:05:38 +00003853<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003854
Bill Wendling3716c5d2007-05-29 09:04:49 +00003855<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00003856<pre>
Chris Lattnerbc088212009-01-11 20:53:49 +00003857%RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 }
3858%ST = <a href="#namedtypes">type</a> { i32, double, %RT }
Chris Lattner33fd7022004-04-05 01:30:49 +00003859
Bill Wendling3716c5d2007-05-29 09:04:49 +00003860define i32* %foo(%ST* %s) {
3861entry:
3862 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3863 ret i32* %reg
3864}
Chris Lattner33fd7022004-04-05 01:30:49 +00003865</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003866</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003867
Chris Lattner590645f2002-04-14 06:13:44 +00003868<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003869<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003870 type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
3871 }</tt>' type, a structure. The second index indexes into the third element
3872 of the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3873 i8 }</tt>' type, another structure. The third index indexes into the second
3874 element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
3875 array. The two dimensions of the array are subscripted into, yielding an
3876 '<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a
3877 pointer to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003878
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003879<p>Note that it is perfectly legal to index partially through a structure,
3880 returning a pointer to an inner element. Because of this, the LLVM code for
3881 the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003882
3883<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003884 define i32* %foo(%ST* %s) {
3885 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen5819f182007-04-22 01:17:39 +00003886 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3887 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003888 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3889 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3890 ret i32* %t5
Chris Lattner33fd7022004-04-05 01:30:49 +00003891 }
Chris Lattnera8292f32002-05-06 22:08:29 +00003892</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003893
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003894<p>Note that it is undefined to access an array out of bounds: array and pointer
3895 indexes must always be within the defined bounds of the array type when
3896 accessed with an instruction that dereferences the pointer (e.g. a load or
3897 store instruction). The one exception for this rule is zero length arrays.
3898 These arrays are defined to be accessible as variable length arrays, which
3899 requires access beyond the zero'th element.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003900
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003901<p>The getelementptr instruction is often confusing. For some more insight into
3902 how it works, see <a href="GetElementPtr.html">the getelementptr FAQ</a>.</p>
Chris Lattner6ab66722006-08-15 00:45:58 +00003903
Chris Lattner590645f2002-04-14 06:13:44 +00003904<h5>Example:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003905<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003906 <i>; yields [12 x i8]*:aptr</i>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003907 %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
3908 <i>; yields i8*:vptr</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00003909 %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003910 <i>; yields i8*:eptr</i>
3911 %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
Sanjiv Gupta0c155e62009-04-25 07:27:44 +00003912 <i>; yields i32*:iptr</i>
Sanjiv Gupta77abea02009-04-24 16:38:13 +00003913 %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
Chris Lattner33fd7022004-04-05 01:30:49 +00003914</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003915
Chris Lattner33fd7022004-04-05 01:30:49 +00003916</div>
Reid Spencer443460a2006-11-09 21:15:49 +00003917
Chris Lattner2f7c9632001-06-06 20:29:01 +00003918<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00003919<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00003920</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003921
Misha Brukman76307852003-11-08 01:05:38 +00003922<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003923
Reid Spencer97c5fa42006-11-08 01:18:52 +00003924<p>The instructions in this category are the conversion instructions (casting)
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003925 which all take a single operand and a type. They perform various bit
3926 conversions on the operand.</p>
3927
Misha Brukman76307852003-11-08 01:05:38 +00003928</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003929
Chris Lattnera8292f32002-05-06 22:08:29 +00003930<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003931<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003932 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3933</div>
3934<div class="doc_text">
3935
3936<h5>Syntax:</h5>
3937<pre>
3938 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3939</pre>
3940
3941<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003942<p>The '<tt>trunc</tt>' instruction truncates its operand to the
3943 type <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003944
3945<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003946<p>The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3947 be an <a href="#t_integer">integer</a> type, and a type that specifies the
3948 size and type of the result, which must be
3949 an <a href="#t_integer">integer</a> type. The bit size of <tt>value</tt> must
3950 be larger than the bit size of <tt>ty2</tt>. Equal sized types are not
3951 allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003952
3953<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003954<p>The '<tt>trunc</tt>' instruction truncates the high order bits
3955 in <tt>value</tt> and converts the remaining bits to <tt>ty2</tt>. Since the
3956 source size must be larger than the destination size, <tt>trunc</tt> cannot
3957 be a <i>no-op cast</i>. It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003958
3959<h5>Example:</h5>
3960<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003961 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003962 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3963 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003964</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003965
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003966</div>
3967
3968<!-- _______________________________________________________________________ -->
3969<div class="doc_subsubsection">
3970 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3971</div>
3972<div class="doc_text">
3973
3974<h5>Syntax:</h5>
3975<pre>
3976 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3977</pre>
3978
3979<h5>Overview:</h5>
3980<p>The '<tt>zext</tt>' instruction zero extends its operand to type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003981 <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003982
3983
3984<h5>Arguments:</h5>
3985<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003986 <a href="#t_integer">integer</a> type, and a type to cast it to, which must
3987 also be of <a href="#t_integer">integer</a> type. The bit size of the
3988 <tt>value</tt> must be smaller than the bit size of the destination type,
3989 <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003990
3991<h5>Semantics:</h5>
3992<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Bill Wendlingd9a66f72009-07-20 02:29:24 +00003993 bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003994
Reid Spencer07c9c682007-01-12 15:46:11 +00003995<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003996
3997<h5>Example:</h5>
3998<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003999 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencer36a15422007-01-12 03:35:51 +00004000 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004001</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004002
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004003</div>
4004
4005<!-- _______________________________________________________________________ -->
4006<div class="doc_subsubsection">
4007 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
4008</div>
4009<div class="doc_text">
4010
4011<h5>Syntax:</h5>
4012<pre>
4013 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4014</pre>
4015
4016<h5>Overview:</h5>
4017<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
4018
4019<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004020<p>The '<tt>sext</tt>' instruction takes a value to cast, which must be of
4021 <a href="#t_integer">integer</a> type, and a type to cast it to, which must
4022 also be of <a href="#t_integer">integer</a> type. The bit size of the
4023 <tt>value</tt> must be smaller than the bit size of the destination type,
4024 <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004025
4026<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004027<p>The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
4028 bit (highest order bit) of the <tt>value</tt> until it reaches the bit size
4029 of the type <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004030
Reid Spencer36a15422007-01-12 03:35:51 +00004031<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004032
4033<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004034<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004035 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencer36a15422007-01-12 03:35:51 +00004036 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004037</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004038
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004039</div>
4040
4041<!-- _______________________________________________________________________ -->
4042<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00004043 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
4044</div>
4045
4046<div class="doc_text">
4047
4048<h5>Syntax:</h5>
Reid Spencer2e2740d2006-11-09 21:48:10 +00004049<pre>
4050 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4051</pre>
4052
4053<h5>Overview:</h5>
4054<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004055 <tt>ty2</tt>.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00004056
4057<h5>Arguments:</h5>
4058<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004059 point</a> value to cast and a <a href="#t_floating">floating point</a> type
4060 to cast it to. The size of <tt>value</tt> must be larger than the size of
4061 <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
4062 <i>no-op cast</i>.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00004063
4064<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004065<p>The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
4066 <a href="#t_floating">floating point</a> type to a smaller
4067 <a href="#t_floating">floating point</a> type. If the value cannot fit
4068 within the destination type, <tt>ty2</tt>, then the results are
4069 undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00004070
4071<h5>Example:</h5>
4072<pre>
4073 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
4074 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
4075</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004076
Reid Spencer2e2740d2006-11-09 21:48:10 +00004077</div>
4078
4079<!-- _______________________________________________________________________ -->
4080<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004081 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
4082</div>
4083<div class="doc_text">
4084
4085<h5>Syntax:</h5>
4086<pre>
4087 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4088</pre>
4089
4090<h5>Overview:</h5>
4091<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004092 floating point value.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004093
4094<h5>Arguments:</h5>
4095<p>The '<tt>fpext</tt>' instruction takes a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004096 <a href="#t_floating">floating point</a> <tt>value</tt> to cast, and
4097 a <a href="#t_floating">floating point</a> type to cast it to. The source
4098 type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004099
4100<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004101<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004102 <a href="#t_floating">floating point</a> type to a larger
4103 <a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
4104 used to make a <i>no-op cast</i> because it always changes bits. Use
4105 <tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004106
4107<h5>Example:</h5>
4108<pre>
4109 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
4110 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
4111</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004112
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004113</div>
4114
4115<!-- _______________________________________________________________________ -->
4116<div class="doc_subsubsection">
Reid Spencer2eadb532007-01-21 00:29:26 +00004117 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004118</div>
4119<div class="doc_text">
4120
4121<h5>Syntax:</h5>
4122<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00004123 &lt;result&gt; = fptoui &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004124</pre>
4125
4126<h5>Overview:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00004127<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004128 unsigned integer equivalent of type <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004129
4130<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004131<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
4132 scalar or vector <a href="#t_floating">floating point</a> value, and a type
4133 to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4134 type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4135 vector integer type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004136
4137<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004138<p>The '<tt>fptoui</tt>' instruction converts its
4139 <a href="#t_floating">floating point</a> operand into the nearest (rounding
4140 towards zero) unsigned integer value. If the value cannot fit
4141 in <tt>ty2</tt>, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004142
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004143<h5>Example:</h5>
4144<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00004145 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00004146 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencer753163d2007-07-31 14:40:14 +00004147 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004148</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004149
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004150</div>
4151
4152<!-- _______________________________________________________________________ -->
4153<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004154 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004155</div>
4156<div class="doc_text">
4157
4158<h5>Syntax:</h5>
4159<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004160 &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 +00004161</pre>
4162
4163<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004164<p>The '<tt>fptosi</tt>' instruction converts
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004165 <a href="#t_floating">floating point</a> <tt>value</tt> to
4166 type <tt>ty2</tt>.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004167
Chris Lattnera8292f32002-05-06 22:08:29 +00004168<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004169<p>The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
4170 scalar or vector <a href="#t_floating">floating point</a> value, and a type
4171 to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4172 type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4173 vector integer type with the same number of elements as <tt>ty</tt></p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004174
Chris Lattnera8292f32002-05-06 22:08:29 +00004175<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004176<p>The '<tt>fptosi</tt>' instruction converts its
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004177 <a href="#t_floating">floating point</a> operand into the nearest (rounding
4178 towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
4179 the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004180
Chris Lattner70de6632001-07-09 00:26:23 +00004181<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004182<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00004183 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00004184 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004185 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004186</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004187
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004188</div>
4189
4190<!-- _______________________________________________________________________ -->
4191<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004192 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004193</div>
4194<div class="doc_text">
4195
4196<h5>Syntax:</h5>
4197<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004198 &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 +00004199</pre>
4200
4201<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004202<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004203 integer and converts that value to the <tt>ty2</tt> type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004204
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004205<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00004206<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004207 scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4208 it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4209 type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4210 floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004211
4212<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004213<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004214 integer quantity and converts it to the corresponding floating point
4215 value. If the value cannot fit in the floating point value, the results are
4216 undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004217
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004218<h5>Example:</h5>
4219<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004220 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004221 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004222</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004223
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004224</div>
4225
4226<!-- _______________________________________________________________________ -->
4227<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004228 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004229</div>
4230<div class="doc_text">
4231
4232<h5>Syntax:</h5>
4233<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004234 &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 +00004235</pre>
4236
4237<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004238<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed integer
4239 and converts that value to the <tt>ty2</tt> type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004240
4241<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00004242<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004243 scalar or vector <a href="#t_integer">integer</a> value, and a type to cast
4244 it to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4245 type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4246 floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004247
4248<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004249<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed integer
4250 quantity and converts it to the corresponding floating point value. If the
4251 value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004252
4253<h5>Example:</h5>
4254<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004255 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004256 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004257</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004258
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004259</div>
4260
4261<!-- _______________________________________________________________________ -->
4262<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00004263 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
4264</div>
4265<div class="doc_text">
4266
4267<h5>Syntax:</h5>
4268<pre>
4269 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4270</pre>
4271
4272<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004273<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
4274 the integer type <tt>ty2</tt>.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004275
4276<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004277<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
4278 must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
4279 <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004280
4281<h5>Semantics:</h5>
4282<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004283 <tt>ty2</tt> by interpreting the pointer value as an integer and either
4284 truncating or zero extending that value to the size of the integer type. If
4285 <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
4286 <tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
4287 are the same size, then nothing is done (<i>no-op cast</i>) other than a type
4288 change.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004289
4290<h5>Example:</h5>
4291<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004292 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
4293 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004294</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004295
Reid Spencerb7344ff2006-11-11 21:00:47 +00004296</div>
4297
4298<!-- _______________________________________________________________________ -->
4299<div class="doc_subsubsection">
4300 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
4301</div>
4302<div class="doc_text">
4303
4304<h5>Syntax:</h5>
4305<pre>
4306 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4307</pre>
4308
4309<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004310<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to a
4311 pointer type, <tt>ty2</tt>.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004312
4313<h5>Arguments:</h5>
Duncan Sands16f122e2007-03-30 12:22:09 +00004314<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004315 value to cast, and a type to cast it to, which must be a
4316 <a href="#t_pointer">pointer</a> type.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004317
4318<h5>Semantics:</h5>
4319<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004320 <tt>ty2</tt> by applying either a zero extension or a truncation depending on
4321 the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
4322 size of a pointer then a truncation is done. If <tt>value</tt> is smaller
4323 than the size of a pointer then a zero extension is done. If they are the
4324 same size, nothing is done (<i>no-op cast</i>).</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004325
4326<h5>Example:</h5>
4327<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004328 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
4329 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
4330 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004331</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004332
Reid Spencerb7344ff2006-11-11 21:00:47 +00004333</div>
4334
4335<!-- _______________________________________________________________________ -->
4336<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00004337 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004338</div>
4339<div class="doc_text">
4340
4341<h5>Syntax:</h5>
4342<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00004343 &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 +00004344</pre>
4345
4346<h5>Overview:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00004347<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004348 <tt>ty2</tt> without changing any bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004349
4350<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004351<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be a
4352 non-aggregate first class value, and a type to cast it to, which must also be
4353 a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes
4354 of <tt>value</tt> and the destination type, <tt>ty2</tt>, must be
4355 identical. If the source type is a pointer, the destination type must also be
4356 a pointer. This instruction supports bitwise conversion of vectors to
4357 integers and to vectors of other types (as long as they have the same
4358 size).</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004359
4360<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00004361<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004362 <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
4363 this conversion. The conversion is done as if the <tt>value</tt> had been
4364 stored to memory and read back as type <tt>ty2</tt>. Pointer types may only
4365 be converted to other pointer types with this instruction. To convert
4366 pointers to other types, use the <a href="#i_inttoptr">inttoptr</a> or
4367 <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004368
4369<h5>Example:</h5>
4370<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004371 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004372 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004373 %Z = bitcast &lt;2 x int&gt; %V to i64; <i>; yields i64: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00004374</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004375
Misha Brukman76307852003-11-08 01:05:38 +00004376</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004377
Reid Spencer97c5fa42006-11-08 01:18:52 +00004378<!-- ======================================================================= -->
4379<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004380
Reid Spencer97c5fa42006-11-08 01:18:52 +00004381<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004382
4383<p>The instructions in this category are the "miscellaneous" instructions, which
4384 defy better classification.</p>
4385
Reid Spencer97c5fa42006-11-08 01:18:52 +00004386</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004387
4388<!-- _______________________________________________________________________ -->
4389<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
4390</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004391
Reid Spencerc828a0e2006-11-18 21:50:54 +00004392<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004393
Reid Spencerc828a0e2006-11-18 21:50:54 +00004394<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004395<pre>
4396 &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004397</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004398
Reid Spencerc828a0e2006-11-18 21:50:54 +00004399<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004400<p>The '<tt>icmp</tt>' instruction returns a boolean value or a vector of
4401 boolean values based on comparison of its two integer, integer vector, or
4402 pointer operands.</p>
4403
Reid Spencerc828a0e2006-11-18 21:50:54 +00004404<h5>Arguments:</h5>
4405<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004406 the condition code indicating the kind of comparison to perform. It is not a
4407 value, just a keyword. The possible condition code are:</p>
4408
Reid Spencerc828a0e2006-11-18 21:50:54 +00004409<ol>
4410 <li><tt>eq</tt>: equal</li>
4411 <li><tt>ne</tt>: not equal </li>
4412 <li><tt>ugt</tt>: unsigned greater than</li>
4413 <li><tt>uge</tt>: unsigned greater or equal</li>
4414 <li><tt>ult</tt>: unsigned less than</li>
4415 <li><tt>ule</tt>: unsigned less or equal</li>
4416 <li><tt>sgt</tt>: signed greater than</li>
4417 <li><tt>sge</tt>: signed greater or equal</li>
4418 <li><tt>slt</tt>: signed less than</li>
4419 <li><tt>sle</tt>: signed less or equal</li>
4420</ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004421
Chris Lattnerc0f423a2007-01-15 01:54:13 +00004422<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004423 <a href="#t_pointer">pointer</a> or integer <a href="#t_vector">vector</a>
4424 typed. They must also be identical types.</p>
4425
Reid Spencerc828a0e2006-11-18 21:50:54 +00004426<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004427<p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to the
4428 condition code given as <tt>cond</tt>. The comparison performed always yields
4429 either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt>
4430 result, as follows:</p>
4431
Reid Spencerc828a0e2006-11-18 21:50:54 +00004432<ol>
4433 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004434 <tt>false</tt> otherwise. No sign interpretation is necessary or
4435 performed.</li>
4436
Reid Spencerc828a0e2006-11-18 21:50:54 +00004437 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004438 <tt>false</tt> otherwise. No sign interpretation is necessary or
4439 performed.</li>
4440
Reid Spencerc828a0e2006-11-18 21:50:54 +00004441 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004442 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4443
Reid Spencerc828a0e2006-11-18 21:50:54 +00004444 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004445 <tt>true</tt> if <tt>op1</tt> is greater than or equal
4446 to <tt>op2</tt>.</li>
4447
Reid Spencerc828a0e2006-11-18 21:50:54 +00004448 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004449 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4450
Reid Spencerc828a0e2006-11-18 21:50:54 +00004451 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004452 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4453
Reid Spencerc828a0e2006-11-18 21:50:54 +00004454 <li><tt>sgt</tt>: interprets the operands as signed values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004455 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4456
Reid Spencerc828a0e2006-11-18 21:50:54 +00004457 <li><tt>sge</tt>: interprets the operands as signed values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004458 <tt>true</tt> if <tt>op1</tt> is greater than or equal
4459 to <tt>op2</tt>.</li>
4460
Reid Spencerc828a0e2006-11-18 21:50:54 +00004461 <li><tt>slt</tt>: interprets the operands as signed values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004462 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
4463
Reid Spencerc828a0e2006-11-18 21:50:54 +00004464 <li><tt>sle</tt>: interprets the operands as signed values and yields
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004465 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004466</ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004467
Reid Spencerc828a0e2006-11-18 21:50:54 +00004468<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004469 values are compared as if they were integers.</p>
4470
4471<p>If the operands are integer vectors, then they are compared element by
4472 element. The result is an <tt>i1</tt> vector with the same number of elements
4473 as the values being compared. Otherwise, the result is an <tt>i1</tt>.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004474
4475<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004476<pre>
4477 &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004478 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
4479 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
4480 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
4481 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
4482 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004483</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004484
4485<p>Note that the code generator does not yet support vector types with
4486 the <tt>icmp</tt> instruction.</p>
4487
Reid Spencerc828a0e2006-11-18 21:50:54 +00004488</div>
4489
4490<!-- _______________________________________________________________________ -->
4491<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
4492</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004493
Reid Spencerc828a0e2006-11-18 21:50:54 +00004494<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004495
Reid Spencerc828a0e2006-11-18 21:50:54 +00004496<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004497<pre>
4498 &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {i1} or {&lt;N x i1&gt;}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004499</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004500
Reid Spencerc828a0e2006-11-18 21:50:54 +00004501<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004502<p>The '<tt>fcmp</tt>' instruction returns a boolean value or vector of boolean
4503 values based on comparison of its operands.</p>
4504
4505<p>If the operands are floating point scalars, then the result type is a boolean
4506(<a href="#t_primitive"><tt>i1</tt></a>).</p>
4507
4508<p>If the operands are floating point vectors, then the result type is a vector
4509 of boolean with the same number of elements as the operands being
4510 compared.</p>
4511
Reid Spencerc828a0e2006-11-18 21:50:54 +00004512<h5>Arguments:</h5>
4513<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004514 the condition code indicating the kind of comparison to perform. It is not a
4515 value, just a keyword. The possible condition code are:</p>
4516
Reid Spencerc828a0e2006-11-18 21:50:54 +00004517<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00004518 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004519 <li><tt>oeq</tt>: ordered and equal</li>
4520 <li><tt>ogt</tt>: ordered and greater than </li>
4521 <li><tt>oge</tt>: ordered and greater than or equal</li>
4522 <li><tt>olt</tt>: ordered and less than </li>
4523 <li><tt>ole</tt>: ordered and less than or equal</li>
4524 <li><tt>one</tt>: ordered and not equal</li>
4525 <li><tt>ord</tt>: ordered (no nans)</li>
4526 <li><tt>ueq</tt>: unordered or equal</li>
4527 <li><tt>ugt</tt>: unordered or greater than </li>
4528 <li><tt>uge</tt>: unordered or greater than or equal</li>
4529 <li><tt>ult</tt>: unordered or less than </li>
4530 <li><tt>ule</tt>: unordered or less than or equal</li>
4531 <li><tt>une</tt>: unordered or not equal</li>
4532 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004533 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004534</ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004535
Jeff Cohen222a8a42007-04-29 01:07:00 +00004536<p><i>Ordered</i> means that neither operand is a QNAN while
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004537 <i>unordered</i> means that either operand may be a QNAN.</p>
4538
4539<p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be either
4540 a <a href="#t_floating">floating point</a> type or
4541 a <a href="#t_vector">vector</a> of floating point type. They must have
4542 identical types.</p>
4543
Reid Spencerc828a0e2006-11-18 21:50:54 +00004544<h5>Semantics:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00004545<p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004546 according to the condition code given as <tt>cond</tt>. If the operands are
4547 vectors, then the vectors are compared element by element. Each comparison
4548 performed always yields an <a href="#t_primitive">i1</a> result, as
4549 follows:</p>
4550
Reid Spencerc828a0e2006-11-18 21:50:54 +00004551<ol>
4552 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004553
Reid Spencerf69acf32006-11-19 03:00:14 +00004554 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004555 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4556
Reid Spencerf69acf32006-11-19 03:00:14 +00004557 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004558 <tt>op1</tt> is greather than <tt>op2</tt>.</li>
4559
Reid Spencerf69acf32006-11-19 03:00:14 +00004560 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004561 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4562
Reid Spencerf69acf32006-11-19 03:00:14 +00004563 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004564 <tt>op1</tt> is less than <tt>op2</tt>.</li>
4565
Reid Spencerf69acf32006-11-19 03:00:14 +00004566 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004567 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4568
Reid Spencerf69acf32006-11-19 03:00:14 +00004569 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004570 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4571
Reid Spencerf69acf32006-11-19 03:00:14 +00004572 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004573
Reid Spencerf69acf32006-11-19 03:00:14 +00004574 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004575 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
4576
Reid Spencerf69acf32006-11-19 03:00:14 +00004577 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004578 <tt>op1</tt> is greater than <tt>op2</tt>.</li>
4579
Reid Spencerf69acf32006-11-19 03:00:14 +00004580 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004581 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
4582
Reid Spencerf69acf32006-11-19 03:00:14 +00004583 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004584 <tt>op1</tt> is less than <tt>op2</tt>.</li>
4585
Reid Spencerf69acf32006-11-19 03:00:14 +00004586 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004587 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
4588
Reid Spencerf69acf32006-11-19 03:00:14 +00004589 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004590 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
4591
Reid Spencerf69acf32006-11-19 03:00:14 +00004592 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004593
Reid Spencerc828a0e2006-11-18 21:50:54 +00004594 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
4595</ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004596
4597<h5>Example:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004598<pre>
4599 &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
Dan Gohmanc579d972008-09-09 01:02:47 +00004600 &lt;result&gt; = fcmp one float 4.0, 5.0 <i>; yields: result=true</i>
4601 &lt;result&gt; = fcmp olt float 4.0, 5.0 <i>; yields: result=true</i>
4602 &lt;result&gt; = fcmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004603</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004604
4605<p>Note that the code generator does not yet support vector types with
4606 the <tt>fcmp</tt> instruction.</p>
4607
Reid Spencerc828a0e2006-11-18 21:50:54 +00004608</div>
4609
Reid Spencer97c5fa42006-11-08 01:18:52 +00004610<!-- _______________________________________________________________________ -->
Nate Begemand2195702008-05-12 19:01:56 +00004611<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004612 <a name="i_phi">'<tt>phi</tt>' Instruction</a>
4613</div>
4614
Reid Spencer97c5fa42006-11-08 01:18:52 +00004615<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004616
Reid Spencer97c5fa42006-11-08 01:18:52 +00004617<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004618<pre>
4619 &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...
4620</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004621
Reid Spencer97c5fa42006-11-08 01:18:52 +00004622<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004623<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in the
4624 SSA graph representing the function.</p>
4625
Reid Spencer97c5fa42006-11-08 01:18:52 +00004626<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004627<p>The type of the incoming values is specified with the first type field. After
4628 this, the '<tt>phi</tt>' instruction takes a list of pairs as arguments, with
4629 one pair for each predecessor basic block of the current block. Only values
4630 of <a href="#t_firstclass">first class</a> type may be used as the value
4631 arguments to the PHI node. Only labels may be used as the label
4632 arguments.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004633
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004634<p>There must be no non-phi instructions between the start of a basic block and
4635 the PHI instructions: i.e. PHI instructions must be first in a basic
4636 block.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004637
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004638<p>For the purposes of the SSA form, the use of each incoming value is deemed to
4639 occur on the edge from the corresponding predecessor block to the current
4640 block (but after any definition of an '<tt>invoke</tt>' instruction's return
4641 value on the same edge).</p>
Jay Foad1a4eea52009-06-03 10:20:10 +00004642
Reid Spencer97c5fa42006-11-08 01:18:52 +00004643<h5>Semantics:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004644<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004645 specified by the pair corresponding to the predecessor basic block that
4646 executed just prior to the current block.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004647
Reid Spencer97c5fa42006-11-08 01:18:52 +00004648<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004649<pre>
4650Loop: ; Infinite loop that counts from 0 on up...
4651 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
4652 %nextindvar = add i32 %indvar, 1
4653 br label %Loop
4654</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004655
Reid Spencer97c5fa42006-11-08 01:18:52 +00004656</div>
4657
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004658<!-- _______________________________________________________________________ -->
4659<div class="doc_subsubsection">
4660 <a name="i_select">'<tt>select</tt>' Instruction</a>
4661</div>
4662
4663<div class="doc_text">
4664
4665<h5>Syntax:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004666<pre>
Dan Gohmanc579d972008-09-09 01:02:47 +00004667 &lt;result&gt; = select <i>selty</i> &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
4668
Dan Gohmanef9462f2008-10-14 16:51:45 +00004669 <i>selty</i> is either i1 or {&lt;N x i1&gt;}
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004670</pre>
4671
4672<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004673<p>The '<tt>select</tt>' instruction is used to choose one value based on a
4674 condition, without branching.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004675
4676
4677<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004678<p>The '<tt>select</tt>' instruction requires an 'i1' value or a vector of 'i1'
4679 values indicating the condition, and two values of the
4680 same <a href="#t_firstclass">first class</a> type. If the val1/val2 are
4681 vectors and the condition is a scalar, then entire vectors are selected, not
4682 individual elements.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004683
4684<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004685<p>If the condition is an i1 and it evaluates to 1, the instruction returns the
4686 first value argument; otherwise, it returns the second value argument.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004687
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004688<p>If the condition is a vector of i1, then the value arguments must be vectors
4689 of the same size, and the selection is done element by element.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004690
4691<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004692<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00004693 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004694</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004695
4696<p>Note that the code generator does not yet support conditions
4697 with vector type.</p>
4698
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004699</div>
4700
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00004701<!-- _______________________________________________________________________ -->
4702<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00004703 <a name="i_call">'<tt>call</tt>' Instruction</a>
4704</div>
4705
Misha Brukman76307852003-11-08 01:05:38 +00004706<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00004707
Chris Lattner2f7c9632001-06-06 20:29:01 +00004708<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004709<pre>
Devang Patel02256232008-10-07 17:48:33 +00004710 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] &lt;ty&gt; [&lt;fnty&gt;*] &lt;fnptrval&gt;(&lt;function args&gt;) [<a href="#fnattrs">fn attrs</a>]
Chris Lattnere23c1392005-05-06 05:47:36 +00004711</pre>
4712
Chris Lattner2f7c9632001-06-06 20:29:01 +00004713<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00004714<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004715
Chris Lattner2f7c9632001-06-06 20:29:01 +00004716<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00004717<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004718
Chris Lattnera8292f32002-05-06 22:08:29 +00004719<ol>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004720 <li>The optional "tail" marker indicates whether the callee function accesses
4721 any allocas or varargs in the caller. If the "tail" marker is present,
4722 the function call is eligible for tail call optimization. Note that calls
4723 may be marked "tail" even if they do not occur before
4724 a <a href="#i_ret"><tt>ret</tt></a> instruction.</li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00004725
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004726 <li>The optional "cconv" marker indicates which <a href="#callingconv">calling
4727 convention</a> the call should use. If none is specified, the call
4728 defaults to using C calling conventions.</li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00004729
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004730 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
4731 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', and
4732 '<tt>inreg</tt>' attributes are valid here.</li>
4733
4734 <li>'<tt>ty</tt>': the type of the call instruction itself which is also the
4735 type of the return value. Functions that return no value are marked
4736 <tt><a href="#t_void">void</a></tt>.</li>
4737
4738 <li>'<tt>fnty</tt>': shall be the signature of the pointer to function value
4739 being invoked. The argument types must match the types implied by this
4740 signature. This type can be omitted if the function is not varargs and if
4741 the function type does not return a pointer to a function.</li>
4742
4743 <li>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
4744 be invoked. In most cases, this is a direct function invocation, but
4745 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
4746 to function value.</li>
4747
4748 <li>'<tt>function args</tt>': argument list whose types match the function
4749 signature argument types. All arguments must be of
4750 <a href="#t_firstclass">first class</a> type. If the function signature
4751 indicates the function accepts a variable number of arguments, the extra
4752 arguments can be specified.</li>
4753
4754 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
4755 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
4756 '<tt>readnone</tt>' attributes are valid here.</li>
Chris Lattnera8292f32002-05-06 22:08:29 +00004757</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00004758
Chris Lattner2f7c9632001-06-06 20:29:01 +00004759<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004760<p>The '<tt>call</tt>' instruction is used to cause control flow to transfer to
4761 a specified function, with its incoming arguments bound to the specified
4762 values. Upon a '<tt><a href="#i_ret">ret</a></tt>' instruction in the called
4763 function, control flow continues with the instruction after the function
4764 call, and the return value of the function is bound to the result
4765 argument.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004766
Chris Lattner2f7c9632001-06-06 20:29:01 +00004767<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004768<pre>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00004769 %retval = call i32 @test(i32 %argc)
Chris Lattnerfb7c88d2008-03-21 17:24:17 +00004770 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i>
4771 %X = tail call i32 @foo() <i>; yields i32</i>
4772 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i>
4773 call void %foo(i8 97 signext)
Devang Pateld6cff512008-03-10 20:49:15 +00004774
4775 %struct.A = type { i32, i8 }
Devang Patel7e9b05e2008-10-06 18:50:38 +00004776 %r = call %struct.A @foo() <i>; yields { 32, i8 }</i>
Dan Gohmancc3132e2008-10-04 19:00:07 +00004777 %gr = extractvalue %struct.A %r, 0 <i>; yields i32</i>
4778 %gr1 = extractvalue %struct.A %r, 1 <i>; yields i8</i>
Chris Lattner6cbe8e92008-10-08 06:26:11 +00004779 %Z = call void @foo() noreturn <i>; indicates that %foo never returns normally</i>
Matthijs Kooijmaneefa7df2008-10-07 10:03:45 +00004780 %ZZ = call zeroext i32 @bar() <i>; Return value is %zero extended</i>
Chris Lattnere23c1392005-05-06 05:47:36 +00004781</pre>
4782
Misha Brukman76307852003-11-08 01:05:38 +00004783</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004784
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004785<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00004786<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00004787 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004788</div>
4789
Misha Brukman76307852003-11-08 01:05:38 +00004790<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00004791
Chris Lattner26ca62e2003-10-18 05:51:36 +00004792<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004793<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004794 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00004795</pre>
4796
Chris Lattner26ca62e2003-10-18 05:51:36 +00004797<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004798<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004799 the "variable argument" area of a function call. It is used to implement the
4800 <tt>va_arg</tt> macro in C.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004801
Chris Lattner26ca62e2003-10-18 05:51:36 +00004802<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004803<p>This instruction takes a <tt>va_list*</tt> value and the type of the
4804 argument. It returns a value of the specified argument type and increments
4805 the <tt>va_list</tt> to point to the next argument. The actual type
4806 of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004807
Chris Lattner26ca62e2003-10-18 05:51:36 +00004808<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004809<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified type
4810 from the specified <tt>va_list</tt> and causes the <tt>va_list</tt> to point
4811 to the next argument. For more information, see the variable argument
4812 handling <a href="#int_varargs">Intrinsic Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004813
4814<p>It is legal for this instruction to be called in a function which does not
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004815 take a variable number of arguments, for example, the <tt>vfprintf</tt>
4816 function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004817
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004818<p><tt>va_arg</tt> is an LLVM instruction instead of
4819 an <a href="#intrinsics">intrinsic function</a> because it takes a type as an
4820 argument.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004821
Chris Lattner26ca62e2003-10-18 05:51:36 +00004822<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004823<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4824
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004825<p>Note that the code generator does not yet fully support va_arg on many
4826 targets. Also, it does not currently support va_arg with aggregate types on
4827 any target.</p>
Dan Gohman3065b612009-01-12 23:12:39 +00004828
Misha Brukman76307852003-11-08 01:05:38 +00004829</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004830
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004831<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00004832<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4833<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00004834
Misha Brukman76307852003-11-08 01:05:38 +00004835<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00004836
4837<p>LLVM supports the notion of an "intrinsic function". These functions have
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004838 well known names and semantics and are required to follow certain
4839 restrictions. Overall, these intrinsics represent an extension mechanism for
4840 the LLVM language that does not require changing all of the transformations
4841 in LLVM when adding to the language (or the bitcode reader/writer, the
4842 parser, etc...).</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004843
John Criswell88190562005-05-16 16:17:45 +00004844<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004845 prefix is reserved in LLVM for intrinsic names; thus, function names may not
4846 begin with this prefix. Intrinsic functions must always be external
4847 functions: you cannot define the body of intrinsic functions. Intrinsic
4848 functions may only be used in call or invoke instructions: it is illegal to
4849 take the address of an intrinsic function. Additionally, because intrinsic
4850 functions are part of the LLVM language, it is required if any are added that
4851 they be documented here.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004852
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004853<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents a
4854 family of functions that perform the same operation but on different data
4855 types. Because LLVM can represent over 8 million different integer types,
4856 overloading is used commonly to allow an intrinsic function to operate on any
4857 integer type. One or more of the argument types or the result type can be
4858 overloaded to accept any integer type. Argument types may also be defined as
4859 exactly matching a previous argument's type or the result type. This allows
4860 an intrinsic function which accepts multiple arguments, but needs all of them
4861 to be of the same type, to only be overloaded with respect to a single
4862 argument or the result.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004863
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004864<p>Overloaded intrinsics will have the names of its overloaded argument types
4865 encoded into its function name, each preceded by a period. Only those types
4866 which are overloaded result in a name suffix. Arguments whose type is matched
4867 against another type do not. For example, the <tt>llvm.ctpop</tt> function
4868 can take an integer of any width and returns an integer of exactly the same
4869 integer width. This leads to a family of functions such as
4870 <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29
4871 %val)</tt>. Only one type, the return type, is overloaded, and only one type
4872 suffix is required. Because the argument's type is matched against the return
4873 type, it does not require its own name suffix.</p>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004874
4875<p>To learn how to add an intrinsic function, please see the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004876 <a href="ExtendingLLVM.html">Extending LLVM Guide</a>.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004877
Misha Brukman76307852003-11-08 01:05:38 +00004878</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004879
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004880<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00004881<div class="doc_subsection">
4882 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4883</div>
4884
Misha Brukman76307852003-11-08 01:05:38 +00004885<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004886
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004887<p>Variable argument support is defined in LLVM with
4888 the <a href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
4889 intrinsic functions. These functions are related to the similarly named
4890 macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004891
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004892<p>All of these functions operate on arguments that use a target-specific value
4893 type "<tt>va_list</tt>". The LLVM assembly language reference manual does
4894 not define what this type is, so all transformations should be prepared to
4895 handle these functions regardless of the type used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004896
Chris Lattner30b868d2006-05-15 17:26:46 +00004897<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004898 instruction and the variable argument handling intrinsic functions are
4899 used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004900
Bill Wendling3716c5d2007-05-29 09:04:49 +00004901<div class="doc_code">
Chris Lattnerfee11462004-02-12 17:01:32 +00004902<pre>
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004903define i32 @test(i32 %X, ...) {
Chris Lattnerfee11462004-02-12 17:01:32 +00004904 ; Initialize variable argument processing
Jeff Cohen222a8a42007-04-29 01:07:00 +00004905 %ap = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004906 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004907 call void @llvm.va_start(i8* %ap2)
Chris Lattnerfee11462004-02-12 17:01:32 +00004908
4909 ; Read a single integer argument
Jeff Cohen222a8a42007-04-29 01:07:00 +00004910 %tmp = va_arg i8** %ap, i32
Chris Lattnerfee11462004-02-12 17:01:32 +00004911
4912 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Jeff Cohen222a8a42007-04-29 01:07:00 +00004913 %aq = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004914 %aq2 = bitcast i8** %aq to i8*
Jeff Cohen222a8a42007-04-29 01:07:00 +00004915 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004916 call void @llvm.va_end(i8* %aq2)
Chris Lattnerfee11462004-02-12 17:01:32 +00004917
4918 ; Stop processing of arguments.
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004919 call void @llvm.va_end(i8* %ap2)
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004920 ret i32 %tmp
Chris Lattnerfee11462004-02-12 17:01:32 +00004921}
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004922
4923declare void @llvm.va_start(i8*)
4924declare void @llvm.va_copy(i8*, i8*)
4925declare void @llvm.va_end(i8*)
Chris Lattnerfee11462004-02-12 17:01:32 +00004926</pre>
Misha Brukman76307852003-11-08 01:05:38 +00004927</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004928
Bill Wendling3716c5d2007-05-29 09:04:49 +00004929</div>
4930
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004931<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004932<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004933 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004934</div>
4935
4936
Misha Brukman76307852003-11-08 01:05:38 +00004937<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004938
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004939<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004940<pre>
4941 declare void %llvm.va_start(i8* &lt;arglist&gt;)
4942</pre>
4943
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004944<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004945<p>The '<tt>llvm.va_start</tt>' intrinsic initializes <tt>*&lt;arglist&gt;</tt>
4946 for subsequent use by <tt><a href="#i_va_arg">va_arg</a></tt>.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004947
4948<h5>Arguments:</h5>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004949<p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004950
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004951<h5>Semantics:</h5>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004952<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004953 macro available in C. In a target-dependent way, it initializes
4954 the <tt>va_list</tt> element to which the argument points, so that the next
4955 call to <tt>va_arg</tt> will produce the first variable argument passed to
4956 the function. Unlike the C <tt>va_start</tt> macro, this intrinsic does not
4957 need to know the last argument of the function as the compiler can figure
4958 that out.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004959
Misha Brukman76307852003-11-08 01:05:38 +00004960</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004961
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004962<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004963<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004964 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004965</div>
4966
Misha Brukman76307852003-11-08 01:05:38 +00004967<div class="doc_text">
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004968
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004969<h5>Syntax:</h5>
4970<pre>
4971 declare void @llvm.va_end(i8* &lt;arglist&gt;)
4972</pre>
4973
4974<h5>Overview:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004975<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004976 which has been initialized previously
4977 with <tt><a href="#int_va_start">llvm.va_start</a></tt>
4978 or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004979
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004980<h5>Arguments:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004981<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004982
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004983<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00004984<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00004985 macro available in C. In a target-dependent way, it destroys
4986 the <tt>va_list</tt> element to which the argument points. Calls
4987 to <a href="#int_va_start"><tt>llvm.va_start</tt></a>
4988 and <a href="#int_va_copy"> <tt>llvm.va_copy</tt></a> must be matched exactly
4989 with calls to <tt>llvm.va_end</tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004990
Misha Brukman76307852003-11-08 01:05:38 +00004991</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004992
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004993<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004994<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004995 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004996</div>
4997
Misha Brukman76307852003-11-08 01:05:38 +00004998<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004999
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00005000<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005001<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005002 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005003</pre>
5004
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00005005<h5>Overview:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00005006<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005007 from the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005008
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00005009<h5>Arguments:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00005010<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005011 The second argument is a pointer to a <tt>va_list</tt> element to copy
5012 from.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005013
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00005014<h5>Semantics:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00005015<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005016 macro available in C. In a target-dependent way, it copies the
5017 source <tt>va_list</tt> element into the destination <tt>va_list</tt>
5018 element. This intrinsic is necessary because
5019 the <tt><a href="#int_va_start"> llvm.va_start</a></tt> intrinsic may be
5020 arbitrarily complex and require, for example, memory allocation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005021
Misha Brukman76307852003-11-08 01:05:38 +00005022</div>
Chris Lattner941515c2004-01-06 05:31:32 +00005023
Chris Lattnerfee11462004-02-12 17:01:32 +00005024<!-- ======================================================================= -->
5025<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00005026 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
5027</div>
5028
5029<div class="doc_text">
5030
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005031<p>LLVM support for <a href="GarbageCollection.html">Accurate Garbage
Chris Lattner67c37d12008-08-05 18:29:16 +00005032Collection</a> (GC) requires the implementation and generation of these
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005033intrinsics. These intrinsics allow identification of <a href="#int_gcroot">GC
5034roots on the stack</a>, as well as garbage collector implementations that
5035require <a href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a>
5036barriers. Front-ends for type-safe garbage collected languages should generate
5037these intrinsics to make use of the LLVM garbage collectors. For more details,
5038see <a href="GarbageCollection.html">Accurate Garbage Collection with
5039LLVM</a>.</p>
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00005040
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005041<p>The garbage collection intrinsics only operate on objects in the generic
5042 address space (address space zero).</p>
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00005043
Chris Lattner757528b0b2004-05-23 21:06:01 +00005044</div>
5045
5046<!-- _______________________________________________________________________ -->
5047<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005048 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005049</div>
5050
5051<div class="doc_text">
5052
5053<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005054<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005055 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005056</pre>
5057
5058<h5>Overview:</h5>
John Criswelldfe6a862004-12-10 15:51:16 +00005059<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005060 the code generator, and allows some metadata to be associated with it.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005061
5062<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005063<p>The first argument specifies the address of a stack object that contains the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005064 root pointer. The second pointer (which must be either a constant or a
5065 global value address) contains the meta-data to be associated with the
5066 root.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005067
5068<h5>Semantics:</h5>
Chris Lattner851b7712008-04-24 05:59:56 +00005069<p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005070 location. At compile-time, the code generator generates information to allow
5071 the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
5072 intrinsic may only be used in a function which <a href="#gc">specifies a GC
5073 algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005074
5075</div>
5076
Chris Lattner757528b0b2004-05-23 21:06:01 +00005077<!-- _______________________________________________________________________ -->
5078<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005079 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005080</div>
5081
5082<div class="doc_text">
5083
5084<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005085<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005086 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005087</pre>
5088
5089<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005090<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005091 locations, allowing garbage collector implementations that require read
5092 barriers.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005093
5094<h5>Arguments:</h5>
Chris Lattnerf9228072006-03-14 20:02:51 +00005095<p>The second argument is the address to read from, which should be an address
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005096 allocated from the garbage collector. The first object is a pointer to the
5097 start of the referenced object, if needed by the language runtime (otherwise
5098 null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005099
5100<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005101<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005102 instruction, but may be replaced with substantially more complex code by the
5103 garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
5104 may only be used in a function which <a href="#gc">specifies a GC
5105 algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005106
5107</div>
5108
Chris Lattner757528b0b2004-05-23 21:06:01 +00005109<!-- _______________________________________________________________________ -->
5110<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005111 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005112</div>
5113
5114<div class="doc_text">
5115
5116<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005117<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005118 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005119</pre>
5120
5121<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005122<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005123 locations, allowing garbage collector implementations that require write
5124 barriers (such as generational or reference counting collectors).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005125
5126<h5>Arguments:</h5>
Chris Lattnerf9228072006-03-14 20:02:51 +00005127<p>The first argument is the reference to store, the second is the start of the
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005128 object to store it to, and the third is the address of the field of Obj to
5129 store to. If the runtime does not require a pointer to the object, Obj may
5130 be null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005131
5132<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005133<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005134 instruction, but may be replaced with substantially more complex code by the
5135 garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
5136 may only be used in a function which <a href="#gc">specifies a GC
5137 algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005138
5139</div>
5140
Chris Lattner757528b0b2004-05-23 21:06:01 +00005141<!-- ======================================================================= -->
5142<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00005143 <a name="int_codegen">Code Generator Intrinsics</a>
5144</div>
5145
5146<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005147
5148<p>These intrinsics are provided by LLVM to expose special features that may
5149 only be implemented with code generator support.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005150
5151</div>
5152
5153<!-- _______________________________________________________________________ -->
5154<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005155 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005156</div>
5157
5158<div class="doc_text">
5159
5160<h5>Syntax:</h5>
5161<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005162 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005163</pre>
5164
5165<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005166<p>The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
5167 target-specific value indicating the return address of the current function
5168 or one of its callers.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005169
5170<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005171<p>The argument to this intrinsic indicates which function to return the address
5172 for. Zero indicates the calling function, one indicates its caller, etc.
5173 The argument is <b>required</b> to be a constant integer value.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005174
5175<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005176<p>The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer
5177 indicating the return address of the specified call frame, or zero if it
5178 cannot be identified. The value returned by this intrinsic is likely to be
5179 incorrect or 0 for arguments other than zero, so it should only be used for
5180 debugging purposes.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005181
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005182<p>Note that calling this intrinsic does not prevent function inlining or other
5183 aggressive transformations, so the value returned may not be that of the
5184 obvious source-language caller.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005185
Chris Lattner3649c3a2004-02-14 04:08:35 +00005186</div>
5187
Chris Lattner3649c3a2004-02-14 04:08:35 +00005188<!-- _______________________________________________________________________ -->
5189<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005190 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005191</div>
5192
5193<div class="doc_text">
5194
5195<h5>Syntax:</h5>
5196<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005197 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005198</pre>
5199
5200<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005201<p>The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
5202 target-specific frame pointer value for the specified stack frame.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005203
5204<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005205<p>The argument to this intrinsic indicates which function to return the frame
5206 pointer for. Zero indicates the calling function, one indicates its caller,
5207 etc. The argument is <b>required</b> to be a constant integer value.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005208
5209<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005210<p>The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer
5211 indicating the frame address of the specified call frame, or zero if it
5212 cannot be identified. The value returned by this intrinsic is likely to be
5213 incorrect or 0 for arguments other than zero, so it should only be used for
5214 debugging purposes.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005215
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005216<p>Note that calling this intrinsic does not prevent function inlining or other
5217 aggressive transformations, so the value returned may not be that of the
5218 obvious source-language caller.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005219
Chris Lattner3649c3a2004-02-14 04:08:35 +00005220</div>
5221
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005222<!-- _______________________________________________________________________ -->
5223<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005224 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005225</div>
5226
5227<div class="doc_text">
5228
5229<h5>Syntax:</h5>
5230<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005231 declare i8 *@llvm.stacksave()
Chris Lattner2f0f0012006-01-13 02:03:13 +00005232</pre>
5233
5234<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005235<p>The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state
5236 of the function stack, for use
5237 with <a href="#int_stackrestore"> <tt>llvm.stackrestore</tt></a>. This is
5238 useful for implementing language features like scoped automatic variable
5239 sized arrays in C99.</p>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005240
5241<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005242<p>This intrinsic returns a opaque pointer value that can be passed
5243 to <a href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When
5244 an <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved
5245 from <tt>llvm.stacksave</tt>, it effectively restores the state of the stack
5246 to the state it was in when the <tt>llvm.stacksave</tt> intrinsic executed.
5247 In practice, this pops any <a href="#i_alloca">alloca</a> blocks from the
5248 stack that were allocated after the <tt>llvm.stacksave</tt> was executed.</p>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005249
5250</div>
5251
5252<!-- _______________________________________________________________________ -->
5253<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005254 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005255</div>
5256
5257<div class="doc_text">
5258
5259<h5>Syntax:</h5>
5260<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005261 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner2f0f0012006-01-13 02:03:13 +00005262</pre>
5263
5264<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005265<p>The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
5266 the function stack to the state it was in when the
5267 corresponding <a href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic
5268 executed. This is useful for implementing language features like scoped
5269 automatic variable sized arrays in C99.</p>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005270
5271<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005272<p>See the description
5273 for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.</p>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005274
5275</div>
5276
Chris Lattner2f0f0012006-01-13 02:03:13 +00005277<!-- _______________________________________________________________________ -->
5278<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005279 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005280</div>
5281
5282<div class="doc_text">
5283
5284<h5>Syntax:</h5>
5285<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005286 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005287</pre>
5288
5289<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005290<p>The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to
5291 insert a prefetch instruction if supported; otherwise, it is a noop.
5292 Prefetches have no effect on the behavior of the program but can change its
5293 performance characteristics.</p>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005294
5295<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005296<p><tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the
5297 specifier determining if the fetch should be for a read (0) or write (1),
5298 and <tt>locality</tt> is a temporal locality specifier ranging from (0) - no
5299 locality, to (3) - extremely local keep in cache. The <tt>rw</tt>
5300 and <tt>locality</tt> arguments must be constant integers.</p>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005301
5302<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005303<p>This intrinsic does not modify the behavior of the program. In particular,
5304 prefetches cannot trap and do not produce a value. On targets that support
5305 this intrinsic, the prefetch can provide hints to the processor cache for
5306 better performance.</p>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005307
5308</div>
5309
Andrew Lenharthb4427912005-03-28 20:05:49 +00005310<!-- _______________________________________________________________________ -->
5311<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005312 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharthb4427912005-03-28 20:05:49 +00005313</div>
5314
5315<div class="doc_text">
5316
5317<h5>Syntax:</h5>
5318<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005319 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Andrew Lenharthb4427912005-03-28 20:05:49 +00005320</pre>
5321
5322<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005323<p>The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program
5324 Counter (PC) in a region of code to simulators and other tools. The method
5325 is target specific, but it is expected that the marker will use exported
5326 symbols to transmit the PC of the marker. The marker makes no guarantees
5327 that it will remain with any specific instruction after optimizations. It is
5328 possible that the presence of a marker will inhibit optimizations. The
5329 intended use is to be inserted after optimizations to allow correlations of
5330 simulation runs.</p>
Andrew Lenharthb4427912005-03-28 20:05:49 +00005331
5332<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005333<p><tt>id</tt> is a numerical id identifying the marker.</p>
Andrew Lenharthb4427912005-03-28 20:05:49 +00005334
5335<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005336<p>This intrinsic does not modify the behavior of the program. Backends that do
5337 not support this intrinisic may ignore it.</p>
Andrew Lenharthb4427912005-03-28 20:05:49 +00005338
5339</div>
5340
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005341<!-- _______________________________________________________________________ -->
5342<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005343 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005344</div>
5345
5346<div class="doc_text">
5347
5348<h5>Syntax:</h5>
5349<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005350 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005351</pre>
5352
5353<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005354<p>The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
5355 counter register (or similar low latency, high accuracy clocks) on those
5356 targets that support it. On X86, it should map to RDTSC. On Alpha, it
5357 should map to RPCC. As the backing counters overflow quickly (on the order
5358 of 9 seconds on alpha), this should only be used for small timings.</p>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005359
5360<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005361<p>When directly supported, reading the cycle counter should not modify any
5362 memory. Implementations are allowed to either return a application specific
5363 value or a system wide value. On backends without support, this is lowered
5364 to a constant 0.</p>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005365
5366</div>
5367
Chris Lattner3649c3a2004-02-14 04:08:35 +00005368<!-- ======================================================================= -->
5369<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00005370 <a name="int_libc">Standard C Library Intrinsics</a>
5371</div>
5372
5373<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005374
5375<p>LLVM provides intrinsics for a few important standard C library functions.
5376 These intrinsics allow source-language front-ends to pass information about
5377 the alignment of the pointer arguments to the code generator, providing
5378 opportunity for more efficient code generation.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005379
5380</div>
5381
5382<!-- _______________________________________________________________________ -->
5383<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005384 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattnerfee11462004-02-12 17:01:32 +00005385</div>
5386
5387<div class="doc_text">
5388
5389<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005390<p>This is an overloaded intrinsic. You can use <tt>llvm.memcpy</tt> on any
5391 integer bit width. Not all targets support all bit widths however.</p>
5392
Chris Lattnerfee11462004-02-12 17:01:32 +00005393<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005394 declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005395 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerdd708342008-11-21 16:42:48 +00005396 declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5397 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005398 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005399 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005400 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005401 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00005402</pre>
5403
5404<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005405<p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5406 source location to the destination location.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005407
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005408<p>Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
5409 intrinsics do not return a value, and takes an extra alignment argument.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005410
5411<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005412<p>The first argument is a pointer to the destination, the second is a pointer
5413 to the source. The third argument is an integer argument specifying the
5414 number of bytes to copy, and the fourth argument is the alignment of the
5415 source and destination locations.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005416
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005417<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5418 then the caller guarantees that both the source and destination pointers are
5419 aligned to that boundary.</p>
Chris Lattner4c67c482004-02-12 21:18:15 +00005420
Chris Lattnerfee11462004-02-12 17:01:32 +00005421<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005422<p>The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the
5423 source location to the destination location, which are not allowed to
5424 overlap. It copies "len" bytes of memory over. If the argument is known to
5425 be aligned to some boundary, this can be specified as the fourth argument,
5426 otherwise it should be set to 0 or 1.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005427
Chris Lattnerfee11462004-02-12 17:01:32 +00005428</div>
5429
Chris Lattnerf30152e2004-02-12 18:10:10 +00005430<!-- _______________________________________________________________________ -->
5431<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005432 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005433</div>
5434
5435<div class="doc_text">
5436
5437<h5>Syntax:</h5>
Chris Lattnerdd708342008-11-21 16:42:48 +00005438<p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005439 width. Not all targets support all bit widths however.</p>
5440
Chris Lattnerf30152e2004-02-12 18:10:10 +00005441<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005442 declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005443 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerdd708342008-11-21 16:42:48 +00005444 declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5445 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005446 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005447 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005448 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005449 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00005450</pre>
5451
5452<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005453<p>The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the
5454 source location to the destination location. It is similar to the
5455 '<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to
5456 overlap.</p>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005457
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005458<p>Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
5459 intrinsics do not return a value, and takes an extra alignment argument.</p>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005460
5461<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005462<p>The first argument is a pointer to the destination, the second is a pointer
5463 to the source. The third argument is an integer argument specifying the
5464 number of bytes to copy, and the fourth argument is the alignment of the
5465 source and destination locations.</p>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005466
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005467<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5468 then the caller guarantees that the source and destination pointers are
5469 aligned to that boundary.</p>
Chris Lattner4c67c482004-02-12 21:18:15 +00005470
Chris Lattnerf30152e2004-02-12 18:10:10 +00005471<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005472<p>The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the
5473 source location to the destination location, which may overlap. It copies
5474 "len" bytes of memory over. If the argument is known to be aligned to some
5475 boundary, this can be specified as the fourth argument, otherwise it should
5476 be set to 0 or 1.</p>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005477
Chris Lattnerf30152e2004-02-12 18:10:10 +00005478</div>
5479
Chris Lattner3649c3a2004-02-14 04:08:35 +00005480<!-- _______________________________________________________________________ -->
5481<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005482 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005483</div>
5484
5485<div class="doc_text">
5486
5487<h5>Syntax:</h5>
Chris Lattnerdd708342008-11-21 16:42:48 +00005488<p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005489 width. Not all targets support all bit widths however.</p>
5490
Chris Lattner3649c3a2004-02-14 04:08:35 +00005491<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005492 declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005493 i8 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerdd708342008-11-21 16:42:48 +00005494 declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5495 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005496 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005497 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005498 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005499 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005500</pre>
5501
5502<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005503<p>The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a
5504 particular byte value.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005505
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005506<p>Note that, unlike the standard libc function, the <tt>llvm.memset</tt>
5507 intrinsic does not return a value, and takes an extra alignment argument.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005508
5509<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005510<p>The first argument is a pointer to the destination to fill, the second is the
5511 byte value to fill it with, the third argument is an integer argument
5512 specifying the number of bytes to fill, and the fourth argument is the known
5513 alignment of destination location.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005514
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005515<p>If the call to this intrinisic has an alignment value that is not 0 or 1,
5516 then the caller guarantees that the destination pointer is aligned to that
5517 boundary.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005518
5519<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005520<p>The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting
5521 at the destination location. If the argument is known to be aligned to some
5522 boundary, this can be specified as the fourth argument, otherwise it should
5523 be set to 0 or 1.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005524
Chris Lattner3649c3a2004-02-14 04:08:35 +00005525</div>
5526
Chris Lattner3b4f4372004-06-11 02:28:03 +00005527<!-- _______________________________________________________________________ -->
5528<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005529 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005530</div>
5531
5532<div class="doc_text">
5533
5534<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005535<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
5536 floating point or vector of floating point type. Not all targets support all
5537 types however.</p>
5538
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005539<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00005540 declare float @llvm.sqrt.f32(float %Val)
5541 declare double @llvm.sqrt.f64(double %Val)
5542 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
5543 declare fp128 @llvm.sqrt.f128(fp128 %Val)
5544 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005545</pre>
5546
5547<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005548<p>The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
5549 returning the same value as the libm '<tt>sqrt</tt>' functions would.
5550 Unlike <tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined
5551 behavior for negative numbers other than -0.0 (which allows for better
5552 optimization, because there is no need to worry about errno being
5553 set). <tt>llvm.sqrt(-0.0)</tt> is defined to return -0.0 like IEEE sqrt.</p>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005554
5555<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005556<p>The argument and return value are floating point numbers of the same
5557 type.</p>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005558
5559<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005560<p>This function returns the sqrt of the specified operand if it is a
5561 nonnegative floating point number.</p>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005562
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005563</div>
5564
Chris Lattner33b73f92006-09-08 06:34:02 +00005565<!-- _______________________________________________________________________ -->
5566<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005567 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattner33b73f92006-09-08 06:34:02 +00005568</div>
5569
5570<div class="doc_text">
5571
5572<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005573<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
5574 floating point or vector of floating point type. Not all targets support all
5575 types however.</p>
5576
Chris Lattner33b73f92006-09-08 06:34:02 +00005577<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00005578 declare float @llvm.powi.f32(float %Val, i32 %power)
5579 declare double @llvm.powi.f64(double %Val, i32 %power)
5580 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
5581 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
5582 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Chris Lattner33b73f92006-09-08 06:34:02 +00005583</pre>
5584
5585<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005586<p>The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
5587 specified (positive or negative) power. The order of evaluation of
5588 multiplications is not defined. When a vector of floating point type is
5589 used, the second argument remains a scalar integer value.</p>
Chris Lattner33b73f92006-09-08 06:34:02 +00005590
5591<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005592<p>The second argument is an integer power, and the first is a value to raise to
5593 that power.</p>
Chris Lattner33b73f92006-09-08 06:34:02 +00005594
5595<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005596<p>This function returns the first value raised to the second power with an
5597 unspecified sequence of rounding operations.</p>
Chris Lattner33b73f92006-09-08 06:34:02 +00005598
Chris Lattner33b73f92006-09-08 06:34:02 +00005599</div>
5600
Dan Gohmanb6324c12007-10-15 20:30:11 +00005601<!-- _______________________________________________________________________ -->
5602<div class="doc_subsubsection">
5603 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
5604</div>
5605
5606<div class="doc_text">
5607
5608<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005609<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
5610 floating point or vector of floating point type. Not all targets support all
5611 types however.</p>
5612
Dan Gohmanb6324c12007-10-15 20:30:11 +00005613<pre>
5614 declare float @llvm.sin.f32(float %Val)
5615 declare double @llvm.sin.f64(double %Val)
5616 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
5617 declare fp128 @llvm.sin.f128(fp128 %Val)
5618 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
5619</pre>
5620
5621<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005622<p>The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005623
5624<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005625<p>The argument and return value are floating point numbers of the same
5626 type.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005627
5628<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005629<p>This function returns the sine of the specified operand, returning the same
5630 values as the libm <tt>sin</tt> functions would, and handles error conditions
5631 in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005632
Dan Gohmanb6324c12007-10-15 20:30:11 +00005633</div>
5634
5635<!-- _______________________________________________________________________ -->
5636<div class="doc_subsubsection">
5637 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
5638</div>
5639
5640<div class="doc_text">
5641
5642<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005643<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
5644 floating point or vector of floating point type. Not all targets support all
5645 types however.</p>
5646
Dan Gohmanb6324c12007-10-15 20:30:11 +00005647<pre>
5648 declare float @llvm.cos.f32(float %Val)
5649 declare double @llvm.cos.f64(double %Val)
5650 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
5651 declare fp128 @llvm.cos.f128(fp128 %Val)
5652 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
5653</pre>
5654
5655<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005656<p>The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005657
5658<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005659<p>The argument and return value are floating point numbers of the same
5660 type.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005661
5662<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005663<p>This function returns the cosine of the specified operand, returning the same
5664 values as the libm <tt>cos</tt> functions would, and handles error conditions
5665 in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005666
Dan Gohmanb6324c12007-10-15 20:30:11 +00005667</div>
5668
5669<!-- _______________________________________________________________________ -->
5670<div class="doc_subsubsection">
5671 <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
5672</div>
5673
5674<div class="doc_text">
5675
5676<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005677<p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
5678 floating point or vector of floating point type. Not all targets support all
5679 types however.</p>
5680
Dan Gohmanb6324c12007-10-15 20:30:11 +00005681<pre>
5682 declare float @llvm.pow.f32(float %Val, float %Power)
5683 declare double @llvm.pow.f64(double %Val, double %Power)
5684 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
5685 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
5686 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
5687</pre>
5688
5689<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005690<p>The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5691 specified (positive or negative) power.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005692
5693<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005694<p>The second argument is a floating point power, and the first is a value to
5695 raise to that power.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005696
5697<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005698<p>This function returns the first value raised to the second power, returning
5699 the same values as the libm <tt>pow</tt> functions would, and handles error
5700 conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005701
Dan Gohmanb6324c12007-10-15 20:30:11 +00005702</div>
5703
Andrew Lenharth1d463522005-05-03 18:01:48 +00005704<!-- ======================================================================= -->
5705<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00005706 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005707</div>
5708
5709<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005710
5711<p>LLVM provides intrinsics for a few important bit manipulation operations.
5712 These allow efficient code generation for some algorithms.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005713
5714</div>
5715
5716<!-- _______________________________________________________________________ -->
5717<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005718 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005719</div>
5720
5721<div class="doc_text">
5722
5723<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005724<p>This is an overloaded intrinsic function. You can use bswap on any integer
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005725 type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p>
5726
Nate Begeman0f223bb2006-01-13 23:26:38 +00005727<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005728 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5729 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5730 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00005731</pre>
5732
5733<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005734<p>The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
5735 values with an even number of bytes (positive multiple of 16 bits). These
5736 are useful for performing operations on data that is not in the target's
5737 native byte order.</p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005738
5739<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005740<p>The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
5741 and low byte of the input i16 swapped. Similarly,
5742 the <tt>llvm.bswap.i32</tt> intrinsic returns an i32 value that has the four
5743 bytes of the input i32 swapped, so that if the input bytes are numbered 0, 1,
5744 2, 3 then the returned i32 will have its bytes in 3, 2, 1, 0 order.
5745 The <tt>llvm.bswap.i48</tt>, <tt>llvm.bswap.i64</tt> and other intrinsics
5746 extend this concept to additional even-byte lengths (6 bytes, 8 bytes and
5747 more, respectively).</p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005748
5749</div>
5750
5751<!-- _______________________________________________________________________ -->
5752<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005753 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005754</div>
5755
5756<div class="doc_text">
5757
5758<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005759<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005760 width. Not all targets support all bit widths however.</p>
5761
Andrew Lenharth1d463522005-05-03 18:01:48 +00005762<pre>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005763 declare i8 @llvm.ctpop.i8(i8 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005764 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005765 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005766 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5767 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00005768</pre>
5769
5770<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005771<p>The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set
5772 in a value.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005773
5774<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005775<p>The only argument is the value to be counted. The argument may be of any
5776 integer type. The return type must match the argument type.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005777
5778<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005779<p>The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005780
Andrew Lenharth1d463522005-05-03 18:01:48 +00005781</div>
5782
5783<!-- _______________________________________________________________________ -->
5784<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00005785 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005786</div>
5787
5788<div class="doc_text">
5789
5790<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005791<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
5792 integer bit width. Not all targets support all bit widths however.</p>
5793
Andrew Lenharth1d463522005-05-03 18:01:48 +00005794<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005795 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
5796 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005797 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005798 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5799 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00005800</pre>
5801
5802<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005803<p>The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5804 leading zeros in a variable.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005805
5806<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005807<p>The only argument is the value to be counted. The argument may be of any
5808 integer type. The return type must match the argument type.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005809
5810<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005811<p>The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant)
5812 zeros in a variable. If the src == 0 then the result is the size in bits of
5813 the type of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005814
Andrew Lenharth1d463522005-05-03 18:01:48 +00005815</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00005816
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005817<!-- _______________________________________________________________________ -->
5818<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00005819 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005820</div>
5821
5822<div class="doc_text">
5823
5824<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005825<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
5826 integer bit width. Not all targets support all bit widths however.</p>
5827
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005828<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005829 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5830 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005831 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005832 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5833 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005834</pre>
5835
5836<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005837<p>The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5838 trailing zeros.</p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005839
5840<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005841<p>The only argument is the value to be counted. The argument may be of any
5842 integer type. The return type must match the argument type.</p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005843
5844<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005845<p>The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant)
5846 zeros in a variable. If the src == 0 then the result is the size in bits of
5847 the type of src. For example, <tt>llvm.cttz(2) = 1</tt>.</p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005848
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005849</div>
5850
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005851<!-- ======================================================================= -->
5852<div class="doc_subsection">
5853 <a name="int_overflow">Arithmetic with Overflow Intrinsics</a>
5854</div>
5855
5856<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005857
5858<p>LLVM provides intrinsics for some arithmetic with overflow operations.</p>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005859
5860</div>
5861
Bill Wendlingf4d70622009-02-08 01:40:31 +00005862<!-- _______________________________________________________________________ -->
5863<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005864 <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005865</div>
5866
5867<div class="doc_text">
5868
5869<h5>Syntax:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005870<p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005871 on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005872
5873<pre>
5874 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
5875 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5876 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
5877</pre>
5878
5879<h5>Overview:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005880<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005881 a signed addition of the two arguments, and indicate whether an overflow
5882 occurred during the signed summation.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005883
5884<h5>Arguments:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005885<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005886 be of integer types of any bit width, but they must have the same bit
5887 width. The second element of the result structure must be of
5888 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5889 undergo signed addition.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005890
5891<h5>Semantics:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005892<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005893 a signed addition of the two variables. They return a structure &mdash; the
5894 first element of which is the signed summation, and the second element of
5895 which is a bit specifying if the signed summation resulted in an
5896 overflow.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005897
5898<h5>Examples:</h5>
5899<pre>
5900 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5901 %sum = extractvalue {i32, i1} %res, 0
5902 %obit = extractvalue {i32, i1} %res, 1
5903 br i1 %obit, label %overflow, label %normal
5904</pre>
5905
5906</div>
5907
5908<!-- _______________________________________________________________________ -->
5909<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005910 <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005911</div>
5912
5913<div class="doc_text">
5914
5915<h5>Syntax:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005916<p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005917 on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005918
5919<pre>
5920 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
5921 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5922 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
5923</pre>
5924
5925<h5>Overview:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005926<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005927 an unsigned addition of the two arguments, and indicate whether a carry
5928 occurred during the unsigned summation.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005929
5930<h5>Arguments:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005931<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005932 be of integer types of any bit width, but they must have the same bit
5933 width. The second element of the result structure must be of
5934 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5935 undergo unsigned addition.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005936
5937<h5>Semantics:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005938<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005939 an unsigned addition of the two arguments. They return a structure &mdash;
5940 the first element of which is the sum, and the second element of which is a
5941 bit specifying if the unsigned summation resulted in a carry.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005942
5943<h5>Examples:</h5>
5944<pre>
5945 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
5946 %sum = extractvalue {i32, i1} %res, 0
5947 %obit = extractvalue {i32, i1} %res, 1
5948 br i1 %obit, label %carry, label %normal
5949</pre>
5950
5951</div>
5952
5953<!-- _______________________________________________________________________ -->
5954<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005955 <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005956</div>
5957
5958<div class="doc_text">
5959
5960<h5>Syntax:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005961<p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005962 on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005963
5964<pre>
5965 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
5966 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5967 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
5968</pre>
5969
5970<h5>Overview:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005971<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005972 a signed subtraction of the two arguments, and indicate whether an overflow
5973 occurred during the signed subtraction.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005974
5975<h5>Arguments:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005976<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005977 be of integer types of any bit width, but they must have the same bit
5978 width. The second element of the result structure must be of
5979 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
5980 undergo signed subtraction.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005981
5982<h5>Semantics:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005983<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00005984 a signed subtraction of the two arguments. They return a structure &mdash;
5985 the first element of which is the subtraction, and the second element of
5986 which is a bit specifying if the signed subtraction resulted in an
5987 overflow.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005988
5989<h5>Examples:</h5>
5990<pre>
5991 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
5992 %sum = extractvalue {i32, i1} %res, 0
5993 %obit = extractvalue {i32, i1} %res, 1
5994 br i1 %obit, label %overflow, label %normal
5995</pre>
5996
5997</div>
5998
5999<!-- _______________________________________________________________________ -->
6000<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006001 <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006002</div>
6003
6004<div class="doc_text">
6005
6006<h5>Syntax:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006007<p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006008 on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006009
6010<pre>
6011 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
6012 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6013 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
6014</pre>
6015
6016<h5>Overview:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006017<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006018 an unsigned subtraction of the two arguments, and indicate whether an
6019 overflow occurred during the unsigned subtraction.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006020
6021<h5>Arguments:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006022<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006023 be of integer types of any bit width, but they must have the same bit
6024 width. The second element of the result structure must be of
6025 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6026 undergo unsigned subtraction.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006027
6028<h5>Semantics:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006029<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006030 an unsigned subtraction of the two arguments. They return a structure &mdash;
6031 the first element of which is the subtraction, and the second element of
6032 which is a bit specifying if the unsigned subtraction resulted in an
6033 overflow.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006034
6035<h5>Examples:</h5>
6036<pre>
6037 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6038 %sum = extractvalue {i32, i1} %res, 0
6039 %obit = extractvalue {i32, i1} %res, 1
6040 br i1 %obit, label %overflow, label %normal
6041</pre>
6042
6043</div>
6044
6045<!-- _______________________________________________________________________ -->
6046<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006047 <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006048</div>
6049
6050<div class="doc_text">
6051
6052<h5>Syntax:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006053<p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006054 on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006055
6056<pre>
6057 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
6058 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6059 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
6060</pre>
6061
6062<h5>Overview:</h5>
6063
6064<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006065 a signed multiplication of the two arguments, and indicate whether an
6066 overflow occurred during the signed multiplication.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006067
6068<h5>Arguments:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006069<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006070 be of integer types of any bit width, but they must have the same bit
6071 width. The second element of the result structure must be of
6072 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6073 undergo signed multiplication.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006074
6075<h5>Semantics:</h5>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006076<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006077 a signed multiplication of the two arguments. They return a structure &mdash;
6078 the first element of which is the multiplication, and the second element of
6079 which is a bit specifying if the signed multiplication resulted in an
6080 overflow.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006081
6082<h5>Examples:</h5>
6083<pre>
6084 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6085 %sum = extractvalue {i32, i1} %res, 0
6086 %obit = extractvalue {i32, i1} %res, 1
6087 br i1 %obit, label %overflow, label %normal
6088</pre>
6089
Reid Spencer5bf54c82007-04-11 23:23:49 +00006090</div>
6091
Bill Wendlingb9a73272009-02-08 23:00:09 +00006092<!-- _______________________________________________________________________ -->
6093<div class="doc_subsubsection">
6094 <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a>
6095</div>
6096
6097<div class="doc_text">
6098
6099<h5>Syntax:</h5>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006100<p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006101 on any integer bit width.</p>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006102
6103<pre>
6104 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
6105 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6106 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
6107</pre>
6108
6109<h5>Overview:</h5>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006110<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006111 a unsigned multiplication of the two arguments, and indicate whether an
6112 overflow occurred during the unsigned multiplication.</p>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006113
6114<h5>Arguments:</h5>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006115<p>The arguments (%a and %b) and the first element of the result structure may
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006116 be of integer types of any bit width, but they must have the same bit
6117 width. The second element of the result structure must be of
6118 type <tt>i1</tt>. <tt>%a</tt> and <tt>%b</tt> are the two values that will
6119 undergo unsigned multiplication.</p>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006120
6121<h5>Semantics:</h5>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006122<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006123 an unsigned multiplication of the two arguments. They return a structure
6124 &mdash; the first element of which is the multiplication, and the second
6125 element of which is a bit specifying if the unsigned multiplication resulted
6126 in an overflow.</p>
Bill Wendlingb9a73272009-02-08 23:00:09 +00006127
6128<h5>Examples:</h5>
6129<pre>
6130 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6131 %sum = extractvalue {i32, i1} %res, 0
6132 %obit = extractvalue {i32, i1} %res, 1
6133 br i1 %obit, label %overflow, label %normal
6134</pre>
6135
6136</div>
6137
Chris Lattner941515c2004-01-06 05:31:32 +00006138<!-- ======================================================================= -->
6139<div class="doc_subsection">
6140 <a name="int_debugger">Debugger Intrinsics</a>
6141</div>
6142
6143<div class="doc_text">
Chris Lattner941515c2004-01-06 05:31:32 +00006144
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006145<p>The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt>
6146 prefix), are described in
6147 the <a href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source
6148 Level Debugging</a> document.</p>
6149
6150</div>
Chris Lattner941515c2004-01-06 05:31:32 +00006151
Jim Laskey2211f492007-03-14 19:31:19 +00006152<!-- ======================================================================= -->
6153<div class="doc_subsection">
6154 <a name="int_eh">Exception Handling Intrinsics</a>
6155</div>
6156
6157<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006158
6159<p>The LLVM exception handling intrinsics (which all start with
6160 <tt>llvm.eh.</tt> prefix), are described in
6161 the <a href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
6162 Handling</a> document.</p>
6163
Jim Laskey2211f492007-03-14 19:31:19 +00006164</div>
6165
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006166<!-- ======================================================================= -->
6167<div class="doc_subsection">
Duncan Sands86e01192007-09-11 14:10:23 +00006168 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +00006169</div>
6170
6171<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006172
6173<p>This intrinsic makes it possible to excise one parameter, marked with
6174 the <tt>nest</tt> attribute, from a function. The result is a callable
6175 function pointer lacking the nest parameter - the caller does not need to
6176 provide a value for it. Instead, the value to use is stored in advance in a
6177 "trampoline", a block of memory usually allocated on the stack, which also
6178 contains code to splice the nest value into the argument list. This is used
6179 to implement the GCC nested function address extension.</p>
6180
6181<p>For example, if the function is
6182 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
6183 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as
6184 follows:</p>
6185
6186<div class="doc_code">
Duncan Sands644f9172007-07-27 12:58:54 +00006187<pre>
Duncan Sands86e01192007-09-11 14:10:23 +00006188 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
6189 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
6190 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
6191 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands644f9172007-07-27 12:58:54 +00006192</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006193</div>
6194
6195<p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
6196 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
6197
Duncan Sands644f9172007-07-27 12:58:54 +00006198</div>
6199
6200<!-- _______________________________________________________________________ -->
6201<div class="doc_subsubsection">
6202 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
6203</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006204
Duncan Sands644f9172007-07-27 12:58:54 +00006205<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006206
Duncan Sands644f9172007-07-27 12:58:54 +00006207<h5>Syntax:</h5>
6208<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006209 declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands644f9172007-07-27 12:58:54 +00006210</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006211
Duncan Sands644f9172007-07-27 12:58:54 +00006212<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006213<p>This fills the memory pointed to by <tt>tramp</tt> with code and returns a
6214 function pointer suitable for executing it.</p>
6215
Duncan Sands644f9172007-07-27 12:58:54 +00006216<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006217<p>The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
6218 pointers. The <tt>tramp</tt> argument must point to a sufficiently large and
6219 sufficiently aligned block of memory; this memory is written to by the
6220 intrinsic. Note that the size and the alignment are target-specific - LLVM
6221 currently provides no portable way of determining them, so a front-end that
6222 generates this intrinsic needs to have some target-specific knowledge.
6223 The <tt>func</tt> argument must hold a function bitcast to
6224 an <tt>i8*</tt>.</p>
6225
Duncan Sands644f9172007-07-27 12:58:54 +00006226<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006227<p>The block of memory pointed to by <tt>tramp</tt> is filled with target
6228 dependent code, turning it into a function. A pointer to this function is
6229 returned, but needs to be bitcast to an <a href="#int_trampoline">appropriate
6230 function pointer type</a> before being called. The new function's signature
6231 is the same as that of <tt>func</tt> with any arguments marked with
6232 the <tt>nest</tt> attribute removed. At most one such <tt>nest</tt> argument
6233 is allowed, and it must be of pointer type. Calling the new function is
6234 equivalent to calling <tt>func</tt> with the same argument list, but
6235 with <tt>nval</tt> used for the missing <tt>nest</tt> argument. If, after
6236 calling <tt>llvm.init.trampoline</tt>, the memory pointed to
6237 by <tt>tramp</tt> is modified, then the effect of any later call to the
6238 returned function pointer is undefined.</p>
6239
Duncan Sands644f9172007-07-27 12:58:54 +00006240</div>
6241
6242<!-- ======================================================================= -->
6243<div class="doc_subsection">
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006244 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
6245</div>
6246
6247<div class="doc_text">
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006248
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006249<p>These intrinsic functions expand the "universal IR" of LLVM to represent
6250 hardware constructs for atomic operations and memory synchronization. This
6251 provides an interface to the hardware, not an interface to the programmer. It
6252 is aimed at a low enough level to allow any programming models or APIs
6253 (Application Programming Interfaces) which need atomic behaviors to map
6254 cleanly onto it. It is also modeled primarily on hardware behavior. Just as
6255 hardware provides a "universal IR" for source languages, it also provides a
6256 starting point for developing a "universal" atomic operation and
6257 synchronization IR.</p>
6258
6259<p>These do <em>not</em> form an API such as high-level threading libraries,
6260 software transaction memory systems, atomic primitives, and intrinsic
6261 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
6262 application libraries. The hardware interface provided by LLVM should allow
6263 a clean implementation of all of these APIs and parallel programming models.
6264 No one model or paradigm should be selected above others unless the hardware
6265 itself ubiquitously does so.</p>
6266
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006267</div>
6268
6269<!-- _______________________________________________________________________ -->
6270<div class="doc_subsubsection">
6271 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
6272</div>
6273<div class="doc_text">
6274<h5>Syntax:</h5>
6275<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006276 declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;, i1 &lt;device&gt; )
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006277</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006278
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006279<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006280<p>The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
6281 specific pairs of memory access types.</p>
6282
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006283<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006284<p>The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
6285 The first four arguments enables a specific barrier as listed below. The
6286 fith argument specifies that the barrier applies to io or device or uncached
6287 memory.</p>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006288
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006289<ul>
6290 <li><tt>ll</tt>: load-load barrier</li>
6291 <li><tt>ls</tt>: load-store barrier</li>
6292 <li><tt>sl</tt>: store-load barrier</li>
6293 <li><tt>ss</tt>: store-store barrier</li>
6294 <li><tt>device</tt>: barrier applies to device and uncached memory also.</li>
6295</ul>
6296
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006297<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006298<p>This intrinsic causes the system to enforce some ordering constraints upon
6299 the loads and stores of the program. This barrier does not
6300 indicate <em>when</em> any events will occur, it only enforces
6301 an <em>order</em> in which they occur. For any of the specified pairs of load
6302 and store operations (f.ex. load-load, or store-load), all of the first
6303 operations preceding the barrier will complete before any of the second
6304 operations succeeding the barrier begin. Specifically the semantics for each
6305 pairing is as follows:</p>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006306
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006307<ul>
6308 <li><tt>ll</tt>: All loads before the barrier must complete before any load
6309 after the barrier begins.</li>
6310 <li><tt>ls</tt>: All loads before the barrier must complete before any
6311 store after the barrier begins.</li>
6312 <li><tt>ss</tt>: All stores before the barrier must complete before any
6313 store after the barrier begins.</li>
6314 <li><tt>sl</tt>: All stores before the barrier must complete before any
6315 load after the barrier begins.</li>
6316</ul>
6317
6318<p>These semantics are applied with a logical "and" behavior when more than one
6319 is enabled in a single memory barrier intrinsic.</p>
6320
6321<p>Backends may implement stronger barriers than those requested when they do
6322 not support as fine grained a barrier as requested. Some architectures do
6323 not need all types of barriers and on such architectures, these become
6324 noops.</p>
6325
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006326<h5>Example:</h5>
6327<pre>
6328%ptr = malloc i32
6329 store i32 4, %ptr
6330
6331%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
6332 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
6333 <i>; guarantee the above finishes</i>
6334 store i32 8, %ptr <i>; before this begins</i>
6335</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006336
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006337</div>
6338
Andrew Lenharth95528942008-02-21 06:45:13 +00006339<!-- _______________________________________________________________________ -->
6340<div class="doc_subsubsection">
Mon P Wang6a490372008-06-25 08:15:39 +00006341 <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a>
Andrew Lenharth95528942008-02-21 06:45:13 +00006342</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006343
Andrew Lenharth95528942008-02-21 06:45:13 +00006344<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006345
Andrew Lenharth95528942008-02-21 06:45:13 +00006346<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006347<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on
6348 any integer bit width and for different address spaces. Not all targets
6349 support all bit widths however.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006350
6351<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006352 declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
6353 declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
6354 declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
6355 declare i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;cmp&gt;, i64 &lt;val&gt; )
Andrew Lenharth95528942008-02-21 06:45:13 +00006356</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006357
Andrew Lenharth95528942008-02-21 06:45:13 +00006358<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006359<p>This loads a value in memory and compares it to a given value. If they are
6360 equal, it stores a new value into the memory.</p>
6361
Andrew Lenharth95528942008-02-21 06:45:13 +00006362<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006363<p>The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result
6364 as well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
6365 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
6366 this integer type. While any bit width integer may be used, targets may only
6367 lower representations they support in hardware.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006368
Andrew Lenharth95528942008-02-21 06:45:13 +00006369<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006370<p>This entire intrinsic must be executed atomically. It first loads the value
6371 in memory pointed to by <tt>ptr</tt> and compares it with the
6372 value <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the
6373 memory. The loaded value is yielded in all cases. This provides the
6374 equivalent of an atomic compare-and-swap operation within the SSA
6375 framework.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006376
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006377<h5>Examples:</h5>
Andrew Lenharth95528942008-02-21 06:45:13 +00006378<pre>
6379%ptr = malloc i32
6380 store i32 4, %ptr
6381
6382%val1 = add i32 4, 4
Mon P Wang2c839d42008-07-30 04:36:53 +00006383%result1 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006384 <i>; yields {i32}:result1 = 4</i>
6385%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6386%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6387
6388%val2 = add i32 1, 1
Mon P Wang2c839d42008-07-30 04:36:53 +00006389%result2 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006390 <i>; yields {i32}:result2 = 8</i>
6391%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
6392
6393%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
6394</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006395
Andrew Lenharth95528942008-02-21 06:45:13 +00006396</div>
6397
6398<!-- _______________________________________________________________________ -->
6399<div class="doc_subsubsection">
6400 <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
6401</div>
6402<div class="doc_text">
6403<h5>Syntax:</h5>
6404
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006405<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
6406 integer bit width. Not all targets support all bit widths however.</p>
6407
Andrew Lenharth95528942008-02-21 06:45:13 +00006408<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006409 declare i8 @llvm.atomic.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
6410 declare i16 @llvm.atomic.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
6411 declare i32 @llvm.atomic.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
6412 declare i64 @llvm.atomic.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
Andrew Lenharth95528942008-02-21 06:45:13 +00006413</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006414
Andrew Lenharth95528942008-02-21 06:45:13 +00006415<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006416<p>This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
6417 the value from memory. It then stores the value in <tt>val</tt> in the memory
6418 at <tt>ptr</tt>.</p>
6419
Andrew Lenharth95528942008-02-21 06:45:13 +00006420<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006421<p>The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both
6422 the <tt>val</tt> argument and the result must be integers of the same bit
6423 width. The first argument, <tt>ptr</tt>, must be a pointer to a value of this
6424 integer type. The targets may only lower integer representations they
6425 support.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006426
Andrew Lenharth95528942008-02-21 06:45:13 +00006427<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006428<p>This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
6429 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
6430 equivalent of an atomic swap operation within the SSA framework.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006431
Andrew Lenharth95528942008-02-21 06:45:13 +00006432<h5>Examples:</h5>
6433<pre>
6434%ptr = malloc i32
6435 store i32 4, %ptr
6436
6437%val1 = add i32 4, 4
Mon P Wang2c839d42008-07-30 04:36:53 +00006438%result1 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006439 <i>; yields {i32}:result1 = 4</i>
6440%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6441%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6442
6443%val2 = add i32 1, 1
Mon P Wang2c839d42008-07-30 04:36:53 +00006444%result2 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006445 <i>; yields {i32}:result2 = 8</i>
6446
6447%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
6448%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
6449</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006450
Andrew Lenharth95528942008-02-21 06:45:13 +00006451</div>
6452
6453<!-- _______________________________________________________________________ -->
6454<div class="doc_subsubsection">
Mon P Wang6a490372008-06-25 08:15:39 +00006455 <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a>
Andrew Lenharth95528942008-02-21 06:45:13 +00006456
6457</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006458
Andrew Lenharth95528942008-02-21 06:45:13 +00006459<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006460
Andrew Lenharth95528942008-02-21 06:45:13 +00006461<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006462<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on
6463 any integer bit width. Not all targets support all bit widths however.</p>
6464
Andrew Lenharth95528942008-02-21 06:45:13 +00006465<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006466 declare i8 @llvm.atomic.load.add.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6467 declare i16 @llvm.atomic.load.add.i16..p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6468 declare i32 @llvm.atomic.load.add.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6469 declare i64 @llvm.atomic.load.add.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Andrew Lenharth95528942008-02-21 06:45:13 +00006470</pre>
Andrew Lenharth95528942008-02-21 06:45:13 +00006471
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006472<h5>Overview:</h5>
6473<p>This intrinsic adds <tt>delta</tt> to the value stored in memory
6474 at <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6475
6476<h5>Arguments:</h5>
6477<p>The intrinsic takes two arguments, the first a pointer to an integer value
6478 and the second an integer value. The result is also an integer value. These
6479 integer types can have any bit width, but they must all have the same bit
6480 width. The targets may only lower integer representations they support.</p>
6481
Andrew Lenharth95528942008-02-21 06:45:13 +00006482<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006483<p>This intrinsic does a series of operations atomically. It first loads the
6484 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
6485 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006486
6487<h5>Examples:</h5>
6488<pre>
6489%ptr = malloc i32
6490 store i32 4, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006491%result1 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006492 <i>; yields {i32}:result1 = 4</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006493%result2 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006494 <i>; yields {i32}:result2 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006495%result3 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006496 <i>; yields {i32}:result3 = 10</i>
Mon P Wang6a490372008-06-25 08:15:39 +00006497%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
Andrew Lenharth95528942008-02-21 06:45:13 +00006498</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006499
Andrew Lenharth95528942008-02-21 06:45:13 +00006500</div>
6501
Mon P Wang6a490372008-06-25 08:15:39 +00006502<!-- _______________________________________________________________________ -->
6503<div class="doc_subsubsection">
6504 <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a>
6505
6506</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006507
Mon P Wang6a490372008-06-25 08:15:39 +00006508<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006509
Mon P Wang6a490372008-06-25 08:15:39 +00006510<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006511<p>This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on
6512 any integer bit width and for different address spaces. Not all targets
6513 support all bit widths however.</p>
6514
Mon P Wang6a490372008-06-25 08:15:39 +00006515<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006516 declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6517 declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6518 declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6519 declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006520</pre>
Mon P Wang6a490372008-06-25 08:15:39 +00006521
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006522<h5>Overview:</h5>
6523<p>This intrinsic subtracts <tt>delta</tt> to the value stored in memory at
6524 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.</p>
6525
6526<h5>Arguments:</h5>
6527<p>The intrinsic takes two arguments, the first a pointer to an integer value
6528 and the second an integer value. The result is also an integer value. These
6529 integer types can have any bit width, but they must all have the same bit
6530 width. The targets may only lower integer representations they support.</p>
6531
Mon P Wang6a490372008-06-25 08:15:39 +00006532<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006533<p>This intrinsic does a series of operations atomically. It first loads the
6534 value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the
6535 result to <tt>ptr</tt>. It yields the original value stored
6536 at <tt>ptr</tt>.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006537
6538<h5>Examples:</h5>
6539<pre>
6540%ptr = malloc i32
6541 store i32 8, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006542%result1 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
Mon P Wang6a490372008-06-25 08:15:39 +00006543 <i>; yields {i32}:result1 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006544%result2 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
Mon P Wang6a490372008-06-25 08:15:39 +00006545 <i>; yields {i32}:result2 = 4</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006546%result3 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 )
Mon P Wang6a490372008-06-25 08:15:39 +00006547 <i>; yields {i32}:result3 = 2</i>
6548%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = -3</i>
6549</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006550
Mon P Wang6a490372008-06-25 08:15:39 +00006551</div>
6552
6553<!-- _______________________________________________________________________ -->
6554<div class="doc_subsubsection">
6555 <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br>
6556 <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br>
6557 <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br>
6558 <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br>
Mon P Wang6a490372008-06-25 08:15:39 +00006559</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006560
Mon P Wang6a490372008-06-25 08:15:39 +00006561<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006562
Mon P Wang6a490372008-06-25 08:15:39 +00006563<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006564<p>These are overloaded intrinsics. You can
6565 use <tt>llvm.atomic.load_and</tt>, <tt>llvm.atomic.load_nand</tt>,
6566 <tt>llvm.atomic.load_or</tt>, and <tt>llvm.atomic.load_xor</tt> on any integer
6567 bit width and for different address spaces. Not all targets support all bit
6568 widths however.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006569
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006570<pre>
6571 declare i8 @llvm.atomic.load.and.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6572 declare i16 @llvm.atomic.load.and.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6573 declare i32 @llvm.atomic.load.and.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6574 declare i64 @llvm.atomic.load.and.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006575</pre>
6576
6577<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006578 declare i8 @llvm.atomic.load.or.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6579 declare i16 @llvm.atomic.load.or.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6580 declare i32 @llvm.atomic.load.or.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6581 declare i64 @llvm.atomic.load.or.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006582</pre>
6583
6584<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006585 declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6586 declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6587 declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6588 declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006589</pre>
6590
6591<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006592 declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6593 declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6594 declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6595 declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006596</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006597
Mon P Wang6a490372008-06-25 08:15:39 +00006598<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006599<p>These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to
6600 the value stored in memory at <tt>ptr</tt>. It yields the original value
6601 at <tt>ptr</tt>.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006602
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006603<h5>Arguments:</h5>
6604<p>These intrinsics take two arguments, the first a pointer to an integer value
6605 and the second an integer value. The result is also an integer value. These
6606 integer types can have any bit width, but they must all have the same bit
6607 width. The targets may only lower integer representations they support.</p>
6608
Mon P Wang6a490372008-06-25 08:15:39 +00006609<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006610<p>These intrinsics does a series of operations atomically. They first load the
6611 value stored at <tt>ptr</tt>. They then do the bitwise
6612 operation <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the
6613 original value stored at <tt>ptr</tt>.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006614
6615<h5>Examples:</h5>
6616<pre>
6617%ptr = malloc i32
6618 store i32 0x0F0F, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006619%result0 = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6a490372008-06-25 08:15:39 +00006620 <i>; yields {i32}:result0 = 0x0F0F</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006621%result1 = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6a490372008-06-25 08:15:39 +00006622 <i>; yields {i32}:result1 = 0xFFFFFFF0</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006623%result2 = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6a490372008-06-25 08:15:39 +00006624 <i>; yields {i32}:result2 = 0xF0</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006625%result3 = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6a490372008-06-25 08:15:39 +00006626 <i>; yields {i32}:result3 = FF</i>
6627%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = F0</i>
6628</pre>
Mon P Wang6a490372008-06-25 08:15:39 +00006629
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006630</div>
Mon P Wang6a490372008-06-25 08:15:39 +00006631
6632<!-- _______________________________________________________________________ -->
6633<div class="doc_subsubsection">
6634 <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br>
6635 <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br>
6636 <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br>
6637 <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br>
Mon P Wang6a490372008-06-25 08:15:39 +00006638</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006639
Mon P Wang6a490372008-06-25 08:15:39 +00006640<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006641
Mon P Wang6a490372008-06-25 08:15:39 +00006642<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006643<p>These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>,
6644 <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and
6645 <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different
6646 address spaces. Not all targets support all bit widths however.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006647
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006648<pre>
6649 declare i8 @llvm.atomic.load.max.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6650 declare i16 @llvm.atomic.load.max.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6651 declare i32 @llvm.atomic.load.max.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6652 declare i64 @llvm.atomic.load.max.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006653</pre>
6654
6655<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006656 declare i8 @llvm.atomic.load.min.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6657 declare i16 @llvm.atomic.load.min.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6658 declare i32 @llvm.atomic.load.min.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6659 declare i64 @llvm.atomic.load.min.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006660</pre>
6661
6662<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006663 declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6664 declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6665 declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6666 declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006667</pre>
6668
6669<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006670 declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6671 declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6672 declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6673 declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006674</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006675
Mon P Wang6a490372008-06-25 08:15:39 +00006676<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006677<p>These intrinsics takes the signed or unsigned minimum or maximum of
6678 <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the
6679 original value at <tt>ptr</tt>.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006680
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006681<h5>Arguments:</h5>
6682<p>These intrinsics take two arguments, the first a pointer to an integer value
6683 and the second an integer value. The result is also an integer value. These
6684 integer types can have any bit width, but they must all have the same bit
6685 width. The targets may only lower integer representations they support.</p>
6686
Mon P Wang6a490372008-06-25 08:15:39 +00006687<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006688<p>These intrinsics does a series of operations atomically. They first load the
6689 value stored at <tt>ptr</tt>. They then do the signed or unsigned min or
6690 max <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They
6691 yield the original value stored at <tt>ptr</tt>.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006692
6693<h5>Examples:</h5>
6694<pre>
6695%ptr = malloc i32
6696 store i32 7, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006697%result0 = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
Mon P Wang6a490372008-06-25 08:15:39 +00006698 <i>; yields {i32}:result0 = 7</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006699%result1 = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )
Mon P Wang6a490372008-06-25 08:15:39 +00006700 <i>; yields {i32}:result1 = -2</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006701%result2 = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 )
Mon P Wang6a490372008-06-25 08:15:39 +00006702 <i>; yields {i32}:result2 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006703%result3 = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 )
Mon P Wang6a490372008-06-25 08:15:39 +00006704 <i>; yields {i32}:result3 = 8</i>
6705%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 30</i>
6706</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006707
Mon P Wang6a490372008-06-25 08:15:39 +00006708</div>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006709
6710<!-- ======================================================================= -->
6711<div class="doc_subsection">
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006712 <a name="int_general">General Intrinsics</a>
6713</div>
6714
6715<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006716
6717<p>This class of intrinsics is designed to be generic and has no specific
6718 purpose.</p>
6719
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006720</div>
6721
6722<!-- _______________________________________________________________________ -->
6723<div class="doc_subsubsection">
6724 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
6725</div>
6726
6727<div class="doc_text">
6728
6729<h5>Syntax:</h5>
6730<pre>
Tanya Lattnerbed1d4d2007-06-18 23:42:37 +00006731 declare void @llvm.var.annotation(i8* &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006732</pre>
6733
6734<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006735<p>The '<tt>llvm.var.annotation</tt>' intrinsic.</p>
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006736
6737<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006738<p>The first argument is a pointer to a value, the second is a pointer to a
6739 global string, the third is a pointer to a global string which is the source
6740 file name, and the last argument is the line number.</p>
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006741
6742<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006743<p>This intrinsic allows annotation of local variables with arbitrary strings.
6744 This can be useful for special purpose optimizations that want to look for
6745 these annotations. These have no other defined use, they are ignored by code
6746 generation and optimization.</p>
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006747
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006748</div>
6749
Tanya Lattner293c0372007-09-21 22:59:12 +00006750<!-- _______________________________________________________________________ -->
6751<div class="doc_subsubsection">
Tanya Lattner0186a652007-09-21 23:57:59 +00006752 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattner293c0372007-09-21 22:59:12 +00006753</div>
6754
6755<div class="doc_text">
6756
6757<h5>Syntax:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006758<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
6759 any integer bit width.</p>
6760
Tanya Lattner293c0372007-09-21 22:59:12 +00006761<pre>
Tanya Lattnercf3e26f2007-09-22 00:03:01 +00006762 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6763 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6764 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6765 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6766 declare i256 @llvm.annotation.i256(i256 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
Tanya Lattner293c0372007-09-21 22:59:12 +00006767</pre>
6768
6769<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006770<p>The '<tt>llvm.annotation</tt>' intrinsic.</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00006771
6772<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006773<p>The first argument is an integer value (result of some expression), the
6774 second is a pointer to a global string, the third is a pointer to a global
6775 string which is the source file name, and the last argument is the line
6776 number. It returns the value of the first argument.</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00006777
6778<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006779<p>This intrinsic allows annotations to be put on arbitrary expressions with
6780 arbitrary strings. This can be useful for special purpose optimizations that
6781 want to look for these annotations. These have no other defined use, they
6782 are ignored by code generation and optimization.</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00006783
Tanya Lattner293c0372007-09-21 22:59:12 +00006784</div>
Jim Laskey2211f492007-03-14 19:31:19 +00006785
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006786<!-- _______________________________________________________________________ -->
6787<div class="doc_subsubsection">
6788 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
6789</div>
6790
6791<div class="doc_text">
6792
6793<h5>Syntax:</h5>
6794<pre>
6795 declare void @llvm.trap()
6796</pre>
6797
6798<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006799<p>The '<tt>llvm.trap</tt>' intrinsic.</p>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006800
6801<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006802<p>None.</p>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006803
6804<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006805<p>This intrinsics is lowered to the target dependent trap instruction. If the
6806 target does not have a trap instruction, this intrinsic will be lowered to
6807 the call of the <tt>abort()</tt> function.</p>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006808
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006809</div>
6810
Bill Wendling14313312008-11-19 05:56:17 +00006811<!-- _______________________________________________________________________ -->
6812<div class="doc_subsubsection">
Misha Brukman50de2b22008-11-22 23:55:29 +00006813 <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
Bill Wendling14313312008-11-19 05:56:17 +00006814</div>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006815
Bill Wendling14313312008-11-19 05:56:17 +00006816<div class="doc_text">
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006817
Bill Wendling14313312008-11-19 05:56:17 +00006818<h5>Syntax:</h5>
6819<pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006820 declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
Bill Wendling14313312008-11-19 05:56:17 +00006821</pre>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006822
Bill Wendling14313312008-11-19 05:56:17 +00006823<h5>Overview:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006824<p>The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and
6825 stores it onto the stack at <tt>slot</tt>. The stack slot is adjusted to
6826 ensure that it is placed on the stack before local variables.</p>
6827
Bill Wendling14313312008-11-19 05:56:17 +00006828<h5>Arguments:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006829<p>The <tt>llvm.stackprotector</tt> intrinsic requires two pointer
6830 arguments. The first argument is the value loaded from the stack
6831 guard <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt>
6832 that has enough space to hold the value of the guard.</p>
6833
Bill Wendling14313312008-11-19 05:56:17 +00006834<h5>Semantics:</h5>
Bill Wendlingd9a66f72009-07-20 02:29:24 +00006835<p>This intrinsic causes the prologue/epilogue inserter to force the position of
6836 the <tt>AllocaInst</tt> stack slot to be before local variables on the
6837 stack. This is to ensure that if a local variable on the stack is
6838 overwritten, it will destroy the value of the guard. When the function exits,
6839 the guard on the stack is checked against the original guard. If they're
6840 different, then the program aborts by calling the <tt>__stack_chk_fail()</tt>
6841 function.</p>
6842
Bill Wendling14313312008-11-19 05:56:17 +00006843</div>
6844
Chris Lattner2f7c9632001-06-06 20:29:01 +00006845<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00006846<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00006847<address>
6848 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00006849 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmanc501f552004-03-01 17:47:27 +00006850 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00006851 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Misha Brukmanc501f552004-03-01 17:47:27 +00006852
6853 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00006854 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00006855 Last modified: $Date$
6856</address>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00006857
Misha Brukman76307852003-11-08 01:05:38 +00006858</body>
6859</html>