blob: 4fb712ee3bba7d24bccd1dee5d1a32f611d4204c [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>
25 <li><a href="#linkage_private">private</a></li>
26 <li><a href="#linkage_linker_private">linker_private</a></li>
27 <li><a href="#linkage_internal">internal</a></li>
28 <li><a href="#linkage_available_externally">available_externally</a></li>
29 <li><a href="#linkage_linkonce">linkonce</a></li>
30 <li><a href="#linkage_common">common</a></li>
31 <li><a href="#linkage_weak">weak</a></li>
32 <li><a href="#linkage_appending">appending</a></li>
33 <li><a href="#linkage_externweak">extern_weak</a></li>
34 <li><a href="#linkage_linkonce">linkonce_odr</a></li>
35 <li><a href="#linkage_weak">weak_odr</a></li>
36 <li><a href="#linkage_external">externally visible</a></li>
37 <li><a href="#linkage_dllimport">dllimport</a></li>
38 <li><a href="#linkage_dllexport">dllexport</a></li>
39 </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 Lattner2f7c9632001-06-06 20:29:01 +000094 <li><a href="#instref">Instruction Reference</a>
95 <ol>
96 <li><a href="#terminators">Terminator Instructions</a>
97 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000098 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
99 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000100 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
101 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000102 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +0000103 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000104 </ol>
105 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000106 <li><a href="#binaryops">Binary Operations</a>
107 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000108 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000109 <li><a href="#i_fadd">'<tt>fadd</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000110 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000111 <li><a href="#i_fsub">'<tt>fsub</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000112 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Dan Gohmana5b96452009-06-04 22:49:04 +0000113 <li><a href="#i_fmul">'<tt>fmul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +0000114 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
115 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
116 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +0000117 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
118 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
119 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000120 </ol>
121 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000122 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
123 <ol>
Reid Spencer2ab01932007-02-02 13:57:07 +0000124 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
125 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
126 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000127 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000128 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000129 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000130 </ol>
131 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000132 <li><a href="#vectorops">Vector Operations</a>
133 <ol>
134 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
135 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
136 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000137 </ol>
138 </li>
Dan Gohmanb9d66602008-05-12 23:51:09 +0000139 <li><a href="#aggregateops">Aggregate Operations</a>
140 <ol>
141 <li><a href="#i_extractvalue">'<tt>extractvalue</tt>' Instruction</a></li>
142 <li><a href="#i_insertvalue">'<tt>insertvalue</tt>' Instruction</a></li>
143 </ol>
144 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000145 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000146 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000147 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
148 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
149 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000150 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
151 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
152 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000153 </ol>
154 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000155 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000156 <ol>
157 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
158 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
159 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
160 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
161 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000162 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
163 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
164 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
165 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000166 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
167 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000168 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000169 </ol>
Dan Gohmanef9462f2008-10-14 16:51:45 +0000170 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000171 <li><a href="#otherops">Other Operations</a>
172 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000173 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
174 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000175 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000176 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000177 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000178 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000179 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000180 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000181 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000182 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000183 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000184 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000185 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
186 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000187 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
188 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
189 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000190 </ol>
191 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000192 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
193 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000194 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
195 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
196 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000197 </ol>
198 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000199 <li><a href="#int_codegen">Code Generator Intrinsics</a>
200 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000201 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
202 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
203 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
204 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
205 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
206 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
207 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000208 </ol>
209 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000210 <li><a href="#int_libc">Standard C Library Intrinsics</a>
211 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000212 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
213 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
214 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
215 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
216 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Dan Gohmanb6324c12007-10-15 20:30:11 +0000217 <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li>
218 <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li>
219 <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000220 </ol>
221 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000222 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000223 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000224 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000225 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
226 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
227 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000228 </ol>
229 </li>
Bill Wendlingf4d70622009-02-08 01:40:31 +0000230 <li><a href="#int_overflow">Arithmetic with Overflow Intrinsics</a>
231 <ol>
Bill Wendlingfd2bd722009-02-08 04:04:40 +0000232 <li><a href="#int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt> Intrinsics</a></li>
233 <li><a href="#int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt> Intrinsics</a></li>
234 <li><a href="#int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt> Intrinsics</a></li>
235 <li><a href="#int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt> Intrinsics</a></li>
236 <li><a href="#int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendlingb9a73272009-02-08 23:00:09 +0000237 <li><a href="#int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt> Intrinsics</a></li>
Bill Wendlingf4d70622009-02-08 01:40:31 +0000238 </ol>
239 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000240 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskey2211f492007-03-14 19:31:19 +0000241 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Duncan Sands86e01192007-09-11 14:10:23 +0000242 <li><a href="#int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +0000243 <ol>
244 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
Duncan Sands644f9172007-07-27 12:58:54 +0000245 </ol>
246 </li>
Bill Wendlingf85850f2008-11-18 22:10:53 +0000247 <li><a href="#int_atomics">Atomic intrinsics</a>
248 <ol>
249 <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
250 <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li>
251 <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
252 <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li>
253 <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li>
254 <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li>
255 <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li>
256 <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li>
257 <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li>
258 <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li>
259 <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li>
260 <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li>
261 <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li>
262 </ol>
263 </li>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000264 <li><a href="#int_general">General intrinsics</a>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000265 <ol>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000266 <li><a href="#int_var_annotation">
Bill Wendling14313312008-11-19 05:56:17 +0000267 '<tt>llvm.var.annotation</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000268 <li><a href="#int_annotation">
Bill Wendling14313312008-11-19 05:56:17 +0000269 '<tt>llvm.annotation.*</tt>' Intrinsic</a></li>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +0000270 <li><a href="#int_trap">
Bill Wendling14313312008-11-19 05:56:17 +0000271 '<tt>llvm.trap</tt>' Intrinsic</a></li>
272 <li><a href="#int_stackprotector">
273 '<tt>llvm.stackprotector</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000274 </ol>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000275 </li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000276 </ol>
277 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000278</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000279
280<div class="doc_author">
281 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
282 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000283</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000284
Chris Lattner2f7c9632001-06-06 20:29:01 +0000285<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000286<div class="doc_section"> <a name="abstract">Abstract </a></div>
287<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000288
Misha Brukman76307852003-11-08 01:05:38 +0000289<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000290<p>This document is a reference manual for the LLVM assembly language.
Bill Wendling6e03f9a2008-08-05 22:29:16 +0000291LLVM is a Static Single Assignment (SSA) based representation that provides
Chris Lattner67c37d12008-08-05 18:29:16 +0000292type safety, low-level operations, flexibility, and the capability of
293representing 'all' high-level languages cleanly. It is the common code
Chris Lattner48b383b02003-11-25 01:02:51 +0000294representation used throughout all phases of the LLVM compilation
295strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000296</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000297
Chris Lattner2f7c9632001-06-06 20:29:01 +0000298<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000299<div class="doc_section"> <a name="introduction">Introduction</a> </div>
300<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000301
Misha Brukman76307852003-11-08 01:05:38 +0000302<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000303
Chris Lattner48b383b02003-11-25 01:02:51 +0000304<p>The LLVM code representation is designed to be used in three
Gabor Greifa54634a2007-07-06 22:07:22 +0000305different forms: as an in-memory compiler IR, as an on-disk bitcode
Chris Lattner48b383b02003-11-25 01:02:51 +0000306representation (suitable for fast loading by a Just-In-Time compiler),
307and as a human readable assembly language representation. This allows
308LLVM to provide a powerful intermediate representation for efficient
309compiler transformations and analysis, while providing a natural means
310to debug and visualize the transformations. The three different forms
311of LLVM are all equivalent. This document describes the human readable
312representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000313
John Criswell4a3327e2005-05-13 22:25:59 +0000314<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000315while being expressive, typed, and extensible at the same time. It
316aims to be a "universal IR" of sorts, by being at a low enough level
317that high-level ideas may be cleanly mapped to it (similar to how
318microprocessors are "universal IR's", allowing many source languages to
319be mapped to them). By providing type information, LLVM can be used as
320the target of optimizations: for example, through pointer analysis, it
321can be proven that a C automatic variable is never accessed outside of
322the current function... allowing it to be promoted to a simple SSA
323value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000324
Misha Brukman76307852003-11-08 01:05:38 +0000325</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000326
Chris Lattner2f7c9632001-06-06 20:29:01 +0000327<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000328<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000329
Misha Brukman76307852003-11-08 01:05:38 +0000330<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000331
Chris Lattner48b383b02003-11-25 01:02:51 +0000332<p>It is important to note that this document describes 'well formed'
333LLVM assembly language. There is a difference between what the parser
334accepts and what is considered 'well formed'. For example, the
335following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000336
Bill Wendling3716c5d2007-05-29 09:04:49 +0000337<div class="doc_code">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000338<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000339%x = <a href="#i_add">add</a> i32 1, %x
Chris Lattner757528b0b2004-05-23 21:06:01 +0000340</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000341</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000342
Chris Lattner48b383b02003-11-25 01:02:51 +0000343<p>...because the definition of <tt>%x</tt> does not dominate all of
344its uses. The LLVM infrastructure provides a verification pass that may
345be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000346automatically run by the parser after parsing input assembly and by
Gabor Greifa54634a2007-07-06 22:07:22 +0000347the optimizer before it outputs bitcode. The violations pointed out
Chris Lattner48b383b02003-11-25 01:02:51 +0000348by the verifier pass indicate bugs in transformation passes or input to
349the parser.</p>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000350</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000351
Chris Lattner87a3dbe2007-10-03 17:34:29 +0000352<!-- Describe the typesetting conventions here. -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000353
Chris Lattner2f7c9632001-06-06 20:29:01 +0000354<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000355<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000356<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000357
Misha Brukman76307852003-11-08 01:05:38 +0000358<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000359
Reid Spencerb23b65f2007-08-07 14:34:28 +0000360 <p>LLVM identifiers come in two basic types: global and local. Global
361 identifiers (functions, global variables) begin with the @ character. Local
362 identifiers (register names, types) begin with the % character. Additionally,
Dan Gohmanef9462f2008-10-14 16:51:45 +0000363 there are three different formats for identifiers, for different purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000364
Chris Lattner2f7c9632001-06-06 20:29:01 +0000365<ol>
Reid Spencerb23b65f2007-08-07 14:34:28 +0000366 <li>Named values are represented as a string of characters with their prefix.
367 For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual
368 regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
Chris Lattnerd79749a2004-12-09 16:36:40 +0000369 Identifiers which require other characters in their names can be surrounded
Daniel Dunbar0f8155a2008-10-14 23:51:43 +0000370 with quotes. Special characters may be escaped using "\xx" where xx is the
371 ASCII code for the character in hexadecimal. In this way, any character can
372 be used in a name value, even quotes themselves.
Chris Lattnerd79749a2004-12-09 16:36:40 +0000373
Reid Spencerb23b65f2007-08-07 14:34:28 +0000374 <li>Unnamed values are represented as an unsigned numeric value with their
375 prefix. For example, %12, @2, %44.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000376
Reid Spencer8f08d802004-12-09 18:02:53 +0000377 <li>Constants, which are described in a <a href="#constants">section about
378 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000379</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000380
Reid Spencerb23b65f2007-08-07 14:34:28 +0000381<p>LLVM requires that values start with a prefix for two reasons: Compilers
Chris Lattnerd79749a2004-12-09 16:36:40 +0000382don't need to worry about name clashes with reserved words, and the set of
383reserved words may be expanded in the future without penalty. Additionally,
384unnamed identifiers allow a compiler to quickly come up with a temporary
385variable without having to avoid symbol table conflicts.</p>
386
Chris Lattner48b383b02003-11-25 01:02:51 +0000387<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5b950642006-11-11 23:08:07 +0000388languages. There are keywords for different opcodes
389('<tt><a href="#i_add">add</a></tt>',
390 '<tt><a href="#i_bitcast">bitcast</a></tt>',
391 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000392href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnerd79749a2004-12-09 16:36:40 +0000393and others. These reserved words cannot conflict with variable names, because
Reid Spencerb23b65f2007-08-07 14:34:28 +0000394none of them start with a prefix character ('%' or '@').</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000395
396<p>Here is an example of LLVM code to multiply the integer variable
397'<tt>%X</tt>' by 8:</p>
398
Misha Brukman76307852003-11-08 01:05:38 +0000399<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000400
Bill Wendling3716c5d2007-05-29 09:04:49 +0000401<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000402<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000403%result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnerd79749a2004-12-09 16:36:40 +0000404</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000405</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000406
Misha Brukman76307852003-11-08 01:05:38 +0000407<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000408
Bill Wendling3716c5d2007-05-29 09:04:49 +0000409<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000410<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000411%result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnerd79749a2004-12-09 16:36:40 +0000412</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000413</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000414
Misha Brukman76307852003-11-08 01:05:38 +0000415<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000416
Bill Wendling3716c5d2007-05-29 09:04:49 +0000417<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000418<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000419<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
420<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
421%result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnerd79749a2004-12-09 16:36:40 +0000422</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000423</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000424
Chris Lattner48b383b02003-11-25 01:02:51 +0000425<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
426important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000427
Chris Lattner2f7c9632001-06-06 20:29:01 +0000428<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000429
430 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
431 line.</li>
432
433 <li>Unnamed temporaries are created when the result of a computation is not
434 assigned to a named value.</li>
435
Misha Brukman76307852003-11-08 01:05:38 +0000436 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000437
Misha Brukman76307852003-11-08 01:05:38 +0000438</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000439
John Criswell02fdc6f2005-05-12 16:52:32 +0000440<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000441demonstrating instructions, we will follow an instruction with a comment that
442defines the type and name of value produced. Comments are shown in italic
443text.</p>
444
Misha Brukman76307852003-11-08 01:05:38 +0000445</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000446
447<!-- *********************************************************************** -->
448<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
449<!-- *********************************************************************** -->
450
451<!-- ======================================================================= -->
452<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
453</div>
454
455<div class="doc_text">
456
457<p>LLVM programs are composed of "Module"s, each of which is a
458translation unit of the input programs. Each module consists of
459functions, global variables, and symbol table entries. Modules may be
460combined together with the LLVM linker, which merges function (and
461global variable) definitions, resolves forward declarations, and merges
462symbol table entries. Here is an example of the "hello world" module:</p>
463
Bill Wendling3716c5d2007-05-29 09:04:49 +0000464<div class="doc_code">
Chris Lattner6af02f32004-12-09 16:11:40 +0000465<pre><i>; Declare the string constant as a global constant...</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000466<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
467 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 +0000468
469<i>; External declaration of the puts function</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000470<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000471
472<i>; Definition of main function</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000473define i32 @main() { <i>; i32()* </i>
Dan Gohman623806e2009-01-04 23:44:43 +0000474 <i>; Convert [13 x i8]* to i8 *...</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000475 %cast210 = <a
Dan Gohman623806e2009-01-04 23:44:43 +0000476 href="#i_getelementptr">getelementptr</a> [13 x i8]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000477
478 <i>; Call puts function to write out the string to stdout...</i>
479 <a
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000480 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000481 <a
Bill Wendling3716c5d2007-05-29 09:04:49 +0000482 href="#i_ret">ret</a> i32 0<br>}<br>
483</pre>
484</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000485
486<p>This example is made up of a <a href="#globalvars">global variable</a>
487named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
488function, and a <a href="#functionstructure">function definition</a>
489for "<tt>main</tt>".</p>
490
Chris Lattnerd79749a2004-12-09 16:36:40 +0000491<p>In general, a module is made up of a list of global values,
492where both functions and global variables are global values. Global values are
493represented by a pointer to a memory location (in this case, a pointer to an
494array of char, and a pointer to a function), and have one of the following <a
495href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000496
Chris Lattnerd79749a2004-12-09 16:36:40 +0000497</div>
498
499<!-- ======================================================================= -->
500<div class="doc_subsection">
501 <a name="linkage">Linkage Types</a>
502</div>
503
504<div class="doc_text">
505
506<p>
507All Global Variables and Functions have one of the following types of linkage:
508</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000509
510<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000511
Rafael Espindola6de96a12009-01-15 20:18:42 +0000512 <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt>
513
514 <dd>Global values with private linkage are only directly accessible by
515 objects in the current module. In particular, linking code into a module with
516 an private global value may cause the private to be renamed as necessary to
517 avoid collisions. Because the symbol is private to the module, all
518 references can be updated. This doesn't show up in any symbol table in the
519 object file.
520 </dd>
521
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +0000522 <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt>
523
524 <dd>Similar to private, but the symbol is passed through the assembler and
525 removed by the linker after evaluation.</dd>
526
Dale Johannesen4188aad2008-05-23 23:13:41 +0000527 <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000528
Duncan Sands35e43c12009-01-16 09:29:46 +0000529 <dd> Similar to private, but the value shows as a local symbol (STB_LOCAL in
Rafael Espindola6de96a12009-01-15 20:18:42 +0000530 the case of ELF) in the object file. This corresponds to the notion of the
Chris Lattnere20b4702007-01-14 06:51:48 +0000531 '<tt>static</tt>' keyword in C.
Chris Lattner6af02f32004-12-09 16:11:40 +0000532 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000533
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +0000534 <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>:
Chris Lattner184f1be2009-04-13 05:44:34 +0000535 </dt>
536
537 <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted
538 into the object file corresponding to the LLVM module. They exist to
539 allow inlining and other optimizations to take place given knowledge of the
540 definition of the global, which is known to be somewhere outside the module.
541 Globals with <tt>available_externally</tt> linkage are allowed to be discarded
542 at will, and are otherwise the same as <tt>linkonce_odr</tt>. This linkage
543 type is only allowed on definitions, not declarations.</dd>
544
Chris Lattner6af02f32004-12-09 16:11:40 +0000545 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000546
Chris Lattnere20b4702007-01-14 06:51:48 +0000547 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
548 the same name when linkage occurs. This is typically used to implement
549 inline functions, templates, or other code which must be generated in each
550 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
551 allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000552 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000553
Dale Johannesen4188aad2008-05-23 23:13:41 +0000554 <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
555
556 <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
557 linkage, except that unreferenced <tt>common</tt> globals may not be
558 discarded. This is used for globals that may be emitted in multiple
559 translation units, but that are not guaranteed to be emitted into every
560 translation unit that uses them. One example of this is tentative
561 definitions in C, such as "<tt>int X;</tt>" at global scope.
562 </dd>
563
Chris Lattner6af02f32004-12-09 16:11:40 +0000564 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000565
Dale Johannesen4188aad2008-05-23 23:13:41 +0000566 <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
567 that some targets may choose to emit different assembly sequences for them
568 for target-dependent reasons. This is used for globals that are declared
569 "weak" in C source code.
Chris Lattner6af02f32004-12-09 16:11:40 +0000570 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000571
Chris Lattner6af02f32004-12-09 16:11:40 +0000572 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000573
574 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
575 pointer to array type. When two global variables with appending linkage are
576 linked together, the two global arrays are appended together. This is the
577 LLVM, typesafe, equivalent of having the system linker append together
578 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000579 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000580
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000581 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
Duncan Sands12da8ce2009-03-07 15:45:40 +0000582
Chris Lattner67c37d12008-08-05 18:29:16 +0000583 <dd>The semantics of this linkage follow the ELF object file model: the
584 symbol is weak until linked, if not linked, the symbol becomes null instead
585 of being an undefined reference.
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000586 </dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000587
Duncan Sands12da8ce2009-03-07 15:45:40 +0000588 <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt>
Duncan Sands12da8ce2009-03-07 15:45:40 +0000589 <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt>
Chris Lattner184f1be2009-04-13 05:44:34 +0000590 <dd>Some languages allow differing globals to be merged, such as two
Duncan Sands12da8ce2009-03-07 15:45:40 +0000591 functions with different semantics. Other languages, such as <tt>C++</tt>,
592 ensure that only equivalent globals are ever merged (the "one definition
Chris Lattner184f1be2009-04-13 05:44:34 +0000593 rule" - "ODR"). Such languages can use the <tt>linkonce_odr</tt>
Duncan Sands4581beb2009-03-11 20:14:15 +0000594 and <tt>weak_odr</tt> linkage types to indicate that the global will only
595 be merged with equivalent globals. These linkage types are otherwise the
596 same as their non-<tt>odr</tt> versions.
Duncan Sands12da8ce2009-03-07 15:45:40 +0000597 </dd>
598
Chris Lattner6af02f32004-12-09 16:11:40 +0000599 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000600
601 <dd>If none of the above identifiers are used, the global is externally
602 visible, meaning that it participates in linkage and can be used to resolve
603 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000604 </dd>
Reid Spencer7972c472007-04-11 23:49:50 +0000605</dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000606
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000607 <p>
608 The next two types of linkage are targeted for Microsoft Windows platform
609 only. They are designed to support importing (exporting) symbols from (to)
Chris Lattner67c37d12008-08-05 18:29:16 +0000610 DLLs (Dynamic Link Libraries).
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000611 </p>
612
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000613 <dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000614 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
615
616 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
617 or variable via a global pointer to a pointer that is set up by the DLL
618 exporting the symbol. On Microsoft Windows targets, the pointer name is
Dan Gohman33a9cef2009-01-12 21:35:55 +0000619 formed by combining <code>__imp_</code> and the function or variable name.
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000620 </dd>
621
622 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
623
624 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
625 pointer to a pointer in a DLL, so that it can be referenced with the
626 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
Dan Gohman33a9cef2009-01-12 21:35:55 +0000627 name is formed by combining <code>__imp_</code> and the function or variable
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000628 name.
629 </dd>
630
Chris Lattner6af02f32004-12-09 16:11:40 +0000631</dl>
632
Dan Gohman8ef44982008-11-24 17:18:39 +0000633<p>For example, since the "<tt>.LC0</tt>"
Chris Lattner6af02f32004-12-09 16:11:40 +0000634variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
635variable and was linked with this one, one of the two would be renamed,
636preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
637external (i.e., lacking any linkage declarations), they are accessible
Reid Spencer92c671e2007-01-05 00:59:10 +0000638outside of the current module.</p>
639<p>It is illegal for a function <i>declaration</i>
Duncan Sandse2881052009-03-11 08:08:06 +0000640to have any linkage type other than "externally visible", <tt>dllimport</tt>
641or <tt>extern_weak</tt>.</p>
Duncan Sands12da8ce2009-03-07 15:45:40 +0000642<p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt>
643or <tt>weak_odr</tt> linkages.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000644</div>
645
646<!-- ======================================================================= -->
647<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000648 <a name="callingconv">Calling Conventions</a>
649</div>
650
651<div class="doc_text">
652
653<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
654and <a href="#i_invoke">invokes</a> can all have an optional calling convention
655specified for the call. The calling convention of any pair of dynamic
656caller/callee must match, or the behavior of the program is undefined. The
657following calling conventions are supported by LLVM, and more may be added in
658the future:</p>
659
660<dl>
661 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
662
663 <dd>This calling convention (the default if no other calling convention is
664 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000665 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencer72ba4992006-12-31 21:30:18 +0000666 prototype and implemented declaration of the function (as does normal C).
Chris Lattner0132aff2005-05-06 22:57:40 +0000667 </dd>
668
669 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
670
671 <dd>This calling convention attempts to make calls as fast as possible
672 (e.g. by passing things in registers). This calling convention allows the
673 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner67c37d12008-08-05 18:29:16 +0000674 without having to conform to an externally specified ABI (Application Binary
675 Interface). Implementations of this convention should allow arbitrary
Arnold Schwaighofer2c6b8882008-05-14 09:17:12 +0000676 <a href="CodeGenerator.html#tailcallopt">tail call optimization</a> to be
677 supported. This calling convention does not support varargs and requires the
678 prototype of all callees to exactly match the prototype of the function
679 definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000680 </dd>
681
682 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
683
684 <dd>This calling convention attempts to make code in the caller as efficient
685 as possible under the assumption that the call is not commonly executed. As
686 such, these calls often preserve all registers so that the call does not break
687 any live ranges in the caller side. This calling convention does not support
688 varargs and requires the prototype of all callees to exactly match the
689 prototype of the function definition.
690 </dd>
691
Chris Lattner573f64e2005-05-07 01:46:40 +0000692 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000693
694 <dd>Any calling convention may be specified by number, allowing
695 target-specific calling conventions to be used. Target specific calling
696 conventions start at 64.
697 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000698</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000699
700<p>More calling conventions can be added/defined on an as-needed basis, to
701support pascal conventions or any other well-known target-independent
702convention.</p>
703
704</div>
705
706<!-- ======================================================================= -->
707<div class="doc_subsection">
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000708 <a name="visibility">Visibility Styles</a>
709</div>
710
711<div class="doc_text">
712
713<p>
714All Global Variables and Functions have one of the following visibility styles:
715</p>
716
717<dl>
718 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
719
Chris Lattner67c37d12008-08-05 18:29:16 +0000720 <dd>On targets that use the ELF object file format, default visibility means
721 that the declaration is visible to other
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000722 modules and, in shared libraries, means that the declared entity may be
723 overridden. On Darwin, default visibility means that the declaration is
724 visible to other modules. Default visibility corresponds to "external
725 linkage" in the language.
726 </dd>
727
728 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
729
730 <dd>Two declarations of an object with hidden visibility refer to the same
731 object if they are in the same shared object. Usually, hidden visibility
732 indicates that the symbol will not be placed into the dynamic symbol table,
733 so no other module (executable or shared library) can reference it
734 directly.
735 </dd>
736
Anton Korobeynikov39f3cff2007-04-29 18:35:00 +0000737 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
738
739 <dd>On ELF, protected visibility indicates that the symbol will be placed in
740 the dynamic symbol table, but that references within the defining module will
741 bind to the local symbol. That is, the symbol cannot be overridden by another
742 module.
743 </dd>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000744</dl>
745
746</div>
747
748<!-- ======================================================================= -->
749<div class="doc_subsection">
Chris Lattnerbc088212009-01-11 20:53:49 +0000750 <a name="namedtypes">Named Types</a>
751</div>
752
753<div class="doc_text">
754
755<p>LLVM IR allows you to specify name aliases for certain types. This can make
756it easier to read the IR and make the IR more condensed (particularly when
757recursive types are involved). An example of a name specification is:
758</p>
759
760<div class="doc_code">
761<pre>
762%mytype = type { %mytype*, i32 }
763</pre>
764</div>
765
766<p>You may give a name to any <a href="#typesystem">type</a> except "<a
767href="t_void">void</a>". Type name aliases may be used anywhere a type is
768expected with the syntax "%mytype".</p>
769
770<p>Note that type names are aliases for the structural type that they indicate,
771and that you can therefore specify multiple names for the same type. This often
772leads to confusing behavior when dumping out a .ll file. Since LLVM IR uses
773structural typing, the name is not part of the type. When printing out LLVM IR,
774the printer will pick <em>one name</em> to render all types of a particular
775shape. This means that if you have code where two different source types end up
776having the same LLVM type, that the dumper will sometimes print the "wrong" or
777unexpected type. This is an important design point and isn't going to
778change.</p>
779
780</div>
781
Chris Lattnerbc088212009-01-11 20:53:49 +0000782<!-- ======================================================================= -->
783<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000784 <a name="globalvars">Global Variables</a>
785</div>
786
787<div class="doc_text">
788
Chris Lattner5d5aede2005-02-12 19:30:21 +0000789<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000790instead of run-time. Global variables may optionally be initialized, may have
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000791an explicit section to be placed in, and may have an optional explicit alignment
792specified. A variable may be defined as "thread_local", which means that it
793will not be shared by threads (each thread will have a separated copy of the
794variable). A variable may be defined as a global "constant," which indicates
795that the contents of the variable will <b>never</b> be modified (enabling better
Chris Lattner5d5aede2005-02-12 19:30:21 +0000796optimization, allowing the global data to be placed in the read-only section of
797an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000798cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000799
800<p>
801LLVM explicitly allows <em>declarations</em> of global variables to be marked
802constant, even if the final definition of the global is not. This capability
803can be used to enable slightly better optimization of the program, but requires
804the language definition to guarantee that optimizations based on the
805'constantness' are valid for the translation units that do not include the
806definition.
807</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000808
809<p>As SSA values, global variables define pointer values that are in
810scope (i.e. they dominate) all basic blocks in the program. Global
811variables always define a pointer to their "content" type because they
812describe a region of memory, and all memory objects in LLVM are
813accessed through pointers.</p>
814
Chris Lattnercb3f64f2009-07-18 21:47:15 +0000815<p>A global variable may be declared to reside in a target-specific numbered
Christopher Lamb308121c2007-12-11 09:31:00 +0000816address space. For targets that support them, address spaces may affect how
817optimizations are performed and/or what target instructions are used to access
Christopher Lamb25f50762007-12-12 08:44:39 +0000818the variable. The default address space is zero. The address space qualifier
819must precede any other attributes.</p>
Christopher Lamb308121c2007-12-11 09:31:00 +0000820
Chris Lattner662c8722005-11-12 00:45:07 +0000821<p>LLVM allows an explicit section to be specified for globals. If the target
822supports it, it will emit globals to the section specified.</p>
823
Chris Lattner54611b42005-11-06 08:02:57 +0000824<p>An explicit alignment may be specified for a global. If not present, or if
825the alignment is set to zero, the alignment of the global is set by the target
826to whatever it feels convenient. If an explicit alignment is specified, the
827global is forced to have at least that much alignment. All alignments must be
828a power of 2.</p>
829
Christopher Lamb308121c2007-12-11 09:31:00 +0000830<p>For example, the following defines a global in a numbered address space with
831an initializer, section, and alignment:</p>
Chris Lattner5760c502007-01-14 00:27:09 +0000832
Bill Wendling3716c5d2007-05-29 09:04:49 +0000833<div class="doc_code">
Chris Lattner5760c502007-01-14 00:27:09 +0000834<pre>
Dan Gohmanaaa679b2009-01-11 00:40:00 +0000835@G = addrspace(5) constant float 1.0, section "foo", align 4
Chris Lattner5760c502007-01-14 00:27:09 +0000836</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000837</div>
Chris Lattner5760c502007-01-14 00:27:09 +0000838
Chris Lattner6af02f32004-12-09 16:11:40 +0000839</div>
840
841
842<!-- ======================================================================= -->
843<div class="doc_subsection">
844 <a name="functionstructure">Functions</a>
845</div>
846
847<div class="doc_text">
848
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000849<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
850an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000851<a href="#visibility">visibility style</a>, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000852<a href="#callingconv">calling convention</a>, a return type, an optional
853<a href="#paramattrs">parameter attribute</a> for the return type, a function
854name, a (possibly empty) argument list (each with optional
Devang Patel7e9b05e2008-10-06 18:50:38 +0000855<a href="#paramattrs">parameter attributes</a>), optional
856<a href="#fnattrs">function attributes</a>, an optional section,
857an optional alignment, an optional <a href="#gc">garbage collector name</a>,
Chris Lattnercbc4d2a2008-10-04 18:10:21 +0000858an opening curly brace, a list of basic blocks, and a closing curly brace.
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000859
860LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
861optional <a href="#linkage">linkage type</a>, an optional
862<a href="#visibility">visibility style</a>, an optional
863<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000864<a href="#paramattrs">parameter attribute</a> for the return type, a function
Gordon Henriksen71183b62007-12-10 03:18:06 +0000865name, a possibly empty list of arguments, an optional alignment, and an optional
Gordon Henriksendc5cafb2007-12-10 03:30:21 +0000866<a href="#gc">garbage collector name</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000867
Chris Lattner67c37d12008-08-05 18:29:16 +0000868<p>A function definition contains a list of basic blocks, forming the CFG
869(Control Flow Graph) for
Chris Lattner6af02f32004-12-09 16:11:40 +0000870the function. Each basic block may optionally start with a label (giving the
871basic block a symbol table entry), contains a list of instructions, and ends
872with a <a href="#terminators">terminator</a> instruction (such as a branch or
873function return).</p>
874
Chris Lattnera59fb102007-06-08 16:52:14 +0000875<p>The first basic block in a function is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000876executed on entrance to the function, and it is not allowed to have predecessor
877basic blocks (i.e. there can not be any branches to the entry block of a
878function). Because the block can have no predecessors, it also cannot have any
879<a href="#i_phi">PHI nodes</a>.</p>
880
Chris Lattner662c8722005-11-12 00:45:07 +0000881<p>LLVM allows an explicit section to be specified for functions. If the target
882supports it, it will emit functions to the section specified.</p>
883
Chris Lattner54611b42005-11-06 08:02:57 +0000884<p>An explicit alignment may be specified for a function. If not present, or if
885the alignment is set to zero, the alignment of the function is set by the target
886to whatever it feels convenient. If an explicit alignment is specified, the
887function is forced to have at least that much alignment. All alignments must be
888a power of 2.</p>
889
Devang Patel02256232008-10-07 17:48:33 +0000890 <h5>Syntax:</h5>
891
892<div class="doc_code">
Chris Lattner0ae02092008-10-13 16:55:18 +0000893<tt>
894define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>]
895 [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>]
896 &lt;ResultType&gt; @&lt;FunctionName&gt; ([argument list])
897 [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N]
898 [<a href="#gc">gc</a>] { ... }
899</tt>
Devang Patel02256232008-10-07 17:48:33 +0000900</div>
901
Chris Lattner6af02f32004-12-09 16:11:40 +0000902</div>
903
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000904
905<!-- ======================================================================= -->
906<div class="doc_subsection">
907 <a name="aliasstructure">Aliases</a>
908</div>
909<div class="doc_text">
910 <p>Aliases act as "second name" for the aliasee value (which can be either
Anton Korobeynikov25b2e822008-03-22 08:36:14 +0000911 function, global variable, another alias or bitcast of global value). Aliases
912 may have an optional <a href="#linkage">linkage type</a>, and an
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000913 optional <a href="#visibility">visibility style</a>.</p>
914
915 <h5>Syntax:</h5>
916
Bill Wendling3716c5d2007-05-29 09:04:49 +0000917<div class="doc_code">
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000918<pre>
Duncan Sands7e99a942008-09-12 20:48:21 +0000919@&lt;Name&gt; = alias [Linkage] [Visibility] &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000920</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000921</div>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000922
923</div>
924
925
926
Chris Lattner91c15c42006-01-23 23:23:47 +0000927<!-- ======================================================================= -->
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000928<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
929<div class="doc_text">
930 <p>The return type and each parameter of a function type may have a set of
931 <i>parameter attributes</i> associated with them. Parameter attributes are
932 used to communicate additional information about the result or parameters of
Duncan Sandsad0ea2d2007-11-27 13:23:08 +0000933 a function. Parameter attributes are considered to be part of the function,
934 not of the function type, so functions with different parameter attributes
935 can have the same function type.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000936
Reid Spencercf7ebf52007-01-15 18:27:39 +0000937 <p>Parameter attributes are simple keywords that follow the type specified. If
938 multiple parameter attributes are needed, they are space separated. For
Bill Wendling3716c5d2007-05-29 09:04:49 +0000939 example:</p>
940
941<div class="doc_code">
942<pre>
Nick Lewyckydac78d82009-02-15 23:06:14 +0000943declare i32 @printf(i8* noalias nocapture, ...)
Chris Lattnerd2597d72008-10-04 18:33:34 +0000944declare i32 @atoi(i8 zeroext)
945declare signext i8 @returns_signed_char()
Bill Wendling3716c5d2007-05-29 09:04:49 +0000946</pre>
947</div>
948
Duncan Sandsad0ea2d2007-11-27 13:23:08 +0000949 <p>Note that any attributes for the function result (<tt>nounwind</tt>,
950 <tt>readonly</tt>) come immediately after the argument list.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000951
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000952 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000953 <dl>
Reid Spencer314e1cb2007-07-19 23:13:04 +0000954 <dt><tt>zeroext</tt></dt>
Chris Lattnerd2597d72008-10-04 18:33:34 +0000955 <dd>This indicates to the code generator that the parameter or return value
956 should be zero-extended to a 32-bit value by the caller (for a parameter)
957 or the callee (for a return value).</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000958
Reid Spencer314e1cb2007-07-19 23:13:04 +0000959 <dt><tt>signext</tt></dt>
Chris Lattnerd2597d72008-10-04 18:33:34 +0000960 <dd>This indicates to the code generator that the parameter or return value
961 should be sign-extended to a 32-bit value by the caller (for a parameter)
962 or the callee (for a return value).</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000963
Anton Korobeynikove8166852007-01-28 14:30:45 +0000964 <dt><tt>inreg</tt></dt>
Dale Johannesenc50ada22008-09-25 20:47:45 +0000965 <dd>This indicates that this parameter or return value should be treated
966 in a special target-dependent fashion during while emitting code for a
967 function call or return (usually, by putting it in a register as opposed
Chris Lattnerd2597d72008-10-04 18:33:34 +0000968 to memory, though some targets use it to distinguish between two different
969 kinds of registers). Use of this attribute is target-specific.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000970
Duncan Sands2a1d8ba2008-10-06 08:14:18 +0000971 <dt><tt><a name="byval">byval</a></tt></dt>
Chris Lattner352ab9b2008-01-15 04:34:22 +0000972 <dd>This indicates that the pointer parameter should really be passed by
973 value to the function. The attribute implies that a hidden copy of the
974 pointee is made between the caller and the callee, so the callee is unable
Chris Lattner1ca5c642008-08-05 18:21:08 +0000975 to modify the value in the callee. This attribute is only valid on LLVM
Chris Lattner352ab9b2008-01-15 04:34:22 +0000976 pointer arguments. It is generally used to pass structs and arrays by
Duncan Sands2a1d8ba2008-10-06 08:14:18 +0000977 value, but is also valid on pointers to scalars. The copy is considered to
978 belong to the caller not the callee (for example,
979 <tt><a href="#readonly">readonly</a></tt> functions should not write to
Devang Patel7e9b05e2008-10-06 18:50:38 +0000980 <tt>byval</tt> parameters). This is not a valid attribute for return
Chris Lattner08aa9062009-02-05 05:42:28 +0000981 values. The byval attribute also supports specifying an alignment with the
982 align attribute. This has a target-specific effect on the code generator
983 that usually indicates a desired alignment for the synthesized stack
984 slot.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000985
Anton Korobeynikove8166852007-01-28 14:30:45 +0000986 <dt><tt>sret</tt></dt>
Duncan Sandsfa4b6732008-02-18 04:19:38 +0000987 <dd>This indicates that the pointer parameter specifies the address of a
988 structure that is the return value of the function in the source program.
Chris Lattnerd2597d72008-10-04 18:33:34 +0000989 This pointer must be guaranteed by the caller to be valid: loads and stores
990 to the structure may be assumed by the callee to not to trap. This may only
Devang Patel7e9b05e2008-10-06 18:50:38 +0000991 be applied to the first parameter. This is not a valid attribute for
992 return values. </dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000993
Zhou Sheng2444a9a2007-06-05 05:28:26 +0000994 <dt><tt>noalias</tt></dt>
Nick Lewyckyf5ffcbc2008-11-24 03:41:24 +0000995 <dd>This indicates that the pointer does not alias any global or any other
996 parameter. The caller is responsible for ensuring that this is the
Nick Lewyckyd59572c2008-11-24 05:00:44 +0000997 case. On a function return value, <tt>noalias</tt> additionally indicates
998 that the pointer does not alias any other pointers visible to the
Nick Lewycky2abb1082008-12-19 06:39:12 +0000999 caller. For further details, please see the discussion of the NoAlias
1000 response in
1001 <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias
1002 analysis</a>.</dd>
1003
1004 <dt><tt>nocapture</tt></dt>
1005 <dd>This indicates that the callee does not make any copies of the pointer
1006 that outlive the callee itself. This is not a valid attribute for return
1007 values.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +00001008
Duncan Sands27e91592007-07-27 19:57:41 +00001009 <dt><tt>nest</tt></dt>
Duncan Sands825bde42008-07-08 09:27:25 +00001010 <dd>This indicates that the pointer parameter can be excised using the
Devang Patel7e9b05e2008-10-06 18:50:38 +00001011 <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid
1012 attribute for return values.</dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +00001013 </dl>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001014
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001015</div>
1016
1017<!-- ======================================================================= -->
Chris Lattner91c15c42006-01-23 23:23:47 +00001018<div class="doc_subsection">
Gordon Henriksen71183b62007-12-10 03:18:06 +00001019 <a name="gc">Garbage Collector Names</a>
1020</div>
1021
1022<div class="doc_text">
1023<p>Each function may specify a garbage collector name, which is simply a
1024string.</p>
1025
1026<div class="doc_code"><pre
1027>define void @f() gc "name" { ...</pre></div>
1028
1029<p>The compiler declares the supported values of <i>name</i>. Specifying a
1030collector which will cause the compiler to alter its output in order to support
1031the named garbage collection algorithm.</p>
1032</div>
1033
1034<!-- ======================================================================= -->
1035<div class="doc_subsection">
Devang Patel9eb525d2008-09-26 23:51:19 +00001036 <a name="fnattrs">Function Attributes</a>
Devang Patelcaacdba2008-09-04 23:05:13 +00001037</div>
1038
1039<div class="doc_text">
Devang Patel9eb525d2008-09-26 23:51:19 +00001040
1041<p>Function attributes are set to communicate additional information about
1042 a function. Function attributes are considered to be part of the function,
1043 not of the function type, so functions with different parameter attributes
1044 can have the same function type.</p>
1045
1046 <p>Function attributes are simple keywords that follow the type specified. If
1047 multiple attributes are needed, they are space separated. For
1048 example:</p>
Devang Patelcaacdba2008-09-04 23:05:13 +00001049
1050<div class="doc_code">
Bill Wendlingb175fa42008-09-07 10:26:33 +00001051<pre>
Devang Patel9eb525d2008-09-26 23:51:19 +00001052define void @f() noinline { ... }
1053define void @f() alwaysinline { ... }
1054define void @f() alwaysinline optsize { ... }
1055define void @f() optsize
Bill Wendlingb175fa42008-09-07 10:26:33 +00001056</pre>
Devang Patelcaacdba2008-09-04 23:05:13 +00001057</div>
1058
Bill Wendlingb175fa42008-09-07 10:26:33 +00001059<dl>
Devang Patel9eb525d2008-09-26 23:51:19 +00001060<dt><tt>alwaysinline</tt></dt>
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001061<dd>This attribute indicates that the inliner should attempt to inline this
1062function into callers whenever possible, ignoring any active inlining size
1063threshold for this caller.</dd>
Bill Wendlingb175fa42008-09-07 10:26:33 +00001064
Devang Patel9eb525d2008-09-26 23:51:19 +00001065<dt><tt>noinline</tt></dt>
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001066<dd>This attribute indicates that the inliner should never inline this function
Chris Lattner0625c282008-10-05 17:14:59 +00001067in any situation. This attribute may not be used together with the
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001068<tt>alwaysinline</tt> attribute.</dd>
Bill Wendlingb175fa42008-09-07 10:26:33 +00001069
Devang Patel9eb525d2008-09-26 23:51:19 +00001070<dt><tt>optsize</tt></dt>
Devang Patele9743902008-09-29 18:34:44 +00001071<dd>This attribute suggests that optimization passes and code generator passes
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001072make choices that keep the code size of this function low, and otherwise do
1073optimizations specifically to reduce code size.</dd>
Bill Wendlingb175fa42008-09-07 10:26:33 +00001074
Devang Patel9eb525d2008-09-26 23:51:19 +00001075<dt><tt>noreturn</tt></dt>
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001076<dd>This function attribute indicates that the function never returns normally.
1077This produces undefined behavior at runtime if the function ever does
1078dynamically return.</dd>
Devang Patel9eb525d2008-09-26 23:51:19 +00001079
1080<dt><tt>nounwind</tt></dt>
Chris Lattnerfbf60a42008-10-04 18:23:17 +00001081<dd>This function attribute indicates that the function never returns with an
1082unwind or exceptional control flow. If the function does unwind, its runtime
1083behavior is undefined.</dd>
1084
1085<dt><tt>readnone</tt></dt>
Duncan Sands1efabaa2009-05-06 06:49:50 +00001086<dd>This attribute indicates that the function computes its result (or decides to
1087unwind an exception) based strictly on its arguments, without dereferencing any
Duncan Sands2a1d8ba2008-10-06 08:14:18 +00001088pointer arguments or otherwise accessing any mutable state (e.g. memory, control
1089registers, etc) visible to caller functions. It does not write through any
1090pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments) and
Duncan Sands1efabaa2009-05-06 06:49:50 +00001091never changes any state visible to callers. This means that it cannot unwind
1092exceptions by calling the <tt>C++</tt> exception throwing methods, but could
1093use the <tt>unwind</tt> instruction.</dd>
Devang Patel9eb525d2008-09-26 23:51:19 +00001094
Duncan Sands2a1d8ba2008-10-06 08:14:18 +00001095<dt><tt><a name="readonly">readonly</a></tt></dt>
1096<dd>This attribute indicates that the function does not write through any
1097pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments)
1098or otherwise modify any state (e.g. memory, control registers, etc) visible to
1099caller functions. It may dereference pointer arguments and read state that may
Duncan Sands1efabaa2009-05-06 06:49:50 +00001100be set in the caller. A readonly function always returns the same value (or
1101unwinds an exception identically) when called with the same set of arguments
1102and global state. It cannot unwind an exception by calling the <tt>C++</tt>
1103exception throwing methods, but may use the <tt>unwind</tt> instruction.</dd>
Bill Wendlinga8130172008-11-13 01:02:51 +00001104
1105<dt><tt><a name="ssp">ssp</a></tt></dt>
Bill Wendling6e41add2008-11-26 19:19:05 +00001106<dd>This attribute indicates that the function should emit a stack smashing
Bill Wendlinga8130172008-11-13 01:02:51 +00001107protector. It is in the form of a "canary"&mdash;a random value placed on the
1108stack before the local variables that's checked upon return from the function to
1109see if it has been overwritten. A heuristic is used to determine if a function
Bill Wendling6e41add2008-11-26 19:19:05 +00001110needs stack protectors or not.
Bill Wendlinga8130172008-11-13 01:02:51 +00001111
Devang Patel310fd4a2009-06-12 19:45:19 +00001112<br><br>If a function that has an <tt>ssp</tt> attribute is inlined into a function
Bill Wendling0f5541e2008-11-26 19:07:40 +00001113that doesn't have an <tt>ssp</tt> attribute, then the resulting function will
Devang Patel310fd4a2009-06-12 19:45:19 +00001114have an <tt>ssp</tt> attribute.</dd>
Bill Wendling0f5541e2008-11-26 19:07:40 +00001115
1116<dt><tt>sspreq</tt></dt>
Bill Wendling6e41add2008-11-26 19:19:05 +00001117<dd>This attribute indicates that the function should <em>always</em> emit a
Bill Wendlinga8130172008-11-13 01:02:51 +00001118stack smashing protector. This overrides the <tt><a href="#ssp">ssp</a></tt>
Bill Wendling6e41add2008-11-26 19:19:05 +00001119function attribute.
Bill Wendling0f5541e2008-11-26 19:07:40 +00001120
Devang Patel310fd4a2009-06-12 19:45:19 +00001121If a function that has an <tt>sspreq</tt> attribute is inlined into a
Bill Wendling0f5541e2008-11-26 19:07:40 +00001122function that doesn't have an <tt>sspreq</tt> attribute or which has
1123an <tt>ssp</tt> attribute, then the resulting function will have
Devang Patel310fd4a2009-06-12 19:45:19 +00001124an <tt>sspreq</tt> attribute.</dd>
1125
1126<dt><tt>noredzone</tt></dt>
Dan Gohman1b1b7e12009-06-15 17:37:09 +00001127<dd>This attribute indicates that the code generator should not use a
Dan Gohman405cf6c2009-06-15 21:18:01 +00001128red zone, even if the target-specific ABI normally permits it.
Dan Gohman1b1b7e12009-06-15 17:37:09 +00001129</dd>
Devang Patel310fd4a2009-06-12 19:45:19 +00001130
1131<dt><tt>noimplicitfloat</tt></dt>
1132<dd>This attributes disables implicit floating point instructions.</dd>
1133
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +00001134<dt><tt>naked</tt></dt>
Chris Lattnerfd8dea42009-07-17 21:14:28 +00001135<dd>This attribute disables prologue / epilogue emission for the function.
1136This can have very system-specific consequences.</dd>
Anton Korobeynikovc8ce7b082009-07-17 18:07:26 +00001137
Bill Wendlingb175fa42008-09-07 10:26:33 +00001138</dl>
1139
Devang Patelcaacdba2008-09-04 23:05:13 +00001140</div>
1141
1142<!-- ======================================================================= -->
1143<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +00001144 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +00001145</div>
1146
1147<div class="doc_text">
1148<p>
1149Modules may contain "module-level inline asm" blocks, which corresponds to the
1150GCC "file scope inline asm" blocks. These blocks are internally concatenated by
1151LLVM and treated as a single unit, but may be separated in the .ll file if
1152desired. The syntax is very simple:
1153</p>
1154
Bill Wendling3716c5d2007-05-29 09:04:49 +00001155<div class="doc_code">
1156<pre>
1157module asm "inline asm code goes here"
1158module asm "more can go here"
1159</pre>
1160</div>
Chris Lattner91c15c42006-01-23 23:23:47 +00001161
1162<p>The strings can contain any character by escaping non-printable characters.
1163 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
1164 for the number.
1165</p>
1166
1167<p>
1168 The inline asm code is simply printed to the machine code .s file when
1169 assembly code is generated.
1170</p>
1171</div>
Chris Lattner6af02f32004-12-09 16:11:40 +00001172
Reid Spencer50c723a2007-02-19 23:54:10 +00001173<!-- ======================================================================= -->
1174<div class="doc_subsection">
1175 <a name="datalayout">Data Layout</a>
1176</div>
1177
1178<div class="doc_text">
1179<p>A module may specify a target specific data layout string that specifies how
Reid Spencer7972c472007-04-11 23:49:50 +00001180data is to be laid out in memory. The syntax for the data layout is simply:</p>
1181<pre> target datalayout = "<i>layout specification</i>"</pre>
1182<p>The <i>layout specification</i> consists of a list of specifications
1183separated by the minus sign character ('-'). Each specification starts with a
1184letter and may include other information after the letter to define some
1185aspect of the data layout. The specifications accepted are as follows: </p>
Reid Spencer50c723a2007-02-19 23:54:10 +00001186<dl>
1187 <dt><tt>E</tt></dt>
1188 <dd>Specifies that the target lays out data in big-endian form. That is, the
1189 bits with the most significance have the lowest address location.</dd>
1190 <dt><tt>e</tt></dt>
Chris Lattner67c37d12008-08-05 18:29:16 +00001191 <dd>Specifies that the target lays out data in little-endian form. That is,
Reid Spencer50c723a2007-02-19 23:54:10 +00001192 the bits with the least significance have the lowest address location.</dd>
1193 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1194 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
1195 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
1196 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
1197 too.</dd>
1198 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1199 <dd>This specifies the alignment for an integer type of a given bit
1200 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
1201 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1202 <dd>This specifies the alignment for a vector type of a given bit
1203 <i>size</i>.</dd>
1204 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1205 <dd>This specifies the alignment for a floating point type of a given bit
1206 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
1207 (double).</dd>
1208 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1209 <dd>This specifies the alignment for an aggregate type of a given bit
1210 <i>size</i>.</dd>
Daniel Dunbar7921a592009-06-08 22:17:53 +00001211 <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
1212 <dd>This specifies the alignment for a stack object of a given bit
1213 <i>size</i>.</dd>
Reid Spencer50c723a2007-02-19 23:54:10 +00001214</dl>
1215<p>When constructing the data layout for a given target, LLVM starts with a
1216default set of specifications which are then (possibly) overriden by the
1217specifications in the <tt>datalayout</tt> keyword. The default specifications
1218are given in this list:</p>
1219<ul>
1220 <li><tt>E</tt> - big endian</li>
1221 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
1222 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
1223 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
1224 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
1225 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
Chris Lattner67c37d12008-08-05 18:29:16 +00001226 <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred
Reid Spencer50c723a2007-02-19 23:54:10 +00001227 alignment of 64-bits</li>
1228 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
1229 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
1230 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
1231 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
1232 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
Daniel Dunbar7921a592009-06-08 22:17:53 +00001233 <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li>
Reid Spencer50c723a2007-02-19 23:54:10 +00001234</ul>
Chris Lattner1ca5c642008-08-05 18:21:08 +00001235<p>When LLVM is determining the alignment for a given type, it uses the
Dan Gohmanef9462f2008-10-14 16:51:45 +00001236following rules:</p>
Reid Spencer50c723a2007-02-19 23:54:10 +00001237<ol>
1238 <li>If the type sought is an exact match for one of the specifications, that
1239 specification is used.</li>
1240 <li>If no match is found, and the type sought is an integer type, then the
1241 smallest integer type that is larger than the bitwidth of the sought type is
1242 used. If none of the specifications are larger than the bitwidth then the the
1243 largest integer type is used. For example, given the default specifications
1244 above, the i7 type will use the alignment of i8 (next largest) while both
1245 i65 and i256 will use the alignment of i64 (largest specified).</li>
1246 <li>If no match is found, and the type sought is a vector type, then the
1247 largest vector type that is smaller than the sought vector type will be used
Dan Gohmanef9462f2008-10-14 16:51:45 +00001248 as a fall back. This happens because &lt;128 x double&gt; can be implemented
1249 in terms of 64 &lt;2 x double&gt;, for example.</li>
Reid Spencer50c723a2007-02-19 23:54:10 +00001250</ol>
1251</div>
Chris Lattner6af02f32004-12-09 16:11:40 +00001252
Chris Lattner2f7c9632001-06-06 20:29:01 +00001253<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001254<div class="doc_section"> <a name="typesystem">Type System</a> </div>
1255<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +00001256
Misha Brukman76307852003-11-08 01:05:38 +00001257<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +00001258
Misha Brukman76307852003-11-08 01:05:38 +00001259<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +00001260intermediate representation. Being typed enables a number of
Chris Lattner67c37d12008-08-05 18:29:16 +00001261optimizations to be performed on the intermediate representation directly,
1262without having to do
Chris Lattner48b383b02003-11-25 01:02:51 +00001263extra analyses on the side before the transformation. A strong type
1264system makes it easier to read the generated code and enables novel
1265analyses and transformations that are not feasible to perform on normal
1266three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +00001267
1268</div>
1269
Chris Lattner2f7c9632001-06-06 20:29:01 +00001270<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001271<div class="doc_subsection"> <a name="t_classifications">Type
Chris Lattner48b383b02003-11-25 01:02:51 +00001272Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001273<div class="doc_text">
Chris Lattner7824d182008-01-04 04:32:38 +00001274<p>The types fall into a few useful
Chris Lattner48b383b02003-11-25 01:02:51 +00001275classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001276
1277<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001278 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001279 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001280 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001281 <td><a href="#t_integer">integer</a></td>
Reid Spencer138249b2007-05-16 18:44:01 +00001282 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001283 </tr>
1284 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001285 <td><a href="#t_floating">floating point</a></td>
1286 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001287 </tr>
1288 <tr>
1289 <td><a name="t_firstclass">first class</a></td>
Chris Lattner7824d182008-01-04 04:32:38 +00001290 <td><a href="#t_integer">integer</a>,
1291 <a href="#t_floating">floating point</a>,
1292 <a href="#t_pointer">pointer</a>,
Dan Gohman08783a882008-06-18 18:42:13 +00001293 <a href="#t_vector">vector</a>,
Dan Gohmanb9d66602008-05-12 23:51:09 +00001294 <a href="#t_struct">structure</a>,
1295 <a href="#t_array">array</a>,
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001296 <a href="#t_label">label</a>,
1297 <a href="#t_metadata">metadata</a>.
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001298 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001299 </tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001300 <tr>
1301 <td><a href="#t_primitive">primitive</a></td>
1302 <td><a href="#t_label">label</a>,
1303 <a href="#t_void">void</a>,
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001304 <a href="#t_floating">floating point</a>,
1305 <a href="#t_metadata">metadata</a>.</td>
Chris Lattner7824d182008-01-04 04:32:38 +00001306 </tr>
1307 <tr>
1308 <td><a href="#t_derived">derived</a></td>
1309 <td><a href="#t_integer">integer</a>,
1310 <a href="#t_array">array</a>,
1311 <a href="#t_function">function</a>,
1312 <a href="#t_pointer">pointer</a>,
1313 <a href="#t_struct">structure</a>,
1314 <a href="#t_pstruct">packed structure</a>,
1315 <a href="#t_vector">vector</a>,
1316 <a href="#t_opaque">opaque</a>.
Dan Gohman93bf60d2008-10-14 16:32:04 +00001317 </td>
Chris Lattner7824d182008-01-04 04:32:38 +00001318 </tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001319 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +00001320</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001321
Chris Lattner48b383b02003-11-25 01:02:51 +00001322<p>The <a href="#t_firstclass">first class</a> types are perhaps the
1323most important. Values of these types are the only ones which can be
1324produced by instructions, passed as arguments, or used as operands to
Dan Gohman34d1c0d2008-05-23 21:53:15 +00001325instructions.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001326</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001327
Chris Lattner2f7c9632001-06-06 20:29:01 +00001328<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001329<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner43542b32008-01-04 04:34:14 +00001330
Chris Lattner7824d182008-01-04 04:32:38 +00001331<div class="doc_text">
1332<p>The primitive types are the fundamental building blocks of the LLVM
1333system.</p>
1334
Chris Lattner43542b32008-01-04 04:34:14 +00001335</div>
1336
Chris Lattner7824d182008-01-04 04:32:38 +00001337<!-- _______________________________________________________________________ -->
1338<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1339
1340<div class="doc_text">
1341 <table>
1342 <tbody>
1343 <tr><th>Type</th><th>Description</th></tr>
1344 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1345 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1346 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1347 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1348 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1349 </tbody>
1350 </table>
1351</div>
1352
1353<!-- _______________________________________________________________________ -->
1354<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1355
1356<div class="doc_text">
1357<h5>Overview:</h5>
1358<p>The void type does not represent any value and has no size.</p>
1359
1360<h5>Syntax:</h5>
1361
1362<pre>
1363 void
1364</pre>
1365</div>
1366
1367<!-- _______________________________________________________________________ -->
1368<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1369
1370<div class="doc_text">
1371<h5>Overview:</h5>
1372<p>The label type represents code labels.</p>
1373
1374<h5>Syntax:</h5>
1375
1376<pre>
1377 label
1378</pre>
1379</div>
1380
Nick Lewyckyadbc2842009-05-30 05:06:04 +00001381<!-- _______________________________________________________________________ -->
1382<div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div>
1383
1384<div class="doc_text">
1385<h5>Overview:</h5>
1386<p>The metadata type represents embedded metadata. The only derived type that
1387may contain metadata is <tt>metadata*</tt> or a function type that returns or
1388takes metadata typed parameters, but not pointer to metadata types.</p>
1389
1390<h5>Syntax:</h5>
1391
1392<pre>
1393 metadata
1394</pre>
1395</div>
1396
Chris Lattner7824d182008-01-04 04:32:38 +00001397
1398<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001399<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001400
Misha Brukman76307852003-11-08 01:05:38 +00001401<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001402
Chris Lattner48b383b02003-11-25 01:02:51 +00001403<p>The real power in LLVM comes from the derived types in the system.
1404This is what allows a programmer to represent arrays, functions,
1405pointers, and other useful types. Note that these derived types may be
1406recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001407
Misha Brukman76307852003-11-08 01:05:38 +00001408</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001409
Chris Lattner2f7c9632001-06-06 20:29:01 +00001410<!-- _______________________________________________________________________ -->
Reid Spencer138249b2007-05-16 18:44:01 +00001411<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1412
1413<div class="doc_text">
1414
1415<h5>Overview:</h5>
1416<p>The integer type is a very simple derived type that simply specifies an
1417arbitrary bit width for the integer type desired. Any bit width from 1 bit to
14182^23-1 (about 8 million) can be specified.</p>
1419
1420<h5>Syntax:</h5>
1421
1422<pre>
1423 iN
1424</pre>
1425
1426<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1427value.</p>
1428
1429<h5>Examples:</h5>
1430<table class="layout">
Nick Lewyckyaab930a2009-05-24 02:46:06 +00001431 <tr class="layout">
1432 <td class="left"><tt>i1</tt></td>
1433 <td class="left">a single-bit integer.</td>
Reid Spencer138249b2007-05-16 18:44:01 +00001434 </tr>
Nick Lewyckyaab930a2009-05-24 02:46:06 +00001435 <tr class="layout">
1436 <td class="left"><tt>i32</tt></td>
1437 <td class="left">a 32-bit integer.</td>
1438 </tr>
1439 <tr class="layout">
1440 <td class="left"><tt>i1942652</tt></td>
1441 <td class="left">a really big integer of over 1 million bits.</td>
1442 </tr>
Reid Spencer138249b2007-05-16 18:44:01 +00001443</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001444
1445<p>Note that the code generator does not yet support large integer types
1446to be used as function return types. The specific limit on how large a
1447return type the code generator can currently handle is target-dependent;
1448currently it's often 64 bits for 32-bit targets and 128 bits for 64-bit
1449targets.</p>
1450
Bill Wendling3716c5d2007-05-29 09:04:49 +00001451</div>
Reid Spencer138249b2007-05-16 18:44:01 +00001452
1453<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001454<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001455
Misha Brukman76307852003-11-08 01:05:38 +00001456<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001457
Chris Lattner2f7c9632001-06-06 20:29:01 +00001458<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +00001459
Misha Brukman76307852003-11-08 01:05:38 +00001460<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +00001461sequentially in memory. The array type requires a size (number of
1462elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001463
Chris Lattner590645f2002-04-14 06:13:44 +00001464<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +00001465
1466<pre>
1467 [&lt;# elements&gt; x &lt;elementtype&gt;]
1468</pre>
1469
John Criswell02fdc6f2005-05-12 16:52:32 +00001470<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +00001471be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001472
Chris Lattner590645f2002-04-14 06:13:44 +00001473<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001474<table class="layout">
1475 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001476 <td class="left"><tt>[40 x i32]</tt></td>
1477 <td class="left">Array of 40 32-bit integer values.</td>
1478 </tr>
1479 <tr class="layout">
1480 <td class="left"><tt>[41 x i32]</tt></td>
1481 <td class="left">Array of 41 32-bit integer values.</td>
1482 </tr>
1483 <tr class="layout">
1484 <td class="left"><tt>[4 x i8]</tt></td>
1485 <td class="left">Array of 4 8-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001486 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001487</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001488<p>Here are some examples of multidimensional arrays:</p>
1489<table class="layout">
1490 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001491 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1492 <td class="left">3x4 array of 32-bit integer values.</td>
1493 </tr>
1494 <tr class="layout">
1495 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1496 <td class="left">12x10 array of single precision floating point values.</td>
1497 </tr>
1498 <tr class="layout">
1499 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1500 <td class="left">2x3x4 array of 16-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001501 </tr>
1502</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001503
John Criswell4c0cf7f2005-10-24 16:17:18 +00001504<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1505length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001506LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1507As a special case, however, zero length arrays are recognized to be variable
1508length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001509type "{ i32, [0 x float]}", for example.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001510
Dan Gohman142ccc02009-01-24 15:58:40 +00001511<p>Note that the code generator does not yet support large aggregate types
1512to be used as function return types. The specific limit on how large an
1513aggregate return type the code generator can currently handle is
1514target-dependent, and also dependent on the aggregate element types.</p>
1515
Misha Brukman76307852003-11-08 01:05:38 +00001516</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001517
Chris Lattner2f7c9632001-06-06 20:29:01 +00001518<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001519<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001520<div class="doc_text">
Chris Lattnerda508ac2008-04-23 04:59:35 +00001521
Chris Lattner2f7c9632001-06-06 20:29:01 +00001522<h5>Overview:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00001523
Chris Lattner48b383b02003-11-25 01:02:51 +00001524<p>The function type can be thought of as a function signature. It
Devang Patele3dfc1c2008-03-24 05:35:41 +00001525consists of a return type and a list of formal parameter types. The
Chris Lattnerda508ac2008-04-23 04:59:35 +00001526return type of a function type is a scalar type, a void type, or a struct type.
Devang Patel9c1f8b12008-03-24 20:52:42 +00001527If the return type is a struct type then all struct elements must be of first
Chris Lattnerda508ac2008-04-23 04:59:35 +00001528class types, and the struct must have at least one element.</p>
Devang Pateld6cff512008-03-10 20:49:15 +00001529
Chris Lattner2f7c9632001-06-06 20:29:01 +00001530<h5>Syntax:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00001531
1532<pre>
1533 &lt;returntype list&gt; (&lt;parameter list&gt;)
1534</pre>
1535
John Criswell4c0cf7f2005-10-24 16:17:18 +00001536<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +00001537specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +00001538which indicates that the function takes a variable number of arguments.
1539Variable argument functions can access their arguments with the <a
Devang Pateld6cff512008-03-10 20:49:15 +00001540 href="#int_varargs">variable argument handling intrinsic</a> functions.
1541'<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1542<a href="#t_firstclass">first class</a> type specifiers.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00001543
Chris Lattner2f7c9632001-06-06 20:29:01 +00001544<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001545<table class="layout">
1546 <tr class="layout">
Reid Spencer58c08712006-12-31 07:18:34 +00001547 <td class="left"><tt>i32 (i32)</tt></td>
1548 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001549 </td>
Reid Spencer58c08712006-12-31 07:18:34 +00001550 </tr><tr class="layout">
Reid Spencer314e1cb2007-07-19 23:13:04 +00001551 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencer655dcc62006-12-31 07:20:23 +00001552 </tt></td>
Reid Spencer58c08712006-12-31 07:18:34 +00001553 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1554 an <tt>i16</tt> that should be sign extended and a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001555 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer58c08712006-12-31 07:18:34 +00001556 <tt>float</tt>.
1557 </td>
1558 </tr><tr class="layout">
1559 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1560 <td class="left">A vararg function that takes at least one
Reid Spencer3e628eb92007-01-04 16:43:23 +00001561 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer58c08712006-12-31 07:18:34 +00001562 which returns an integer. This is the signature for <tt>printf</tt> in
1563 LLVM.
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001564 </td>
Devang Patele3dfc1c2008-03-24 05:35:41 +00001565 </tr><tr class="layout">
1566 <td class="left"><tt>{i32, i32} (i32)</tt></td>
Misha Brukmanc9813bd2008-11-27 06:41:20 +00001567 <td class="left">A function taking an <tt>i32</tt>, returning two
1568 <tt>i32</tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
Devang Patele3dfc1c2008-03-24 05:35:41 +00001569 </td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001570 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001571</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001572
Misha Brukman76307852003-11-08 01:05:38 +00001573</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001574<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001575<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001576<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001577<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001578<p>The structure type is used to represent a collection of data members
1579together in memory. The packing of the field types is defined to match
1580the ABI of the underlying processor. The elements of a structure may
1581be any type that has a size.</p>
1582<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1583and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1584field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1585instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001586<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001587<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001588<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001589<table class="layout">
1590 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001591 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1592 <td class="left">A triple of three <tt>i32</tt> values</td>
1593 </tr><tr class="layout">
1594 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1595 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1596 second element is a <a href="#t_pointer">pointer</a> to a
1597 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1598 an <tt>i32</tt>.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001599 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001600</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001601
1602<p>Note that the code generator does not yet support large aggregate types
1603to be used as function return types. The specific limit on how large an
1604aggregate return type the code generator can currently handle is
1605target-dependent, and also dependent on the aggregate element types.</p>
1606
Misha Brukman76307852003-11-08 01:05:38 +00001607</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001608
Chris Lattner2f7c9632001-06-06 20:29:01 +00001609<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001610<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1611</div>
1612<div class="doc_text">
1613<h5>Overview:</h5>
1614<p>The packed structure type is used to represent a collection of data members
1615together in memory. There is no padding between fields. Further, the alignment
1616of a packed structure is 1 byte. The elements of a packed structure may
1617be any type that has a size.</p>
1618<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1619and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1620field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1621instruction.</p>
1622<h5>Syntax:</h5>
1623<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1624<h5>Examples:</h5>
1625<table class="layout">
1626 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001627 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1628 <td class="left">A triple of three <tt>i32</tt> values</td>
1629 </tr><tr class="layout">
Bill Wendlingb175fa42008-09-07 10:26:33 +00001630 <td class="left">
1631<tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)*&nbsp;}&nbsp;&gt;</tt></td>
Jeff Cohen5819f182007-04-22 01:17:39 +00001632 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1633 second element is a <a href="#t_pointer">pointer</a> to a
1634 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1635 an <tt>i32</tt>.</td>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001636 </tr>
1637</table>
1638</div>
1639
1640<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001641<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001642<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001643<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001644<p>As in many languages, the pointer type represents a pointer or
Christopher Lamb308121c2007-12-11 09:31:00 +00001645reference to another object, which must live in memory. Pointer types may have
1646an optional address space attribute defining the target-specific numbered
1647address space where the pointed-to object resides. The default address space is
1648zero.</p>
Chris Lattner4a67c912009-02-08 19:53:29 +00001649
1650<p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does
Chris Lattnerd1d4cff2009-02-08 22:21:28 +00001651it permit pointers to labels (<tt>label*</tt>). Use <tt>i8*</tt> instead.</p>
Chris Lattner4a67c912009-02-08 19:53:29 +00001652
Chris Lattner590645f2002-04-14 06:13:44 +00001653<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001654<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001655<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001656<table class="layout">
1657 <tr class="layout">
Dan Gohman623806e2009-01-04 23:44:43 +00001658 <td class="left"><tt>[4 x i32]*</tt></td>
Chris Lattner747359f2007-12-19 05:04:11 +00001659 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1660 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1661 </tr>
1662 <tr class="layout">
1663 <td class="left"><tt>i32 (i32 *) *</tt></td>
1664 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001665 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner747359f2007-12-19 05:04:11 +00001666 <tt>i32</tt>.</td>
1667 </tr>
1668 <tr class="layout">
1669 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1670 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1671 that resides in address space #5.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001672 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001673</table>
Misha Brukman76307852003-11-08 01:05:38 +00001674</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001675
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001676<!-- _______________________________________________________________________ -->
Reid Spencer404a3252007-02-15 03:07:05 +00001677<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001678<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001679
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001680<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001681
Reid Spencer404a3252007-02-15 03:07:05 +00001682<p>A vector type is a simple derived type that represents a vector
1683of elements. Vector types are used when multiple primitive data
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001684are operated in parallel using a single instruction (SIMD).
Reid Spencer404a3252007-02-15 03:07:05 +00001685A vector type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +00001686elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer404a3252007-02-15 03:07:05 +00001687of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001688considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001689
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001690<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001691
1692<pre>
1693 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1694</pre>
1695
John Criswell4a3327e2005-05-13 22:25:59 +00001696<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001697be any integer or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001698
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001699<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001700
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001701<table class="layout">
1702 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001703 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1704 <td class="left">Vector of 4 32-bit integer values.</td>
1705 </tr>
1706 <tr class="layout">
1707 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1708 <td class="left">Vector of 8 32-bit floating-point values.</td>
1709 </tr>
1710 <tr class="layout">
1711 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1712 <td class="left">Vector of 2 64-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001713 </tr>
1714</table>
Dan Gohman142ccc02009-01-24 15:58:40 +00001715
1716<p>Note that the code generator does not yet support large vector types
1717to be used as function return types. The specific limit on how large a
1718vector return type codegen can currently handle is target-dependent;
1719currently it's often a few times longer than a hardware vector register.</p>
1720
Misha Brukman76307852003-11-08 01:05:38 +00001721</div>
1722
Chris Lattner37b6b092005-04-25 17:34:15 +00001723<!-- _______________________________________________________________________ -->
1724<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1725<div class="doc_text">
1726
1727<h5>Overview:</h5>
1728
1729<p>Opaque types are used to represent unknown types in the system. This
Gordon Henriksena699c4d2007-10-14 00:34:53 +00001730corresponds (for example) to the C notion of a forward declared structure type.
Chris Lattner37b6b092005-04-25 17:34:15 +00001731In LLVM, opaque types can eventually be resolved to any type (not just a
1732structure type).</p>
1733
1734<h5>Syntax:</h5>
1735
1736<pre>
1737 opaque
1738</pre>
1739
1740<h5>Examples:</h5>
1741
1742<table class="layout">
1743 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001744 <td class="left"><tt>opaque</tt></td>
1745 <td class="left">An opaque type.</td>
Chris Lattner37b6b092005-04-25 17:34:15 +00001746 </tr>
1747</table>
1748</div>
1749
Chris Lattnercf7a5842009-02-02 07:32:36 +00001750<!-- ======================================================================= -->
1751<div class="doc_subsection">
1752 <a name="t_uprefs">Type Up-references</a>
1753</div>
1754
1755<div class="doc_text">
1756<h5>Overview:</h5>
1757<p>
1758An "up reference" allows you to refer to a lexically enclosing type without
1759requiring it to have a name. For instance, a structure declaration may contain a
1760pointer to any of the types it is lexically a member of. Example of up
1761references (with their equivalent as named type declarations) include:</p>
1762
1763<pre>
Chris Lattnerbf1d5452009-02-09 10:00:56 +00001764 { \2 * } %x = type { %x* }
Chris Lattnercf7a5842009-02-02 07:32:36 +00001765 { \2 }* %y = type { %y }*
1766 \1* %z = type %z*
1767</pre>
1768
1769<p>
1770An up reference is needed by the asmprinter for printing out cyclic types when
1771there is no declared name for a type in the cycle. Because the asmprinter does
1772not want to print out an infinite type string, it needs a syntax to handle
1773recursive types that have no names (all names are optional in llvm IR).
1774</p>
1775
1776<h5>Syntax:</h5>
1777<pre>
1778 \&lt;level&gt;
1779</pre>
1780
1781<p>
1782The level is the count of the lexical type that is being referred to.
1783</p>
1784
1785<h5>Examples:</h5>
1786
1787<table class="layout">
1788 <tr class="layout">
1789 <td class="left"><tt>\1*</tt></td>
1790 <td class="left">Self-referential pointer.</td>
1791 </tr>
1792 <tr class="layout">
1793 <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td>
1794 <td class="left">Recursive structure where the upref refers to the out-most
1795 structure.</td>
1796 </tr>
1797</table>
1798</div>
1799
Chris Lattner37b6b092005-04-25 17:34:15 +00001800
Chris Lattner74d3f822004-12-09 17:30:23 +00001801<!-- *********************************************************************** -->
1802<div class="doc_section"> <a name="constants">Constants</a> </div>
1803<!-- *********************************************************************** -->
1804
1805<div class="doc_text">
1806
1807<p>LLVM has several different basic types of constants. This section describes
1808them all and their syntax.</p>
1809
1810</div>
1811
1812<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001813<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001814
1815<div class="doc_text">
1816
1817<dl>
1818 <dt><b>Boolean constants</b></dt>
1819
1820 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencer36a15422007-01-12 03:35:51 +00001821 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattner74d3f822004-12-09 17:30:23 +00001822 </dd>
1823
1824 <dt><b>Integer constants</b></dt>
1825
Reid Spencer8f08d802004-12-09 18:02:53 +00001826 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencer3e628eb92007-01-04 16:43:23 +00001827 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattner74d3f822004-12-09 17:30:23 +00001828 integer types.
1829 </dd>
1830
1831 <dt><b>Floating point constants</b></dt>
1832
1833 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1834 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner1429e6f2008-04-01 18:45:27 +00001835 notation (see below). The assembler requires the exact decimal value of
1836 a floating-point constant. For example, the assembler accepts 1.25 but
1837 rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point
1838 constants must have a <a href="#t_floating">floating point</a> type. </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001839
1840 <dt><b>Null pointer constants</b></dt>
1841
John Criswelldfe6a862004-12-10 15:51:16 +00001842 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001843 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1844
1845</dl>
1846
Dale Johannesencd4a3012009-02-11 22:14:51 +00001847<p>The one non-intuitive notation for constants is the hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001848of floating point constants. For example, the form '<tt>double
18490x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
18504.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001851(and the only time that they are generated by the disassembler) is when a
1852floating point constant must be emitted but it cannot be represented as a
Dale Johannesencd4a3012009-02-11 22:14:51 +00001853decimal floating point number in a reasonable number of digits. For example,
1854NaN's, infinities, and other
Reid Spencer8f08d802004-12-09 18:02:53 +00001855special values are represented in their IEEE hexadecimal format so that
1856assembly and disassembly do not cause any bits to change in the constants.</p>
Dale Johannesencd4a3012009-02-11 22:14:51 +00001857<p>When using the hexadecimal form, constants of types float and double are
1858represented using the 16-digit form shown above (which matches the IEEE754
1859representation for double); float values must, however, be exactly representable
1860as IEE754 single precision.
1861Hexadecimal format is always used for long
1862double, and there are three forms of long double. The 80-bit
1863format used by x86 is represented as <tt>0xK</tt>
1864followed by 20 hexadecimal digits.
1865The 128-bit format used by PowerPC (two adjacent doubles) is represented
1866by <tt>0xM</tt> followed by 32 hexadecimal digits. The IEEE 128-bit
1867format is represented
1868by <tt>0xL</tt> followed by 32 hexadecimal digits; no currently supported
1869target uses this format. Long doubles will only work if they match
1870the long double format on your target. All hexadecimal formats are big-endian
1871(sign bit at the left).</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001872</div>
1873
1874<!-- ======================================================================= -->
Chris Lattner361bfcd2009-02-28 18:32:25 +00001875<div class="doc_subsection">
1876<a name="aggregateconstants"> <!-- old anchor -->
1877<a name="complexconstants">Complex Constants</a></a>
Chris Lattner74d3f822004-12-09 17:30:23 +00001878</div>
1879
1880<div class="doc_text">
Chris Lattner361bfcd2009-02-28 18:32:25 +00001881<p>Complex constants are a (potentially recursive) combination of simple
1882constants and smaller complex constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001883
1884<dl>
1885 <dt><b>Structure constants</b></dt>
1886
1887 <dd>Structure constants are represented with notation similar to structure
1888 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerbea11172007-12-25 20:34:52 +00001889 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1890 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>". Structure constants
Chris Lattner455fc8c2005-03-07 22:13:59 +00001891 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001892 types of elements must match those specified by the type.
1893 </dd>
1894
1895 <dt><b>Array constants</b></dt>
1896
1897 <dd>Array constants are represented with notation similar to array type
1898 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001899 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001900 constants must have <a href="#t_array">array type</a>, and the number and
1901 types of elements must match those specified by the type.
1902 </dd>
1903
Reid Spencer404a3252007-02-15 03:07:05 +00001904 <dt><b>Vector constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001905
Reid Spencer404a3252007-02-15 03:07:05 +00001906 <dd>Vector constants are represented with notation similar to vector type
Chris Lattner74d3f822004-12-09 17:30:23 +00001907 definitions (a comma separated list of elements, surrounded by
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001908 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Jeff Cohen5819f182007-04-22 01:17:39 +00001909 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
Reid Spencer404a3252007-02-15 03:07:05 +00001910 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattner74d3f822004-12-09 17:30:23 +00001911 match those specified by the type.
1912 </dd>
1913
1914 <dt><b>Zero initialization</b></dt>
1915
1916 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1917 value to zero of <em>any</em> type, including scalar and aggregate types.
1918 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001919 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001920 initializers.
1921 </dd>
Nick Lewycky49f89192009-04-04 07:22:01 +00001922
1923 <dt><b>Metadata node</b></dt>
1924
Nick Lewycky8e2c4f42009-05-30 16:08:30 +00001925 <dd>A metadata node is a structure-like constant with
1926 <a href="#t_metadata">metadata type</a>. For example:
1927 "<tt>metadata !{ i32 0, metadata !"test" }</tt>". Unlike other constants
1928 that are meant to be interpreted as part of the instruction stream, metadata
1929 is a place to attach additional information such as debug info.
Nick Lewycky49f89192009-04-04 07:22:01 +00001930 </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001931</dl>
1932
1933</div>
1934
1935<!-- ======================================================================= -->
1936<div class="doc_subsection">
1937 <a name="globalconstants">Global Variable and Function Addresses</a>
1938</div>
1939
1940<div class="doc_text">
1941
1942<p>The addresses of <a href="#globalvars">global variables</a> and <a
1943href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001944constants. These constants are explicitly referenced when the <a
1945href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001946href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1947file:</p>
1948
Bill Wendling3716c5d2007-05-29 09:04:49 +00001949<div class="doc_code">
Chris Lattner74d3f822004-12-09 17:30:23 +00001950<pre>
Chris Lattner00538a12007-06-06 18:28:13 +00001951@X = global i32 17
1952@Y = global i32 42
1953@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
Chris Lattner74d3f822004-12-09 17:30:23 +00001954</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001955</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001956
1957</div>
1958
1959<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001960<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001961<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001962 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001963 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001964 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001965
Reid Spencer641f5c92004-12-09 18:13:12 +00001966 <p>Undefined values indicate to the compiler that the program is well defined
1967 no matter what value is used, giving the compiler more freedom to optimize.
1968 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001969</div>
1970
1971<!-- ======================================================================= -->
1972<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1973</div>
1974
1975<div class="doc_text">
1976
1977<p>Constant expressions are used to allow expressions involving other constants
1978to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001979href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001980that does not have side effects (e.g. load and call are not supported). The
1981following is the syntax for constant expressions:</p>
1982
1983<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001984 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1985 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001986 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001987
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001988 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1989 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001990 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001991
1992 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1993 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001994 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001995
1996 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1997 <dd>Truncate a floating point constant to another floating point type. The
1998 size of CST must be larger than the size of TYPE. Both types must be
1999 floating point.</dd>
2000
2001 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
2002 <dd>Floating point extend a constant to another type. The size of CST must be
2003 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
2004
Reid Spencer753163d2007-07-31 14:40:14 +00002005 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002006 <dd>Convert a floating point constant to the corresponding unsigned integer
Nate Begemand4d45c22007-11-17 03:58:34 +00002007 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
2008 or vector floating point type. Both CST and TYPE must be scalars, or vectors
2009 of the same number of elements. If the value won't fit in the integer type,
2010 the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002011
Reid Spencer51b07252006-11-09 23:03:26 +00002012 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002013 <dd>Convert a floating point constant to the corresponding signed integer
Nate Begemand4d45c22007-11-17 03:58:34 +00002014 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
2015 or vector floating point type. Both CST and TYPE must be scalars, or vectors
2016 of the same number of elements. If the value won't fit in the integer type,
2017 the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002018
Reid Spencer51b07252006-11-09 23:03:26 +00002019 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002020 <dd>Convert an unsigned integer constant to the corresponding floating point
Nate Begemand4d45c22007-11-17 03:58:34 +00002021 constant. TYPE must be a scalar or vector floating point type. CST must be of
2022 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
2023 of the same number of elements. If the value won't fit in the floating point
2024 type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002025
Reid Spencer51b07252006-11-09 23:03:26 +00002026 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002027 <dd>Convert a signed integer constant to the corresponding floating point
Nate Begemand4d45c22007-11-17 03:58:34 +00002028 constant. TYPE must be a scalar or vector floating point type. CST must be of
2029 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
2030 of the same number of elements. If the value won't fit in the floating point
2031 type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002032
Reid Spencer5b950642006-11-11 23:08:07 +00002033 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
2034 <dd>Convert a pointer typed constant to the corresponding integer constant
2035 TYPE must be an integer type. CST must be of pointer type. The CST value is
2036 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
2037
2038 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
2039 <dd>Convert a integer constant to a pointer constant. TYPE must be a
2040 pointer type. CST must be of integer type. The CST value is zero extended,
2041 truncated, or unchanged to make it fit in a pointer size. This one is
2042 <i>really</i> dangerous!</dd>
2043
2044 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Chris Lattner789dee32009-02-28 18:27:03 +00002045 <dd>Convert a constant, CST, to another TYPE. The constraints of the operands
2046 are the same as those for the <a href="#i_bitcast">bitcast
2047 instruction</a>.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00002048
2049 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
2050
2051 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
2052 constants. As with the <a href="#i_getelementptr">getelementptr</a>
2053 instruction, the index list may have zero or more indexes, which are required
2054 to make sense for the type of "CSTPTR".</dd>
2055
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002056 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
2057
2058 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer9965ee72006-12-04 19:23:19 +00002059 constants.</dd>
2060
2061 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
2062 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
2063
2064 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
2065 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002066
2067 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
2068
2069 <dd>Perform the <a href="#i_extractelement">extractelement
Dan Gohmanef9462f2008-10-14 16:51:45 +00002070 operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00002071
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00002072 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
2073
2074 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer9965ee72006-12-04 19:23:19 +00002075 operation</a> on constants.</dd>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00002076
Chris Lattner016a0e52006-04-08 00:13:41 +00002077
2078 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
2079
2080 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer9965ee72006-12-04 19:23:19 +00002081 operation</a> on constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00002082
Chris Lattner74d3f822004-12-09 17:30:23 +00002083 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
2084
Reid Spencer641f5c92004-12-09 18:13:12 +00002085 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
2086 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00002087 binary</a> operations. The constraints on operands are the same as those for
2088 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00002089 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00002090</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00002091</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00002092
Nick Lewycky49f89192009-04-04 07:22:01 +00002093<!-- ======================================================================= -->
2094<div class="doc_subsection"><a name="metadata">Embedded Metadata</a>
2095</div>
2096
2097<div class="doc_text">
2098
2099<p>Embedded metadata provides a way to attach arbitrary data to the
2100instruction stream without affecting the behaviour of the program. There are
Nick Lewyckyadbc2842009-05-30 05:06:04 +00002101two metadata primitives, strings and nodes. All metadata has the
2102<tt>metadata</tt> type and is identified in syntax by a preceding exclamation
2103point ('<tt>!</tt>').
Nick Lewycky49f89192009-04-04 07:22:01 +00002104</p>
2105
2106<p>A metadata string is a string surrounded by double quotes. It can contain
2107any character by escaping non-printable characters with "\xx" where "xx" is
2108the two digit hex code. For example: "<tt>!"test\00"</tt>".
2109</p>
2110
2111<p>Metadata nodes are represented with notation similar to structure constants
2112(a comma separated list of elements, surrounded by braces and preceeded by an
Nick Lewyckyadbc2842009-05-30 05:06:04 +00002113exclamation point). For example: "<tt>!{ metadata !"test\00", i32 10}</tt>".
Nick Lewycky49f89192009-04-04 07:22:01 +00002114</p>
2115
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +00002116<p>A metadata node will attempt to track changes to the values it holds. In
2117the event that a value is deleted, it will be replaced with a typeless
Nick Lewyckyadbc2842009-05-30 05:06:04 +00002118"<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p>
Nick Lewyckyb8f9b7a2009-05-10 20:57:05 +00002119
Nick Lewycky49f89192009-04-04 07:22:01 +00002120<p>Optimizations may rely on metadata to provide additional information about
2121the program that isn't available in the instructions, or that isn't easily
2122computable. Similarly, the code generator may expect a certain metadata format
2123to be used to express debugging information.</p>
2124</div>
2125
Chris Lattner2f7c9632001-06-06 20:29:01 +00002126<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00002127<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
2128<!-- *********************************************************************** -->
2129
2130<!-- ======================================================================= -->
2131<div class="doc_subsection">
2132<a name="inlineasm">Inline Assembler Expressions</a>
2133</div>
2134
2135<div class="doc_text">
2136
2137<p>
2138LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
2139Module-Level Inline Assembly</a>) through the use of a special value. This
2140value represents the inline assembler as a string (containing the instructions
2141to emit), a list of operand constraints (stored as a string), and a flag that
2142indicates whether or not the inline asm expression has side effects. An example
2143inline assembler expression is:
2144</p>
2145
Bill Wendling3716c5d2007-05-29 09:04:49 +00002146<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002147<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002148i32 (i32) asm "bswap $0", "=r,r"
Chris Lattner98f013c2006-01-25 23:47:57 +00002149</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002150</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002151
2152<p>
2153Inline assembler expressions may <b>only</b> be used as the callee operand of
2154a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
2155</p>
2156
Bill Wendling3716c5d2007-05-29 09:04:49 +00002157<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002158<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002159%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattner98f013c2006-01-25 23:47:57 +00002160</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002161</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002162
2163<p>
2164Inline asms with side effects not visible in the constraint list must be marked
2165as having side effects. This is done through the use of the
2166'<tt>sideeffect</tt>' keyword, like so:
2167</p>
2168
Bill Wendling3716c5d2007-05-29 09:04:49 +00002169<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00002170<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002171call void asm sideeffect "eieio", ""()
Chris Lattner98f013c2006-01-25 23:47:57 +00002172</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002173</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00002174
2175<p>TODO: The format of the asm and constraints string still need to be
2176documented here. Constraints on what can be done (e.g. duplication, moving, etc
Chris Lattnerd5528262008-10-04 18:36:02 +00002177need to be documented). This is probably best done by reference to another
2178document that covers inline asm from a holistic perspective.
Chris Lattner98f013c2006-01-25 23:47:57 +00002179</p>
2180
2181</div>
2182
2183<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002184<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
2185<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00002186
Misha Brukman76307852003-11-08 01:05:38 +00002187<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00002188
Chris Lattner48b383b02003-11-25 01:02:51 +00002189<p>The LLVM instruction set consists of several different
2190classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00002191instructions</a>, <a href="#binaryops">binary instructions</a>,
2192<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002193 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
2194instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00002195
Misha Brukman76307852003-11-08 01:05:38 +00002196</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002197
Chris Lattner2f7c9632001-06-06 20:29:01 +00002198<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002199<div class="doc_subsection"> <a name="terminators">Terminator
2200Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002201
Misha Brukman76307852003-11-08 01:05:38 +00002202<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00002203
Chris Lattner48b383b02003-11-25 01:02:51 +00002204<p>As mentioned <a href="#functionstructure">previously</a>, every
2205basic block in a program ends with a "Terminator" instruction, which
2206indicates which block should be executed after the current block is
2207finished. These terminator instructions typically yield a '<tt>void</tt>'
2208value: they produce control flow, not values (the one exception being
2209the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00002210<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00002211 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
2212instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002213the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
2214 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
2215 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00002216
Misha Brukman76307852003-11-08 01:05:38 +00002217</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00002218
Chris Lattner2f7c9632001-06-06 20:29:01 +00002219<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002220<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
2221Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002222<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002223<h5>Syntax:</h5>
Dan Gohmancc3132e2008-10-04 19:00:07 +00002224<pre>
2225 ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002226 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002227</pre>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002228
Chris Lattner2f7c9632001-06-06 20:29:01 +00002229<h5>Overview:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002230
Dan Gohmancc3132e2008-10-04 19:00:07 +00002231<p>The '<tt>ret</tt>' instruction is used to return control flow (and
2232optionally a value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00002233<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Dan Gohmancc3132e2008-10-04 19:00:07 +00002234returns a value and then causes control flow, and one that just causes
Chris Lattner48b383b02003-11-25 01:02:51 +00002235control flow to occur.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002236
Chris Lattner2f7c9632001-06-06 20:29:01 +00002237<h5>Arguments:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002238
Dan Gohmancc3132e2008-10-04 19:00:07 +00002239<p>The '<tt>ret</tt>' instruction optionally accepts a single argument,
2240the return value. The type of the return value must be a
2241'<a href="#t_firstclass">first class</a>' type.</p>
2242
2243<p>A function is not <a href="#wellformed">well formed</a> if
2244it it has a non-void return type and contains a '<tt>ret</tt>'
2245instruction with no return value or a return value with a type that
2246does not match its type, or if it has a void return type and contains
2247a '<tt>ret</tt>' instruction with a return value.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002248
Chris Lattner2f7c9632001-06-06 20:29:01 +00002249<h5>Semantics:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002250
Chris Lattner48b383b02003-11-25 01:02:51 +00002251<p>When the '<tt>ret</tt>' instruction is executed, control flow
2252returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00002253 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00002254the instruction after the call. If the caller was an "<a
2255 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00002256at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00002257returns a value, that value shall set the call or invoke instruction's
Dan Gohmanef9462f2008-10-14 16:51:45 +00002258return value.</p>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002259
Chris Lattner2f7c9632001-06-06 20:29:01 +00002260<h5>Example:</h5>
Chris Lattnerda508ac2008-04-23 04:59:35 +00002261
2262<pre>
2263 ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002264 ret void <i>; Return from a void function</i>
Bill Wendling050ee8f2009-02-28 22:12:54 +00002265 ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002266</pre>
Dan Gohman3065b612009-01-12 23:12:39 +00002267
Dan Gohman142ccc02009-01-24 15:58:40 +00002268<p>Note that the code generator does not yet fully support large
2269 return values. The specific sizes that are currently supported are
2270 dependent on the target. For integers, on 32-bit targets the limit
2271 is often 64 bits, and on 64-bit targets the limit is often 128 bits.
2272 For aggregate types, the current limits are dependent on the element
2273 types; for example targets are often limited to 2 total integer
2274 elements and 2 total floating-point elements.</p>
Dan Gohman3065b612009-01-12 23:12:39 +00002275
Misha Brukman76307852003-11-08 01:05:38 +00002276</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002277<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002278<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002279<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002280<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00002281<pre> br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002282</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002283<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002284<p>The '<tt>br</tt>' instruction is used to cause control flow to
2285transfer to a different basic block in the current function. There are
2286two forms of this instruction, corresponding to a conditional branch
2287and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002288<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002289<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencer36a15422007-01-12 03:35:51 +00002290single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Reid Spencer50c723a2007-02-19 23:54:10 +00002291unconditional form of the '<tt>br</tt>' instruction takes a single
2292'<tt>label</tt>' value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002293<h5>Semantics:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00002294<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002295argument is evaluated. If the value is <tt>true</tt>, control flows
2296to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
2297control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002298<h5>Example:</h5>
Chris Lattnere648c282009-05-09 18:11:50 +00002299<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq i32 %a, %b<br> br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002300 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00002301</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002302<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002303<div class="doc_subsubsection">
2304 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
2305</div>
2306
Misha Brukman76307852003-11-08 01:05:38 +00002307<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002308<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002309
2310<pre>
2311 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
2312</pre>
2313
Chris Lattner2f7c9632001-06-06 20:29:01 +00002314<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002315
2316<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
2317several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00002318instruction, allowing a branch to occur to one of many possible
2319destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002320
2321
Chris Lattner2f7c9632001-06-06 20:29:01 +00002322<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002323
2324<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
2325comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
2326an array of pairs of comparison value constants and '<tt>label</tt>'s. The
2327table is not allowed to contain duplicate constant entries.</p>
2328
Chris Lattner2f7c9632001-06-06 20:29:01 +00002329<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002330
Chris Lattner48b383b02003-11-25 01:02:51 +00002331<p>The <tt>switch</tt> instruction specifies a table of values and
2332destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00002333table is searched for the given value. If the value is found, control flow is
2334transfered to the corresponding destination; otherwise, control flow is
2335transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002336
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002337<h5>Implementation:</h5>
2338
2339<p>Depending on properties of the target machine and the particular
2340<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00002341ways. For example, it could be generated as a series of chained conditional
2342branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002343
2344<h5>Example:</h5>
2345
2346<pre>
2347 <i>; Emulate a conditional br instruction</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002348 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Dan Gohman623806e2009-01-04 23:44:43 +00002349 switch i32 %Val, label %truedest [ i32 0, label %falsedest ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002350
2351 <i>; Emulate an unconditional br instruction</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002352 switch i32 0, label %dest [ ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00002353
2354 <i>; Implement a jump table:</i>
Dan Gohman623806e2009-01-04 23:44:43 +00002355 switch i32 %val, label %otherwise [ i32 0, label %onzero
2356 i32 1, label %onone
2357 i32 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00002358</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002359</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00002360
Chris Lattner2f7c9632001-06-06 20:29:01 +00002361<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00002362<div class="doc_subsubsection">
2363 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
2364</div>
2365
Misha Brukman76307852003-11-08 01:05:38 +00002366<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00002367
Chris Lattner2f7c9632001-06-06 20:29:01 +00002368<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002369
2370<pre>
Devang Patel02256232008-10-07 17:48:33 +00002371 &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 +00002372 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00002373</pre>
2374
Chris Lattnera8292f32002-05-06 22:08:29 +00002375<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002376
2377<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
2378function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00002379'<tt>normal</tt>' label or the
2380'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00002381"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
2382"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00002383href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
Dan Gohmanef9462f2008-10-14 16:51:45 +00002384continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002385
Chris Lattner2f7c9632001-06-06 20:29:01 +00002386<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002387
Misha Brukman76307852003-11-08 01:05:38 +00002388<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00002389
Chris Lattner2f7c9632001-06-06 20:29:01 +00002390<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00002391 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00002392 The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00002393 convention</a> the call should use. If none is specified, the call defaults
2394 to using C calling conventions.
2395 </li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00002396
2397 <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for
2398 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>',
2399 and '<tt>inreg</tt>' attributes are valid here.</li>
2400
Chris Lattner0132aff2005-05-06 22:57:40 +00002401 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
2402 function value being invoked. In most cases, this is a direct function
2403 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
2404 an arbitrary pointer to function value.
2405 </li>
2406
2407 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
2408 function to be invoked. </li>
2409
2410 <li>'<tt>function args</tt>': argument list whose types match the function
2411 signature argument types. If the function signature indicates the function
2412 accepts a variable number of arguments, the extra arguments can be
2413 specified. </li>
2414
2415 <li>'<tt>normal label</tt>': the label reached when the called function
2416 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
2417
2418 <li>'<tt>exception label</tt>': the label reached when a callee returns with
2419 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
2420
Devang Patel02256232008-10-07 17:48:33 +00002421 <li>The optional <a href="#fnattrs">function attributes</a> list. Only
Devang Patel7e9b05e2008-10-06 18:50:38 +00002422 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
2423 '<tt>readnone</tt>' attributes are valid here.</li>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002424</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00002425
Chris Lattner2f7c9632001-06-06 20:29:01 +00002426<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002427
Misha Brukman76307852003-11-08 01:05:38 +00002428<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00002429href="#i_call">call</a></tt>' instruction in most regards. The primary
2430difference is that it establishes an association with a label, which is used by
2431the runtime library to unwind the stack.</p>
2432
2433<p>This instruction is used in languages with destructors to ensure that proper
2434cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2435exception. Additionally, this is important for implementation of
2436'<tt>catch</tt>' clauses in high-level languages that support them.</p>
2437
Jay Foad1a4eea52009-06-03 10:20:10 +00002438<p>For the purposes of the SSA form, the definition of the value
2439returned by the '<tt>invoke</tt>' instruction is deemed to occur on
2440the edge from the current block to the "normal" label. If the callee
2441unwinds then no return value is available.</p>
Dan Gohman9069d892009-05-22 21:47:08 +00002442
Chris Lattner2f7c9632001-06-06 20:29:01 +00002443<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00002444<pre>
Nick Lewycky084ab472008-03-16 07:18:12 +00002445 %retval = invoke i32 @Test(i32 15) to label %Continue
Jeff Cohen5819f182007-04-22 01:17:39 +00002446 unwind label %TestCleanup <i>; {i32}:retval set</i>
Nick Lewycky084ab472008-03-16 07:18:12 +00002447 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
Jeff Cohen5819f182007-04-22 01:17:39 +00002448 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002449</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002450</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002451
2452
Chris Lattner5ed60612003-09-03 00:41:47 +00002453<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002454
Chris Lattner48b383b02003-11-25 01:02:51 +00002455<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2456Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002457
Misha Brukman76307852003-11-08 01:05:38 +00002458<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002459
Chris Lattner5ed60612003-09-03 00:41:47 +00002460<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002461<pre>
2462 unwind
2463</pre>
2464
Chris Lattner5ed60612003-09-03 00:41:47 +00002465<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002466
2467<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
2468at the first callee in the dynamic call stack which used an <a
2469href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
2470primarily used to implement exception handling.</p>
2471
Chris Lattner5ed60612003-09-03 00:41:47 +00002472<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002473
Chris Lattnerfe8519c2008-04-19 21:01:16 +00002474<p>The '<tt>unwind</tt>' instruction causes execution of the current function to
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002475immediately halt. The dynamic call stack is then searched for the first <a
2476href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
2477execution continues at the "exceptional" destination block specified by the
2478<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
2479dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002480</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002481
2482<!-- _______________________________________________________________________ -->
2483
2484<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2485Instruction</a> </div>
2486
2487<div class="doc_text">
2488
2489<h5>Syntax:</h5>
2490<pre>
2491 unreachable
2492</pre>
2493
2494<h5>Overview:</h5>
2495
2496<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
2497instruction is used to inform the optimizer that a particular portion of the
2498code is not reachable. This can be used to indicate that the code after a
2499no-return function cannot be reached, and other facts.</p>
2500
2501<h5>Semantics:</h5>
2502
2503<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
2504</div>
2505
2506
2507
Chris Lattner2f7c9632001-06-06 20:29:01 +00002508<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002509<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002510<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00002511<p>Binary operators are used to do most of the computation in a
Chris Lattner81f92972008-04-01 18:47:32 +00002512program. They require two operands of the same type, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00002513produce a single value. The operands might represent
Reid Spencer404a3252007-02-15 03:07:05 +00002514multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattner81f92972008-04-01 18:47:32 +00002515The result value has the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002516<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00002517</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002518<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002519<div class="doc_subsubsection">
2520 <a name="i_add">'<tt>add</tt>' Instruction</a>
2521</div>
2522
Misha Brukman76307852003-11-08 01:05:38 +00002523<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002524
Chris Lattner2f7c9632001-06-06 20:29:01 +00002525<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002526
2527<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002528 &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 +00002529</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002530
Chris Lattner2f7c9632001-06-06 20:29:01 +00002531<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002532
Misha Brukman76307852003-11-08 01:05:38 +00002533<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002534
Chris Lattner2f7c9632001-06-06 20:29:01 +00002535<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002536
2537<p>The two arguments to the '<tt>add</tt>' instruction must be <a
Dan Gohmana5b96452009-06-04 22:49:04 +00002538 href="#t_integer">integer</a> or
2539 <a href="#t_vector">vector</a> of integer values. Both arguments must
2540 have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002541
Chris Lattner2f7c9632001-06-06 20:29:01 +00002542<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002543
Dan Gohmana5b96452009-06-04 22:49:04 +00002544<p>The value produced is the integer sum of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002545
Dan Gohmana5b96452009-06-04 22:49:04 +00002546<p>If the sum has unsigned overflow, the result returned is the
Chris Lattner2f2427e2008-01-28 00:36:27 +00002547mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2548the result.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002549
Chris Lattner2f2427e2008-01-28 00:36:27 +00002550<p>Because LLVM integers use a two's complement representation, this
2551instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002552
Chris Lattner2f7c9632001-06-06 20:29:01 +00002553<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002554
2555<pre>
2556 &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002557</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002558</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002559<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002560<div class="doc_subsubsection">
Dan Gohmana5b96452009-06-04 22:49:04 +00002561 <a name="i_fadd">'<tt>fadd</tt>' Instruction</a>
2562</div>
2563
2564<div class="doc_text">
2565
2566<h5>Syntax:</h5>
2567
2568<pre>
2569 &lt;result&gt; = fadd &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2570</pre>
2571
2572<h5>Overview:</h5>
2573
2574<p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p>
2575
2576<h5>Arguments:</h5>
2577
2578<p>The two arguments to the '<tt>fadd</tt>' instruction must be
2579<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of
2580floating point values. Both arguments must have identical types.</p>
2581
2582<h5>Semantics:</h5>
2583
2584<p>The value produced is the floating point sum of the two operands.</p>
2585
2586<h5>Example:</h5>
2587
2588<pre>
2589 &lt;result&gt; = fadd float 4.0, %var <i>; yields {float}:result = 4.0 + %var</i>
2590</pre>
2591</div>
2592<!-- _______________________________________________________________________ -->
2593<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002594 <a name="i_sub">'<tt>sub</tt>' Instruction</a>
2595</div>
2596
Misha Brukman76307852003-11-08 01:05:38 +00002597<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002598
Chris Lattner2f7c9632001-06-06 20:29:01 +00002599<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002600
2601<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002602 &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 +00002603</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002604
Chris Lattner2f7c9632001-06-06 20:29:01 +00002605<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002606
Misha Brukman76307852003-11-08 01:05:38 +00002607<p>The '<tt>sub</tt>' instruction returns the difference of its two
2608operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002609
2610<p>Note that the '<tt>sub</tt>' instruction is used to represent the
2611'<tt>neg</tt>' instruction present in most other intermediate
2612representations.</p>
2613
Chris Lattner2f7c9632001-06-06 20:29:01 +00002614<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002615
2616<p>The two arguments to the '<tt>sub</tt>' instruction must be <a
Dan Gohmana5b96452009-06-04 22:49:04 +00002617 href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of
2618 integer values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002619
Chris Lattner2f7c9632001-06-06 20:29:01 +00002620<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002621
Dan Gohmana5b96452009-06-04 22:49:04 +00002622<p>The value produced is the integer difference of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002623
Dan Gohmana5b96452009-06-04 22:49:04 +00002624<p>If the difference has unsigned overflow, the result returned is the
Chris Lattner2f2427e2008-01-28 00:36:27 +00002625mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2626the result.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002627
Chris Lattner2f2427e2008-01-28 00:36:27 +00002628<p>Because LLVM integers use a two's complement representation, this
2629instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002630
Chris Lattner2f7c9632001-06-06 20:29:01 +00002631<h5>Example:</h5>
Bill Wendling2d8b9a82007-05-29 09:42:13 +00002632<pre>
2633 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002634 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002635</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002636</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002637
Chris Lattner2f7c9632001-06-06 20:29:01 +00002638<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002639<div class="doc_subsubsection">
Dan Gohmana5b96452009-06-04 22:49:04 +00002640 <a name="i_fsub">'<tt>fsub</tt>' Instruction</a>
2641</div>
2642
2643<div class="doc_text">
2644
2645<h5>Syntax:</h5>
2646
2647<pre>
2648 &lt;result&gt; = fsub &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2649</pre>
2650
2651<h5>Overview:</h5>
2652
2653<p>The '<tt>fsub</tt>' instruction returns the difference of its two
2654operands.</p>
2655
2656<p>Note that the '<tt>fsub</tt>' instruction is used to represent the
2657'<tt>fneg</tt>' instruction present in most other intermediate
2658representations.</p>
2659
2660<h5>Arguments:</h5>
2661
2662<p>The two arguments to the '<tt>fsub</tt>' instruction must be <a
2663 <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2664 of floating point values. Both arguments must have identical types.</p>
2665
2666<h5>Semantics:</h5>
2667
2668<p>The value produced is the floating point difference of the two operands.</p>
2669
2670<h5>Example:</h5>
2671<pre>
2672 &lt;result&gt; = fsub float 4.0, %var <i>; yields {float}:result = 4.0 - %var</i>
2673 &lt;result&gt; = fsub float -0.0, %val <i>; yields {float}:result = -%var</i>
2674</pre>
2675</div>
2676
2677<!-- _______________________________________________________________________ -->
2678<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002679 <a name="i_mul">'<tt>mul</tt>' Instruction</a>
2680</div>
2681
Misha Brukman76307852003-11-08 01:05:38 +00002682<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002683
Chris Lattner2f7c9632001-06-06 20:29:01 +00002684<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002685<pre> &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 +00002686</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002687<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002688<p>The '<tt>mul</tt>' instruction returns the product of its two
2689operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002690
Chris Lattner2f7c9632001-06-06 20:29:01 +00002691<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002692
2693<p>The two arguments to the '<tt>mul</tt>' instruction must be <a
Dan Gohmana5b96452009-06-04 22:49:04 +00002694href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2695values. Both arguments must have identical types.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002696
Chris Lattner2f7c9632001-06-06 20:29:01 +00002697<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002698
Dan Gohmana5b96452009-06-04 22:49:04 +00002699<p>The value produced is the integer product of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002700
Dan Gohmana5b96452009-06-04 22:49:04 +00002701<p>If the result of the multiplication has unsigned overflow,
Chris Lattner2f2427e2008-01-28 00:36:27 +00002702the result returned is the mathematical result modulo
27032<sup>n</sup>, where n is the bit width of the result.</p>
2704<p>Because LLVM integers use a two's complement representation, and the
2705result is the same width as the operands, this instruction returns the
2706correct result for both signed and unsigned integers. If a full product
2707(e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands
2708should be sign-extended or zero-extended as appropriate to the
2709width of the full product.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002710<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002711<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002712</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002713</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002714
Chris Lattner2f7c9632001-06-06 20:29:01 +00002715<!-- _______________________________________________________________________ -->
Dan Gohmana5b96452009-06-04 22:49:04 +00002716<div class="doc_subsubsection">
2717 <a name="i_fmul">'<tt>fmul</tt>' Instruction</a>
2718</div>
2719
2720<div class="doc_text">
2721
2722<h5>Syntax:</h5>
2723<pre> &lt;result&gt; = fmul &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
2724</pre>
2725<h5>Overview:</h5>
2726<p>The '<tt>fmul</tt>' instruction returns the product of its two
2727operands.</p>
2728
2729<h5>Arguments:</h5>
2730
2731<p>The two arguments to the '<tt>fmul</tt>' instruction must be
2732<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2733of floating point values. Both arguments must have identical types.</p>
2734
2735<h5>Semantics:</h5>
2736
2737<p>The value produced is the floating point product of the two operands.</p>
2738
2739<h5>Example:</h5>
2740<pre> &lt;result&gt; = fmul float 4.0, %var <i>; yields {float}:result = 4.0 * %var</i>
2741</pre>
2742</div>
2743
2744<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002745<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2746</a></div>
2747<div class="doc_text">
2748<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002749<pre> &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 +00002750</pre>
2751<h5>Overview:</h5>
2752<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
2753operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002754
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002755<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002756
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002757<p>The two arguments to the '<tt>udiv</tt>' instruction must be
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002758<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2759values. Both arguments must have identical types.</p>
2760
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002761<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002762
Chris Lattner2f2427e2008-01-28 00:36:27 +00002763<p>The value produced is the unsigned integer quotient of the two operands.</p>
2764<p>Note that unsigned integer division and signed integer division are distinct
2765operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2766<p>Division by zero leads to undefined behavior.</p>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002767<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002768<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002769</pre>
2770</div>
2771<!-- _______________________________________________________________________ -->
2772<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2773</a> </div>
2774<div class="doc_text">
2775<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002776<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002777 &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 +00002778</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002779
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002780<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002781
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002782<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
2783operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002784
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002785<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002786
2787<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
2788<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2789values. Both arguments must have identical types.</p>
2790
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002791<h5>Semantics:</h5>
Chris Lattner1429e6f2008-04-01 18:45:27 +00002792<p>The value produced is the signed integer quotient of the two operands rounded towards zero.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002793<p>Note that signed integer division and unsigned integer division are distinct
2794operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2795<p>Division by zero leads to undefined behavior. Overflow also leads to
2796undefined behavior; this is a rare case, but can occur, for example,
2797by doing a 32-bit division of -2147483648 by -1.</p>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002798<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002799<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002800</pre>
2801</div>
2802<!-- _______________________________________________________________________ -->
2803<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002804Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002805<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002806<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002807<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002808 &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 +00002809</pre>
2810<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002811
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002812<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner48b383b02003-11-25 01:02:51 +00002813operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002814
Chris Lattner48b383b02003-11-25 01:02:51 +00002815<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002816
Jeff Cohen5819f182007-04-22 01:17:39 +00002817<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002818<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2819of floating point values. Both arguments must have identical types.</p>
2820
Chris Lattner48b383b02003-11-25 01:02:51 +00002821<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002822
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002823<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002824
Chris Lattner48b383b02003-11-25 01:02:51 +00002825<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002826
2827<pre>
2828 &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002829</pre>
2830</div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002831
Chris Lattner48b383b02003-11-25 01:02:51 +00002832<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00002833<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2834</div>
2835<div class="doc_text">
2836<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002837<pre> &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 +00002838</pre>
2839<h5>Overview:</h5>
2840<p>The '<tt>urem</tt>' instruction returns the remainder from the
2841unsigned division of its two arguments.</p>
2842<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002843<p>The two arguments to the '<tt>urem</tt>' instruction must be
2844<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2845values. Both arguments must have identical types.</p>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002846<h5>Semantics:</h5>
2847<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
Chris Lattner1429e6f2008-04-01 18:45:27 +00002848This instruction always performs an unsigned division to get the remainder.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002849<p>Note that unsigned integer remainder and signed integer remainder are
2850distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2851<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002852<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002853<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002854</pre>
2855
2856</div>
2857<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002858<div class="doc_subsubsection">
2859 <a name="i_srem">'<tt>srem</tt>' Instruction</a>
2860</div>
2861
Chris Lattner48b383b02003-11-25 01:02:51 +00002862<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002863
Chris Lattner48b383b02003-11-25 01:02:51 +00002864<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002865
2866<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002867 &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 +00002868</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002869
Chris Lattner48b383b02003-11-25 01:02:51 +00002870<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002871
Reid Spencer7eb55b32006-11-02 01:53:59 +00002872<p>The '<tt>srem</tt>' instruction returns the remainder from the
Dan Gohman08143e32007-11-05 23:35:22 +00002873signed division of its two operands. This instruction can also take
2874<a href="#t_vector">vector</a> versions of the values in which case
2875the elements must be integers.</p>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00002876
Chris Lattner48b383b02003-11-25 01:02:51 +00002877<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002878
Reid Spencer7eb55b32006-11-02 01:53:59 +00002879<p>The two arguments to the '<tt>srem</tt>' instruction must be
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002880<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
2881values. Both arguments must have identical types.</p>
2882
Chris Lattner48b383b02003-11-25 01:02:51 +00002883<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002884
Reid Spencer7eb55b32006-11-02 01:53:59 +00002885<p>This instruction returns the <i>remainder</i> of a division (where the result
Gabor Greif0f75ad02008-08-07 21:46:00 +00002886has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i>
2887operator (where the result has the same sign as the divisor, <tt>op2</tt>) of
Reid Spencer806ad6a2007-03-24 22:23:39 +00002888a value. For more information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002889 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
Reid Spencer806ad6a2007-03-24 22:23:39 +00002890Math Forum</a>. For a table of how this is implemented in various languages,
Reid Spencerdb3b93b2007-03-24 22:40:44 +00002891please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
Reid Spencer806ad6a2007-03-24 22:23:39 +00002892Wikipedia: modulo operation</a>.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002893<p>Note that signed integer remainder and unsigned integer remainder are
2894distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2895<p>Taking the remainder of a division by zero leads to undefined behavior.
2896Overflow also leads to undefined behavior; this is a rare case, but can occur,
2897for example, by taking the remainder of a 32-bit division of -2147483648 by -1.
2898(The remainder doesn't actually overflow, but this rule lets srem be
2899implemented using instructions that return both the result of the division
2900and the remainder.)</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002901<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002902<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002903</pre>
2904
2905</div>
2906<!-- _______________________________________________________________________ -->
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002907<div class="doc_subsubsection">
2908 <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div>
2909
Reid Spencer7eb55b32006-11-02 01:53:59 +00002910<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002911
Reid Spencer7eb55b32006-11-02 01:53:59 +00002912<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002913<pre> &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 +00002914</pre>
2915<h5>Overview:</h5>
2916<p>The '<tt>frem</tt>' instruction returns the remainder from the
2917division of its two operands.</p>
2918<h5>Arguments:</h5>
2919<p>The two arguments to the '<tt>frem</tt>' instruction must be
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002920<a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a>
2921of floating point values. Both arguments must have identical types.</p>
2922
Reid Spencer7eb55b32006-11-02 01:53:59 +00002923<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002924
Chris Lattner1429e6f2008-04-01 18:45:27 +00002925<p>This instruction returns the <i>remainder</i> of a division.
2926The remainder has the same sign as the dividend.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002927
Reid Spencer7eb55b32006-11-02 01:53:59 +00002928<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00002929
2930<pre>
2931 &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002932</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002933</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00002934
Reid Spencer2ab01932007-02-02 13:57:07 +00002935<!-- ======================================================================= -->
2936<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2937Operations</a> </div>
2938<div class="doc_text">
2939<p>Bitwise binary operators are used to do various forms of
2940bit-twiddling in a program. They are generally very efficient
2941instructions and can commonly be strength reduced from other
Chris Lattner1429e6f2008-04-01 18:45:27 +00002942instructions. They require two operands of the same type, execute an operation on them,
2943and produce a single value. The resulting value is the same type as its operands.</p>
Reid Spencer2ab01932007-02-02 13:57:07 +00002944</div>
2945
Reid Spencer04e259b2007-01-31 21:39:12 +00002946<!-- _______________________________________________________________________ -->
2947<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2948Instruction</a> </div>
2949<div class="doc_text">
2950<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002951<pre> &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 +00002952</pre>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002953
Reid Spencer04e259b2007-01-31 21:39:12 +00002954<h5>Overview:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002955
Reid Spencer04e259b2007-01-31 21:39:12 +00002956<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2957the left a specified number of bits.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002958
Reid Spencer04e259b2007-01-31 21:39:12 +00002959<h5>Arguments:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002960
Reid Spencer04e259b2007-01-31 21:39:12 +00002961<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
Nate Begemanfecbc8c2008-07-29 15:49:41 +00002962 href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greif0f75ad02008-08-07 21:46:00 +00002963type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002964
Reid Spencer04e259b2007-01-31 21:39:12 +00002965<h5>Semantics:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002966
Gabor Greif0f75ad02008-08-07 21:46:00 +00002967<p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod 2<sup>n</sup>,
2968where n is the width of the result. If <tt>op2</tt> is (statically or dynamically) negative or
Mon P Wang68d4eee2008-12-10 08:55:09 +00002969equal to or larger than the number of bits in <tt>op1</tt>, the result is undefined.
2970If the arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
2971corresponding shift amount in <tt>op2</tt>.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002972
Reid Spencer04e259b2007-01-31 21:39:12 +00002973<h5>Example:</h5><pre>
2974 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2975 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2976 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002977 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00002978 &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 +00002979</pre>
2980</div>
2981<!-- _______________________________________________________________________ -->
2982<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2983Instruction</a> </div>
2984<div class="doc_text">
2985<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00002986<pre> &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 +00002987</pre>
2988
2989<h5>Overview:</h5>
2990<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00002991operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002992
2993<h5>Arguments:</h5>
2994<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
Nate Begemanfecbc8c2008-07-29 15:49:41 +00002995<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greif0f75ad02008-08-07 21:46:00 +00002996type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002997
2998<h5>Semantics:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002999
Reid Spencer04e259b2007-01-31 21:39:12 +00003000<p>This instruction always performs a logical shift right operation. The most
3001significant bits of the result will be filled with zero bits after the
Gabor Greif0f75ad02008-08-07 21:46:00 +00003002shift. If <tt>op2</tt> is (statically or dynamically) equal to or larger than
Mon P Wang68d4eee2008-12-10 08:55:09 +00003003the number of bits in <tt>op1</tt>, the result is undefined. If the arguments are
3004vectors, each vector element of <tt>op1</tt> is shifted by the corresponding shift
3005amount in <tt>op2</tt>.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003006
3007<h5>Example:</h5>
3008<pre>
3009 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
3010 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
3011 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
3012 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003013 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00003014 &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 +00003015</pre>
3016</div>
3017
Reid Spencer2ab01932007-02-02 13:57:07 +00003018<!-- _______________________________________________________________________ -->
Reid Spencer04e259b2007-01-31 21:39:12 +00003019<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
3020Instruction</a> </div>
3021<div class="doc_text">
3022
3023<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00003024<pre> &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 +00003025</pre>
3026
3027<h5>Overview:</h5>
3028<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00003029operand shifted to the right a specified number of bits with sign extension.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003030
3031<h5>Arguments:</h5>
3032<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
Nate Begemanfecbc8c2008-07-29 15:49:41 +00003033<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
Gabor Greif0f75ad02008-08-07 21:46:00 +00003034type. '<tt>op2</tt>' is treated as an unsigned value.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003035
3036<h5>Semantics:</h5>
3037<p>This instruction always performs an arithmetic shift right operation,
3038The most significant bits of the result will be filled with the sign bit
Gabor Greif0f75ad02008-08-07 21:46:00 +00003039of <tt>op1</tt>. If <tt>op2</tt> is (statically or dynamically) equal to or
Mon P Wang68d4eee2008-12-10 08:55:09 +00003040larger than the number of bits in <tt>op1</tt>, the result is undefined. If the
3041arguments are vectors, each vector element of <tt>op1</tt> is shifted by the
3042corresponding shift amount in <tt>op2</tt>.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00003043
3044<h5>Example:</h5>
3045<pre>
3046 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
3047 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
3048 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
3049 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00003050 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Mon P Wang4dd832d2008-12-09 05:46:39 +00003051 &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 +00003052</pre>
3053</div>
3054
Chris Lattner2f7c9632001-06-06 20:29:01 +00003055<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003056<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
3057Instruction</a> </div>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003058
Misha Brukman76307852003-11-08 01:05:38 +00003059<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003060
Chris Lattner2f7c9632001-06-06 20:29:01 +00003061<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003062
3063<pre>
Gabor Greif0f75ad02008-08-07 21:46:00 +00003064 &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 +00003065</pre>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003066
Chris Lattner2f7c9632001-06-06 20:29:01 +00003067<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003068
Chris Lattner48b383b02003-11-25 01:02:51 +00003069<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
3070its two operands.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003071
Chris Lattner2f7c9632001-06-06 20:29:01 +00003072<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003073
3074<p>The two arguments to the '<tt>and</tt>' instruction must be
3075<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3076values. Both arguments must have identical types.</p>
3077
Chris Lattner2f7c9632001-06-06 20:29:01 +00003078<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003079<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003080<p> </p>
Bill Wendling5703c6e2008-09-07 10:29:20 +00003081<div>
Misha Brukman76307852003-11-08 01:05:38 +00003082<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00003083 <tbody>
3084 <tr>
3085 <td>In0</td>
3086 <td>In1</td>
3087 <td>Out</td>
3088 </tr>
3089 <tr>
3090 <td>0</td>
3091 <td>0</td>
3092 <td>0</td>
3093 </tr>
3094 <tr>
3095 <td>0</td>
3096 <td>1</td>
3097 <td>0</td>
3098 </tr>
3099 <tr>
3100 <td>1</td>
3101 <td>0</td>
3102 <td>0</td>
3103 </tr>
3104 <tr>
3105 <td>1</td>
3106 <td>1</td>
3107 <td>1</td>
3108 </tr>
3109 </tbody>
3110</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00003111</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003112<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003113<pre>
3114 &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003115 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
3116 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003117</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003118</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003119<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003120<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00003121<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00003122<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00003123<pre> &lt;result&gt; = or &lt;ty&gt; &lt;op1&gt;, &lt;op2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003124</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00003125<h5>Overview:</h5>
3126<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
3127or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003128<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003129
3130<p>The two arguments to the '<tt>or</tt>' instruction must be
3131<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3132values. Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003133<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003134<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003135<p> </p>
Bill Wendling5703c6e2008-09-07 10:29:20 +00003136<div>
Chris Lattner48b383b02003-11-25 01:02:51 +00003137<table border="1" cellspacing="0" cellpadding="4">
3138 <tbody>
3139 <tr>
3140 <td>In0</td>
3141 <td>In1</td>
3142 <td>Out</td>
3143 </tr>
3144 <tr>
3145 <td>0</td>
3146 <td>0</td>
3147 <td>0</td>
3148 </tr>
3149 <tr>
3150 <td>0</td>
3151 <td>1</td>
3152 <td>1</td>
3153 </tr>
3154 <tr>
3155 <td>1</td>
3156 <td>0</td>
3157 <td>1</td>
3158 </tr>
3159 <tr>
3160 <td>1</td>
3161 <td>1</td>
3162 <td>1</td>
3163 </tr>
3164 </tbody>
3165</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00003166</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003167<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003168<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
3169 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
3170 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003171</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003172</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003173<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003174<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
3175Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00003176<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00003177<h5>Syntax:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00003178<pre> &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 +00003179</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003180<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00003181<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
3182or of its two operands. The <tt>xor</tt> is used to implement the
3183"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003184<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003185<p>The two arguments to the '<tt>xor</tt>' instruction must be
3186<a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer
3187values. Both arguments must have identical types.</p>
3188
Chris Lattner2f7c9632001-06-06 20:29:01 +00003189<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00003190
Misha Brukman76307852003-11-08 01:05:38 +00003191<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003192<p> </p>
Bill Wendling5703c6e2008-09-07 10:29:20 +00003193<div>
Chris Lattner48b383b02003-11-25 01:02:51 +00003194<table border="1" cellspacing="0" cellpadding="4">
3195 <tbody>
3196 <tr>
3197 <td>In0</td>
3198 <td>In1</td>
3199 <td>Out</td>
3200 </tr>
3201 <tr>
3202 <td>0</td>
3203 <td>0</td>
3204 <td>0</td>
3205 </tr>
3206 <tr>
3207 <td>0</td>
3208 <td>1</td>
3209 <td>1</td>
3210 </tr>
3211 <tr>
3212 <td>1</td>
3213 <td>0</td>
3214 <td>1</td>
3215 </tr>
3216 <tr>
3217 <td>1</td>
3218 <td>1</td>
3219 <td>0</td>
3220 </tr>
3221 </tbody>
3222</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00003223</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00003224<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003225<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003226<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
3227 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
3228 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
3229 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003230</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003231</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003232
Chris Lattner2f7c9632001-06-06 20:29:01 +00003233<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00003234<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00003235 <a name="vectorops">Vector Operations</a>
3236</div>
3237
3238<div class="doc_text">
3239
3240<p>LLVM supports several instructions to represent vector operations in a
Jeff Cohen5819f182007-04-22 01:17:39 +00003241target-independent manner. These instructions cover the element-access and
Chris Lattnerce83bff2006-04-08 23:07:04 +00003242vector-specific operations needed to process vectors effectively. While LLVM
3243does directly support these vector operations, many sophisticated algorithms
3244will want to use target-specific intrinsics to take full advantage of a specific
3245target.</p>
3246
3247</div>
3248
3249<!-- _______________________________________________________________________ -->
3250<div class="doc_subsubsection">
3251 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
3252</div>
3253
3254<div class="doc_text">
3255
3256<h5>Syntax:</h5>
3257
3258<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003259 &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 +00003260</pre>
3261
3262<h5>Overview:</h5>
3263
3264<p>
3265The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer404a3252007-02-15 03:07:05 +00003266element from a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00003267</p>
3268
3269
3270<h5>Arguments:</h5>
3271
3272<p>
3273The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00003274value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattnerce83bff2006-04-08 23:07:04 +00003275an index indicating the position from which to extract the element.
3276The index may be a variable.</p>
3277
3278<h5>Semantics:</h5>
3279
3280<p>
3281The result is a scalar of the same type as the element type of
3282<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
3283<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
3284results are undefined.
3285</p>
3286
3287<h5>Example:</h5>
3288
3289<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003290 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00003291</pre>
3292</div>
3293
3294
3295<!-- _______________________________________________________________________ -->
3296<div class="doc_subsubsection">
3297 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
3298</div>
3299
3300<div class="doc_text">
3301
3302<h5>Syntax:</h5>
3303
3304<pre>
Dan Gohman43ba0672008-05-12 23:38:42 +00003305 &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 +00003306</pre>
3307
3308<h5>Overview:</h5>
3309
3310<p>
3311The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer404a3252007-02-15 03:07:05 +00003312element into a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00003313</p>
3314
3315
3316<h5>Arguments:</h5>
3317
3318<p>
3319The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00003320value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattnerce83bff2006-04-08 23:07:04 +00003321scalar value whose type must equal the element type of the first
3322operand. The third operand is an index indicating the position at
3323which to insert the value. The index may be a variable.</p>
3324
3325<h5>Semantics:</h5>
3326
3327<p>
Reid Spencer404a3252007-02-15 03:07:05 +00003328The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattnerce83bff2006-04-08 23:07:04 +00003329element values are those of <tt>val</tt> except at position
3330<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
3331exceeds the length of <tt>val</tt>, the results are undefined.
3332</p>
3333
3334<h5>Example:</h5>
3335
3336<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003337 %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 +00003338</pre>
3339</div>
3340
3341<!-- _______________________________________________________________________ -->
3342<div class="doc_subsubsection">
3343 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
3344</div>
3345
3346<div class="doc_text">
3347
3348<h5>Syntax:</h5>
3349
3350<pre>
Mon P Wang25f01062008-11-10 04:46:22 +00003351 &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 +00003352</pre>
3353
3354<h5>Overview:</h5>
3355
3356<p>
3357The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
Mon P Wang25f01062008-11-10 04:46:22 +00003358from two input vectors, returning a vector with the same element type as
3359the input and length that is the same as the shuffle mask.
Chris Lattnerce83bff2006-04-08 23:07:04 +00003360</p>
3361
3362<h5>Arguments:</h5>
3363
3364<p>
Mon P Wang25f01062008-11-10 04:46:22 +00003365The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
3366with types that match each other. The third argument is a shuffle mask whose
3367element type is always 'i32'. The result of the instruction is a vector whose
3368length is the same as the shuffle mask and whose element type is the same as
3369the element type of the first two operands.
Chris Lattnerce83bff2006-04-08 23:07:04 +00003370</p>
3371
3372<p>
3373The shuffle mask operand is required to be a constant vector with either
3374constant integer or undef values.
3375</p>
3376
3377<h5>Semantics:</h5>
3378
3379<p>
3380The elements of the two input vectors are numbered from left to right across
3381both of the vectors. The shuffle mask operand specifies, for each element of
Mon P Wang25f01062008-11-10 04:46:22 +00003382the result vector, which element of the two input vectors the result element
Chris Lattnerce83bff2006-04-08 23:07:04 +00003383gets. The element selector may be undef (meaning "don't care") and the second
3384operand may be undef if performing a shuffle from only one vector.
3385</p>
3386
3387<h5>Example:</h5>
3388
3389<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003390 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen5819f182007-04-22 01:17:39 +00003391 &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 +00003392 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
3393 &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 +00003394 %result = shufflevector &lt;8 x i32&gt; %v1, &lt;8 x i32&gt; undef,
3395 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i>
3396 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
3397 &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 +00003398</pre>
3399</div>
3400
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00003401
Chris Lattnerce83bff2006-04-08 23:07:04 +00003402<!-- ======================================================================= -->
3403<div class="doc_subsection">
Dan Gohmanb9d66602008-05-12 23:51:09 +00003404 <a name="aggregateops">Aggregate Operations</a>
3405</div>
3406
3407<div class="doc_text">
3408
3409<p>LLVM supports several instructions for working with aggregate values.
3410</p>
3411
3412</div>
3413
3414<!-- _______________________________________________________________________ -->
3415<div class="doc_subsubsection">
3416 <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a>
3417</div>
3418
3419<div class="doc_text">
3420
3421<h5>Syntax:</h5>
3422
3423<pre>
3424 &lt;result&gt; = extractvalue &lt;aggregate type&gt; &lt;val&gt;, &lt;idx&gt;{, &lt;idx&gt;}*
3425</pre>
3426
3427<h5>Overview:</h5>
3428
3429<p>
Dan Gohman35a835c2008-05-13 18:16:06 +00003430The '<tt>extractvalue</tt>' instruction extracts the value of a struct field
3431or array element from an aggregate value.
Dan Gohmanb9d66602008-05-12 23:51:09 +00003432</p>
3433
3434
3435<h5>Arguments:</h5>
3436
3437<p>
3438The first operand of an '<tt>extractvalue</tt>' instruction is a
3439value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a>
Dan Gohman35a835c2008-05-13 18:16:06 +00003440type. The operands are constant indices to specify which value to extract
Dan Gohman1ecaf452008-05-31 00:58:22 +00003441in a similar manner as indices in a
Dan Gohmanb9d66602008-05-12 23:51:09 +00003442'<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.
3443</p>
3444
3445<h5>Semantics:</h5>
3446
3447<p>
3448The result is the value at the position in the aggregate specified by
3449the index operands.
3450</p>
3451
3452<h5>Example:</h5>
3453
3454<pre>
Dan Gohman1ecaf452008-05-31 00:58:22 +00003455 %result = extractvalue {i32, float} %agg, 0 <i>; yields i32</i>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003456</pre>
3457</div>
3458
3459
3460<!-- _______________________________________________________________________ -->
3461<div class="doc_subsubsection">
3462 <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a>
3463</div>
3464
3465<div class="doc_text">
3466
3467<h5>Syntax:</h5>
3468
3469<pre>
Dan Gohman1ecaf452008-05-31 00:58:22 +00003470 &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 +00003471</pre>
3472
3473<h5>Overview:</h5>
3474
3475<p>
3476The '<tt>insertvalue</tt>' instruction inserts a value
Dan Gohman35a835c2008-05-13 18:16:06 +00003477into a struct field or array element in an aggregate.
Dan Gohmanb9d66602008-05-12 23:51:09 +00003478</p>
3479
3480
3481<h5>Arguments:</h5>
3482
3483<p>
3484The first operand of an '<tt>insertvalue</tt>' instruction is a
3485value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type.
3486The second operand is a first-class value to insert.
Dan Gohman34d1c0d2008-05-23 21:53:15 +00003487The following operands are constant indices
Dan Gohman1ecaf452008-05-31 00:58:22 +00003488indicating the position at which to insert the value in a similar manner as
Dan Gohman35a835c2008-05-13 18:16:06 +00003489indices in a
Dan Gohmanb9d66602008-05-12 23:51:09 +00003490'<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction.
3491The value to insert must have the same type as the value identified
Dan Gohman35a835c2008-05-13 18:16:06 +00003492by the indices.
Dan Gohmanef9462f2008-10-14 16:51:45 +00003493</p>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003494
3495<h5>Semantics:</h5>
3496
3497<p>
3498The result is an aggregate of the same type as <tt>val</tt>. Its
3499value is that of <tt>val</tt> except that the value at the position
Dan Gohman35a835c2008-05-13 18:16:06 +00003500specified by the indices is that of <tt>elt</tt>.
Dan Gohmanb9d66602008-05-12 23:51:09 +00003501</p>
3502
3503<h5>Example:</h5>
3504
3505<pre>
Dan Gohman88ce1a52008-06-23 15:26:37 +00003506 %result = insertvalue {i32, float} %agg, i32 1, 0 <i>; yields {i32, float}</i>
Dan Gohmanb9d66602008-05-12 23:51:09 +00003507</pre>
3508</div>
3509
3510
3511<!-- ======================================================================= -->
3512<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00003513 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00003514</div>
3515
Misha Brukman76307852003-11-08 01:05:38 +00003516<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003517
Chris Lattner48b383b02003-11-25 01:02:51 +00003518<p>A key design point of an SSA-based representation is how it
3519represents memory. In LLVM, no memory locations are in SSA form, which
3520makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00003521allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003522
Misha Brukman76307852003-11-08 01:05:38 +00003523</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003524
Chris Lattner2f7c9632001-06-06 20:29:01 +00003525<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003526<div class="doc_subsubsection">
3527 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
3528</div>
3529
Misha Brukman76307852003-11-08 01:05:38 +00003530<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003531
Chris Lattner2f7c9632001-06-06 20:29:01 +00003532<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003533
3534<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003535 &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 +00003536</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003537
Chris Lattner2f7c9632001-06-06 20:29:01 +00003538<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003539
Chris Lattner48b383b02003-11-25 01:02:51 +00003540<p>The '<tt>malloc</tt>' instruction allocates memory from the system
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00003541heap and returns a pointer to it. The object is always allocated in the generic
3542address space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003543
Chris Lattner2f7c9632001-06-06 20:29:01 +00003544<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003545
3546<p>The '<tt>malloc</tt>' instruction allocates
3547<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00003548bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00003549appropriate type to the program. If "NumElements" is specified, it is the
Gabor Greifdd1fc982008-02-09 22:24:34 +00003550number of elements allocated, otherwise "NumElements" is defaulted to be one.
Duncan Sands2ae473f2009-06-20 13:26:06 +00003551If a constant alignment is specified, the value result of the allocation is
3552guaranteed to be aligned to at least that boundary. If not specified, or if
3553zero, the target can choose to align the allocation on any convenient boundary
3554compatible with the type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003555
Misha Brukman76307852003-11-08 01:05:38 +00003556<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003557
Chris Lattner2f7c9632001-06-06 20:29:01 +00003558<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003559
Chris Lattner48b383b02003-11-25 01:02:51 +00003560<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
Nick Lewyckyf5ffcbc2008-11-24 03:41:24 +00003561a pointer is returned. The result of a zero byte allocation is undefined. The
Chris Lattnerfe8519c2008-04-19 21:01:16 +00003562result is null if there is insufficient memory available.</p>
Misha Brukman76307852003-11-08 01:05:38 +00003563
Chris Lattner54611b42005-11-06 08:02:57 +00003564<h5>Example:</h5>
3565
3566<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003567 %array = malloc [4 x i8] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner54611b42005-11-06 08:02:57 +00003568
Bill Wendling2d8b9a82007-05-29 09:42:13 +00003569 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
3570 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
3571 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
3572 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
3573 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003574</pre>
Dan Gohman3065b612009-01-12 23:12:39 +00003575
3576<p>Note that the code generator does not yet respect the
3577 alignment value.</p>
3578
Misha Brukman76307852003-11-08 01:05:38 +00003579</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003580
Chris Lattner2f7c9632001-06-06 20:29:01 +00003581<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003582<div class="doc_subsubsection">
3583 <a name="i_free">'<tt>free</tt>' Instruction</a>
3584</div>
3585
Misha Brukman76307852003-11-08 01:05:38 +00003586<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003587
Chris Lattner2f7c9632001-06-06 20:29:01 +00003588<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003589
3590<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003591 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003592</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003593
Chris Lattner2f7c9632001-06-06 20:29:01 +00003594<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003595
Chris Lattner48b383b02003-11-25 01:02:51 +00003596<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00003597memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003598
Chris Lattner2f7c9632001-06-06 20:29:01 +00003599<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003600
Chris Lattner48b383b02003-11-25 01:02:51 +00003601<p>'<tt>value</tt>' shall be a pointer value that points to a value
3602that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
3603instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003604
Chris Lattner2f7c9632001-06-06 20:29:01 +00003605<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003606
John Criswelldfe6a862004-12-10 15:51:16 +00003607<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner0f103e12008-04-19 22:41:32 +00003608after this instruction executes. If the pointer is null, the operation
3609is a noop.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003610
Chris Lattner2f7c9632001-06-06 20:29:01 +00003611<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003612
3613<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003614 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003615 free [4 x i8]* %array
Chris Lattner2f7c9632001-06-06 20:29:01 +00003616</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003617</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003618
Chris Lattner2f7c9632001-06-06 20:29:01 +00003619<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00003620<div class="doc_subsubsection">
3621 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
3622</div>
3623
Misha Brukman76307852003-11-08 01:05:38 +00003624<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00003625
Chris Lattner2f7c9632001-06-06 20:29:01 +00003626<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003627
3628<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003629 &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 +00003630</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00003631
Chris Lattner2f7c9632001-06-06 20:29:01 +00003632<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003633
Jeff Cohen5819f182007-04-22 01:17:39 +00003634<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
3635currently executing function, to be automatically released when this function
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00003636returns to its caller. The object is always allocated in the generic address
3637space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003638
Chris Lattner2f7c9632001-06-06 20:29:01 +00003639<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003640
John Criswelldfe6a862004-12-10 15:51:16 +00003641<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00003642bytes of memory on the runtime stack, returning a pointer of the
Gabor Greifdd1fc982008-02-09 22:24:34 +00003643appropriate type to the program. If "NumElements" is specified, it is the
3644number of elements allocated, otherwise "NumElements" is defaulted to be one.
Duncan Sands2ae473f2009-06-20 13:26:06 +00003645If a constant alignment is specified, the value result of the allocation is
3646guaranteed to be aligned to at least that boundary. If not specified, or if
3647zero, the target can choose to align the allocation on any convenient boundary
3648compatible with the type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003649
Misha Brukman76307852003-11-08 01:05:38 +00003650<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003651
Chris Lattner2f7c9632001-06-06 20:29:01 +00003652<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003653
Bill Wendling9ee6a312009-05-08 20:49:29 +00003654<p>Memory is allocated; a pointer is returned. The operation is undefined if
Chris Lattnerfe8519c2008-04-19 21:01:16 +00003655there is insufficient stack space for the allocation. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00003656memory is automatically released when the function returns. The '<tt>alloca</tt>'
3657instruction is commonly used to represent automatic variables that must
3658have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00003659 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Chris Lattner1f17cce2008-04-02 00:38:26 +00003660instructions), the memory is reclaimed. Allocating zero bytes
3661is legal, but the result is undefined.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00003662
Chris Lattner2f7c9632001-06-06 20:29:01 +00003663<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00003664
3665<pre>
Dan Gohman7a5acb52009-01-04 23:49:44 +00003666 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
3667 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
3668 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
3669 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00003670</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003671</div>
Chris Lattner54611b42005-11-06 08:02:57 +00003672
Chris Lattner2f7c9632001-06-06 20:29:01 +00003673<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003674<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
3675Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00003676<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00003677<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00003678<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;]<br></pre>
Chris Lattner095735d2002-05-06 03:03:22 +00003679<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003680<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00003681<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00003682<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00003683address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00003684 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00003685marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00003686the number or order of execution of this <tt>load</tt> with other
3687volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
3688instructions. </p>
Chris Lattner2a1993f2008-01-06 21:04:43 +00003689<p>
Chris Lattner1f17cce2008-04-02 00:38:26 +00003690The optional constant "align" argument specifies the alignment of the operation
Chris Lattner2a1993f2008-01-06 21:04:43 +00003691(that is, the alignment of the memory address). A value of 0 or an
3692omitted "align" argument means that the operation has the preferential
3693alignment for the target. It is the responsibility of the code emitter
3694to ensure that the alignment information is correct. Overestimating
3695the alignment results in an undefined behavior. Underestimating the
3696alignment may produce less efficient code. An alignment of 1 is always
3697safe.
3698</p>
Chris Lattner095735d2002-05-06 03:03:22 +00003699<h5>Semantics:</h5>
Duncan Sandsb1656c12009-03-22 11:33:16 +00003700<p>The location of memory pointed to is loaded. If the value being loaded
3701is of scalar type then the number of bytes read does not exceed the minimum
3702number of bytes needed to hold all bits of the type. For example, loading an
3703<tt>i24</tt> reads at most three bytes. When loading a value of a type like
3704<tt>i20</tt> with a size that is not an integral number of bytes, the result
3705is undefined if the value was not originally written using a store of the
3706same type.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00003707<h5>Examples:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003708<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00003709 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003710 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
3711 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00003712</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003713</div>
Chris Lattner095735d2002-05-06 03:03:22 +00003714<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003715<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
3716Instruction</a> </div>
Reid Spencera89fb182006-11-09 21:18:01 +00003717<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00003718<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00003719<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
3720 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 +00003721</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00003722<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003723<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00003724<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00003725<p>There are two arguments to the '<tt>store</tt>' instruction: a value
Jeff Cohen5819f182007-04-22 01:17:39 +00003726to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner1f17cce2008-04-02 00:38:26 +00003727operand must be a pointer to the <a href="#t_firstclass">first class</a> type
3728of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00003729operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00003730optimizer is not allowed to modify the number or order of execution of
3731this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
3732 href="#i_store">store</a></tt> instructions.</p>
Chris Lattner2a1993f2008-01-06 21:04:43 +00003733<p>
Chris Lattner1f17cce2008-04-02 00:38:26 +00003734The optional constant "align" argument specifies the alignment of the operation
Chris Lattner2a1993f2008-01-06 21:04:43 +00003735(that is, the alignment of the memory address). A value of 0 or an
3736omitted "align" argument means that the operation has the preferential
3737alignment for the target. It is the responsibility of the code emitter
3738to ensure that the alignment information is correct. Overestimating
3739the alignment results in an undefined behavior. Underestimating the
3740alignment may produce less efficient code. An alignment of 1 is always
3741safe.
3742</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003743<h5>Semantics:</h5>
3744<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
Duncan Sandsb1656c12009-03-22 11:33:16 +00003745at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.
3746If '<tt>&lt;value&gt;</tt>' is of scalar type then the number of bytes
3747written does not exceed the minimum number of bytes needed to hold all
3748bits of the type. For example, storing an <tt>i24</tt> writes at most
3749three bytes. When writing a value of a type like <tt>i20</tt> with a
3750size that is not an integral number of bytes, it is unspecified what
3751happens to the extra bits that do not belong to the type, but they will
3752typically be overwritten.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00003753<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003754<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling8830ffe2007-10-22 05:10:05 +00003755 store i32 3, i32* %ptr <i>; yields {void}</i>
3756 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00003757</pre>
Reid Spencer443460a2006-11-09 21:15:49 +00003758</div>
3759
Chris Lattner095735d2002-05-06 03:03:22 +00003760<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00003761<div class="doc_subsubsection">
3762 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3763</div>
3764
Misha Brukman76307852003-11-08 01:05:38 +00003765<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00003766<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003767<pre>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003768 &lt;result&gt; = getelementptr &lt;pty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
Chris Lattner33fd7022004-04-05 01:30:49 +00003769</pre>
3770
Chris Lattner590645f2002-04-14 06:13:44 +00003771<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003772
3773<p>
3774The '<tt>getelementptr</tt>' instruction is used to get the address of a
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003775subelement of an aggregate data structure. It performs address calculation only
3776and does not access memory.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003777
Chris Lattner590645f2002-04-14 06:13:44 +00003778<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003779
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003780<p>The first argument is always a pointer, and forms the basis of the
3781calculation. The remaining arguments are indices, that indicate which of the
3782elements of the aggregate object are indexed. The interpretation of each index
3783is dependent on the type being indexed into. The first index always indexes the
3784pointer value given as the first argument, the second index indexes a value of
3785the type pointed to (not necessarily the value directly pointed to, since the
3786first index can be non-zero), etc. The first type indexed into must be a pointer
3787value, subsequent types can be arrays, vectors and structs. Note that subsequent
3788types being indexed into can never be pointers, since that would require loading
3789the pointer before continuing calculation.</p>
3790
3791<p>The type of each index argument depends on the type it is indexing into.
3792When indexing into a (packed) structure, only <tt>i32</tt> integer
3793<b>constants</b> are allowed. When indexing into an array, pointer or vector,
Sanjiv Gupta1f8555a2009-04-27 03:21:00 +00003794integers of any width are allowed (also non-constants).</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003795
Chris Lattner48b383b02003-11-25 01:02:51 +00003796<p>For example, let's consider a C code fragment and how it gets
3797compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003798
Bill Wendling3716c5d2007-05-29 09:04:49 +00003799<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00003800<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003801struct RT {
3802 char A;
Chris Lattnera446f1b2007-05-29 15:43:56 +00003803 int B[10][20];
Bill Wendling3716c5d2007-05-29 09:04:49 +00003804 char C;
3805};
3806struct ST {
Chris Lattnera446f1b2007-05-29 15:43:56 +00003807 int X;
Bill Wendling3716c5d2007-05-29 09:04:49 +00003808 double Y;
3809 struct RT Z;
3810};
Chris Lattner33fd7022004-04-05 01:30:49 +00003811
Chris Lattnera446f1b2007-05-29 15:43:56 +00003812int *foo(struct ST *s) {
Bill Wendling3716c5d2007-05-29 09:04:49 +00003813 return &amp;s[1].Z.B[5][13];
3814}
Chris Lattner33fd7022004-04-05 01:30:49 +00003815</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003816</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003817
Misha Brukman76307852003-11-08 01:05:38 +00003818<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003819
Bill Wendling3716c5d2007-05-29 09:04:49 +00003820<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00003821<pre>
Chris Lattnerbc088212009-01-11 20:53:49 +00003822%RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 }
3823%ST = <a href="#namedtypes">type</a> { i32, double, %RT }
Chris Lattner33fd7022004-04-05 01:30:49 +00003824
Bill Wendling3716c5d2007-05-29 09:04:49 +00003825define i32* %foo(%ST* %s) {
3826entry:
3827 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3828 ret i32* %reg
3829}
Chris Lattner33fd7022004-04-05 01:30:49 +00003830</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003831</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003832
Chris Lattner590645f2002-04-14 06:13:44 +00003833<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003834
Misha Brukman76307852003-11-08 01:05:38 +00003835<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003836type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattner33fd7022004-04-05 01:30:49 +00003837}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003838the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3839i8 }</tt>' type, another structure. The third index indexes into the second
3840element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattner33fd7022004-04-05 01:30:49 +00003841array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003842'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
3843to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003844
Chris Lattner48b383b02003-11-25 01:02:51 +00003845<p>Note that it is perfectly legal to index partially through a
3846structure, returning a pointer to an inner element. Because of this,
3847the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003848
3849<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003850 define i32* %foo(%ST* %s) {
3851 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen5819f182007-04-22 01:17:39 +00003852 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3853 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003854 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3855 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3856 ret i32* %t5
Chris Lattner33fd7022004-04-05 01:30:49 +00003857 }
Chris Lattnera8292f32002-05-06 22:08:29 +00003858</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003859
Chris Lattnerdd282822009-03-09 20:55:18 +00003860<p>Note that it is undefined to access an array out of bounds: array
3861and pointer indexes must always be within the defined bounds of the
3862array type when accessed with an instruction that dereferences the
3863pointer (e.g. a load or store instruction). The one exception for
3864this rule is zero length arrays. These arrays are defined to be
3865accessible as variable length arrays, which requires access beyond the
3866zero'th element.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003867
Chris Lattner6ab66722006-08-15 00:45:58 +00003868<p>The getelementptr instruction is often confusing. For some more insight
3869into how it works, see <a href="GetElementPtr.html">the getelementptr
3870FAQ</a>.</p>
3871
Chris Lattner590645f2002-04-14 06:13:44 +00003872<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003873
Chris Lattner33fd7022004-04-05 01:30:49 +00003874<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003875 <i>; yields [12 x i8]*:aptr</i>
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003876 %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1
3877 <i>; yields i8*:vptr</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00003878 %vptr = getelementptr {i32, &lt;2 x i8&gt;}* %svptr, i64 0, i32 1, i32 1
Matthijs Kooijman0e268272008-10-13 13:44:15 +00003879 <i>; yields i8*:eptr</i>
3880 %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1
Sanjiv Gupta0c155e62009-04-25 07:27:44 +00003881 <i>; yields i32*:iptr</i>
Sanjiv Gupta77abea02009-04-24 16:38:13 +00003882 %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0
Chris Lattner33fd7022004-04-05 01:30:49 +00003883</pre>
Chris Lattner33fd7022004-04-05 01:30:49 +00003884</div>
Reid Spencer443460a2006-11-09 21:15:49 +00003885
Chris Lattner2f7c9632001-06-06 20:29:01 +00003886<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00003887<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00003888</div>
Misha Brukman76307852003-11-08 01:05:38 +00003889<div class="doc_text">
Reid Spencer97c5fa42006-11-08 01:18:52 +00003890<p>The instructions in this category are the conversion instructions (casting)
3891which all take a single operand and a type. They perform various bit conversions
3892on the operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00003893</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003894
Chris Lattnera8292f32002-05-06 22:08:29 +00003895<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003896<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003897 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3898</div>
3899<div class="doc_text">
3900
3901<h5>Syntax:</h5>
3902<pre>
3903 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3904</pre>
3905
3906<h5>Overview:</h5>
3907<p>
3908The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
3909</p>
3910
3911<h5>Arguments:</h5>
3912<p>
3913The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3914be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003915and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencer51b07252006-11-09 23:03:26 +00003916type. The bit size of <tt>value</tt> must be larger than the bit size of
3917<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003918
3919<h5>Semantics:</h5>
3920<p>
3921The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencer51b07252006-11-09 23:03:26 +00003922and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
3923larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
3924It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003925
3926<h5>Example:</h5>
3927<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003928 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003929 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3930 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003931</pre>
3932</div>
3933
3934<!-- _______________________________________________________________________ -->
3935<div class="doc_subsubsection">
3936 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3937</div>
3938<div class="doc_text">
3939
3940<h5>Syntax:</h5>
3941<pre>
3942 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3943</pre>
3944
3945<h5>Overview:</h5>
3946<p>The '<tt>zext</tt>' instruction zero extends its operand to type
3947<tt>ty2</tt>.</p>
3948
3949
3950<h5>Arguments:</h5>
3951<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003952<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3953also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00003954<tt>value</tt> must be smaller than the bit size of the destination type,
3955<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003956
3957<h5>Semantics:</h5>
3958<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Chris Lattnerc87f3df2007-05-24 19:13:27 +00003959bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003960
Reid Spencer07c9c682007-01-12 15:46:11 +00003961<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003962
3963<h5>Example:</h5>
3964<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003965 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003966 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003967</pre>
3968</div>
3969
3970<!-- _______________________________________________________________________ -->
3971<div class="doc_subsubsection">
3972 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
3973</div>
3974<div class="doc_text">
3975
3976<h5>Syntax:</h5>
3977<pre>
3978 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3979</pre>
3980
3981<h5>Overview:</h5>
3982<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
3983
3984<h5>Arguments:</h5>
3985<p>
3986The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003987<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3988also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00003989<tt>value</tt> must be smaller than the bit size of the destination type,
3990<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003991
3992<h5>Semantics:</h5>
3993<p>
3994The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
3995bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
Chris Lattnerc87f3df2007-05-24 19:13:27 +00003996the type <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003997
Reid Spencer36a15422007-01-12 03:35:51 +00003998<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003999
4000<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004001<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004002 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencer36a15422007-01-12 03:35:51 +00004003 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004004</pre>
4005</div>
4006
4007<!-- _______________________________________________________________________ -->
4008<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00004009 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
4010</div>
4011
4012<div class="doc_text">
4013
4014<h5>Syntax:</h5>
4015
4016<pre>
4017 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4018</pre>
4019
4020<h5>Overview:</h5>
4021<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
4022<tt>ty2</tt>.</p>
4023
4024
4025<h5>Arguments:</h5>
4026<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
4027 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
4028cast it to. The size of <tt>value</tt> must be larger than the size of
4029<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
4030<i>no-op cast</i>.</p>
4031
4032<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004033<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
4034<a href="#t_floating">floating point</a> type to a smaller
4035<a href="#t_floating">floating point</a> type. If the value cannot fit within
4036the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00004037
4038<h5>Example:</h5>
4039<pre>
4040 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
4041 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
4042</pre>
4043</div>
4044
4045<!-- _______________________________________________________________________ -->
4046<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004047 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
4048</div>
4049<div class="doc_text">
4050
4051<h5>Syntax:</h5>
4052<pre>
4053 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4054</pre>
4055
4056<h5>Overview:</h5>
4057<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
4058floating point value.</p>
4059
4060<h5>Arguments:</h5>
4061<p>The '<tt>fpext</tt>' instruction takes a
4062<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencer51b07252006-11-09 23:03:26 +00004063and a <a href="#t_floating">floating point</a> type to cast it to. The source
4064type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004065
4066<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004067<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Duncan Sands16f122e2007-03-30 12:22:09 +00004068<a href="#t_floating">floating point</a> type to a larger
4069<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
Reid Spencer51b07252006-11-09 23:03:26 +00004070used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5b950642006-11-11 23:08:07 +00004071<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004072
4073<h5>Example:</h5>
4074<pre>
4075 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
4076 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
4077</pre>
4078</div>
4079
4080<!-- _______________________________________________________________________ -->
4081<div class="doc_subsubsection">
Reid Spencer2eadb532007-01-21 00:29:26 +00004082 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004083</div>
4084<div class="doc_text">
4085
4086<h5>Syntax:</h5>
4087<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00004088 &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 +00004089</pre>
4090
4091<h5>Overview:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00004092<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004093unsigned integer equivalent of type <tt>ty2</tt>.
4094</p>
4095
4096<h5>Arguments:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00004097<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
Nate Begemand4d45c22007-11-17 03:58:34 +00004098scalar or vector <a href="#t_floating">floating point</a> value, and a type
4099to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4100type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4101vector integer type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004102
4103<h5>Semantics:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00004104<p> The '<tt>fptoui</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004105<a href="#t_floating">floating point</a> operand into the nearest (rounding
4106towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
4107the results are undefined.</p>
4108
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004109<h5>Example:</h5>
4110<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00004111 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00004112 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencer753163d2007-07-31 14:40:14 +00004113 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004114</pre>
4115</div>
4116
4117<!-- _______________________________________________________________________ -->
4118<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004119 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004120</div>
4121<div class="doc_text">
4122
4123<h5>Syntax:</h5>
4124<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004125 &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 +00004126</pre>
4127
4128<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004129<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004130<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004131</p>
4132
Chris Lattnera8292f32002-05-06 22:08:29 +00004133<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004134<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Nate Begemand4d45c22007-11-17 03:58:34 +00004135scalar or vector <a href="#t_floating">floating point</a> value, and a type
4136to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
4137type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
4138vector integer type with the same number of elements as <tt>ty</tt></p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004139
Chris Lattnera8292f32002-05-06 22:08:29 +00004140<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004141<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004142<a href="#t_floating">floating point</a> operand into the nearest (rounding
4143towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
4144the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004145
Chris Lattner70de6632001-07-09 00:26:23 +00004146<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004147<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00004148 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00004149 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004150 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004151</pre>
4152</div>
4153
4154<!-- _______________________________________________________________________ -->
4155<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004156 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004157</div>
4158<div class="doc_text">
4159
4160<h5>Syntax:</h5>
4161<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004162 &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 +00004163</pre>
4164
4165<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004166<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004167integer and converts that value to the <tt>ty2</tt> type.</p>
4168
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004169<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00004170<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
4171scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
4172to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4173type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4174floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004175
4176<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004177<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004178integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00004179the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004180
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004181<h5>Example:</h5>
4182<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004183 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004184 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004185</pre>
4186</div>
4187
4188<!-- _______________________________________________________________________ -->
4189<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00004190 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004191</div>
4192<div class="doc_text">
4193
4194<h5>Syntax:</h5>
4195<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00004196 &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 +00004197</pre>
4198
4199<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004200<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004201integer and converts that value to the <tt>ty2</tt> type.</p>
4202
4203<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00004204<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
4205scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
4206to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
4207type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
4208floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004209
4210<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00004211<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004212integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00004213the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004214
4215<h5>Example:</h5>
4216<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004217 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004218 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004219</pre>
4220</div>
4221
4222<!-- _______________________________________________________________________ -->
4223<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00004224 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
4225</div>
4226<div class="doc_text">
4227
4228<h5>Syntax:</h5>
4229<pre>
4230 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4231</pre>
4232
4233<h5>Overview:</h5>
4234<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
4235the integer type <tt>ty2</tt>.</p>
4236
4237<h5>Arguments:</h5>
4238<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
Duncan Sands16f122e2007-03-30 12:22:09 +00004239must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Dan Gohmanef9462f2008-10-14 16:51:45 +00004240<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004241
4242<h5>Semantics:</h5>
4243<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
4244<tt>ty2</tt> by interpreting the pointer value as an integer and either
4245truncating or zero extending that value to the size of the integer type. If
4246<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
4247<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
Jeff Cohen222a8a42007-04-29 01:07:00 +00004248are the same size, then nothing is done (<i>no-op cast</i>) other than a type
4249change.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004250
4251<h5>Example:</h5>
4252<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004253 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
4254 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004255</pre>
4256</div>
4257
4258<!-- _______________________________________________________________________ -->
4259<div class="doc_subsubsection">
4260 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
4261</div>
4262<div class="doc_text">
4263
4264<h5>Syntax:</h5>
4265<pre>
4266 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
4267</pre>
4268
4269<h5>Overview:</h5>
4270<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
4271a pointer type, <tt>ty2</tt>.</p>
4272
4273<h5>Arguments:</h5>
Duncan Sands16f122e2007-03-30 12:22:09 +00004274<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004275value to cast, and a type to cast it to, which must be a
Dan Gohmanef9462f2008-10-14 16:51:45 +00004276<a href="#t_pointer">pointer</a> type.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004277
4278<h5>Semantics:</h5>
4279<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
4280<tt>ty2</tt> by applying either a zero extension or a truncation depending on
4281the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
4282size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
4283the size of a pointer then a zero extension is done. If they are the same size,
4284nothing is done (<i>no-op cast</i>).</p>
4285
4286<h5>Example:</h5>
4287<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004288 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
4289 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
4290 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00004291</pre>
4292</div>
4293
4294<!-- _______________________________________________________________________ -->
4295<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00004296 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004297</div>
4298<div class="doc_text">
4299
4300<h5>Syntax:</h5>
4301<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00004302 &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 +00004303</pre>
4304
4305<h5>Overview:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004306
Reid Spencer5b950642006-11-11 23:08:07 +00004307<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004308<tt>ty2</tt> without changing any bits.</p>
4309
4310<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004311
Reid Spencer5b950642006-11-11 23:08:07 +00004312<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Dan Gohmanc05dca92008-09-08 16:45:59 +00004313a non-aggregate first class value, and a type to cast it to, which must also be
4314a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes of
4315<tt>value</tt>
Reid Spencere3db84c2007-01-09 20:08:58 +00004316and the destination type, <tt>ty2</tt>, must be identical. If the source
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004317type is a pointer, the destination type must also be a pointer. This
4318instruction supports bitwise conversion of vectors to integers and to vectors
4319of other types (as long as they have the same size).</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004320
4321<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00004322<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencerb7344ff2006-11-11 21:00:47 +00004323<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
4324this conversion. The conversion is done as if the <tt>value</tt> had been
4325stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
4326converted to other pointer types with this instruction. To convert pointers to
4327other types, use the <a href="#i_inttoptr">inttoptr</a> or
4328<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00004329
4330<h5>Example:</h5>
4331<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004332 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004333 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004334 %Z = bitcast &lt;2 x int&gt; %V to i64; <i>; yields i64: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00004335</pre>
Misha Brukman76307852003-11-08 01:05:38 +00004336</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004337
Reid Spencer97c5fa42006-11-08 01:18:52 +00004338<!-- ======================================================================= -->
4339<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
4340<div class="doc_text">
4341<p>The instructions in this category are the "miscellaneous"
4342instructions, which defy better classification.</p>
4343</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004344
4345<!-- _______________________________________________________________________ -->
4346<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
4347</div>
4348<div class="doc_text">
4349<h5>Syntax:</h5>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004350<pre> &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 +00004351</pre>
4352<h5>Overview:</h5>
Dan Gohmanc579d972008-09-09 01:02:47 +00004353<p>The '<tt>icmp</tt>' instruction returns a boolean value or
4354a vector of boolean values based on comparison
4355of its two integer, integer vector, or pointer operands.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004356<h5>Arguments:</h5>
4357<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Jeff Cohen222a8a42007-04-29 01:07:00 +00004358the condition code indicating the kind of comparison to perform. It is not
4359a value, just a keyword. The possible condition code are:
Dan Gohmanef9462f2008-10-14 16:51:45 +00004360</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004361<ol>
4362 <li><tt>eq</tt>: equal</li>
4363 <li><tt>ne</tt>: not equal </li>
4364 <li><tt>ugt</tt>: unsigned greater than</li>
4365 <li><tt>uge</tt>: unsigned greater or equal</li>
4366 <li><tt>ult</tt>: unsigned less than</li>
4367 <li><tt>ule</tt>: unsigned less or equal</li>
4368 <li><tt>sgt</tt>: signed greater than</li>
4369 <li><tt>sge</tt>: signed greater or equal</li>
4370 <li><tt>slt</tt>: signed less than</li>
4371 <li><tt>sle</tt>: signed less or equal</li>
4372</ol>
Chris Lattnerc0f423a2007-01-15 01:54:13 +00004373<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Dan Gohmanc579d972008-09-09 01:02:47 +00004374<a href="#t_pointer">pointer</a>
4375or integer <a href="#t_vector">vector</a> typed.
4376They must also be identical types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004377<h5>Semantics:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00004378<p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to
Reid Spencerc828a0e2006-11-18 21:50:54 +00004379the condition code given as <tt>cond</tt>. The comparison performed always
Dan Gohmanc579d972008-09-09 01:02:47 +00004380yields either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt> result, as follows:
Dan Gohmanef9462f2008-10-14 16:51:45 +00004381</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004382<ol>
4383 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
4384 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
4385 </li>
4386 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
Dan Gohmanef9462f2008-10-14 16:51:45 +00004387 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004388 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004389 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004390 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004391 <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004392 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004393 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004394 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004395 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004396 <li><tt>sgt</tt>: interprets the operands as signed values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004397 <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004398 <li><tt>sge</tt>: interprets the operands as signed values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004399 <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004400 <li><tt>slt</tt>: interprets the operands as signed values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004401 <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004402 <li><tt>sle</tt>: interprets the operands as signed values and yields
Gabor Greif0f75ad02008-08-07 21:46:00 +00004403 <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004404</ol>
4405<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Jeff Cohen222a8a42007-04-29 01:07:00 +00004406values are compared as if they were integers.</p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004407<p>If the operands are integer vectors, then they are compared
4408element by element. The result is an <tt>i1</tt> vector with
4409the same number of elements as the values being compared.
4410Otherwise, the result is an <tt>i1</tt>.
4411</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004412
4413<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004414<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
4415 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
4416 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
4417 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
4418 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
4419 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004420</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004421
4422<p>Note that the code generator does not yet support vector types with
4423 the <tt>icmp</tt> instruction.</p>
4424
Reid Spencerc828a0e2006-11-18 21:50:54 +00004425</div>
4426
4427<!-- _______________________________________________________________________ -->
4428<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
4429</div>
4430<div class="doc_text">
4431<h5>Syntax:</h5>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004432<pre> &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 +00004433</pre>
4434<h5>Overview:</h5>
Dan Gohmanc579d972008-09-09 01:02:47 +00004435<p>The '<tt>fcmp</tt>' instruction returns a boolean value
4436or vector of boolean values based on comparison
Dan Gohmanef9462f2008-10-14 16:51:45 +00004437of its operands.</p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004438<p>
4439If the operands are floating point scalars, then the result
4440type is a boolean (<a href="#t_primitive"><tt>i1</tt></a>).
4441</p>
4442<p>If the operands are floating point vectors, then the result type
4443is a vector of boolean with the same number of elements as the
4444operands being compared.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004445<h5>Arguments:</h5>
4446<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Jeff Cohen222a8a42007-04-29 01:07:00 +00004447the condition code indicating the kind of comparison to perform. It is not
Dan Gohmanef9462f2008-10-14 16:51:45 +00004448a value, just a keyword. The possible condition code are:</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004449<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00004450 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004451 <li><tt>oeq</tt>: ordered and equal</li>
4452 <li><tt>ogt</tt>: ordered and greater than </li>
4453 <li><tt>oge</tt>: ordered and greater than or equal</li>
4454 <li><tt>olt</tt>: ordered and less than </li>
4455 <li><tt>ole</tt>: ordered and less than or equal</li>
4456 <li><tt>one</tt>: ordered and not equal</li>
4457 <li><tt>ord</tt>: ordered (no nans)</li>
4458 <li><tt>ueq</tt>: unordered or equal</li>
4459 <li><tt>ugt</tt>: unordered or greater than </li>
4460 <li><tt>uge</tt>: unordered or greater than or equal</li>
4461 <li><tt>ult</tt>: unordered or less than </li>
4462 <li><tt>ule</tt>: unordered or less than or equal</li>
4463 <li><tt>une</tt>: unordered or not equal</li>
4464 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004465 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004466</ol>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004467<p><i>Ordered</i> means that neither operand is a QNAN while
Reid Spencer02e0d1d2006-12-06 07:08:07 +00004468<i>unordered</i> means that either operand may be a QNAN.</p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004469<p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be
4470either a <a href="#t_floating">floating point</a> type
4471or a <a href="#t_vector">vector</a> of floating point type.
4472They must have identical types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004473<h5>Semantics:</h5>
Gabor Greif0f75ad02008-08-07 21:46:00 +00004474<p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt>
Dan Gohmanc579d972008-09-09 01:02:47 +00004475according to the condition code given as <tt>cond</tt>.
4476If the operands are vectors, then the vectors are compared
4477element by element.
4478Each comparison performed
Dan Gohmanef9462f2008-10-14 16:51:45 +00004479always yields an <a href="#t_primitive">i1</a> result, as follows:</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004480<ol>
4481 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004482 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004483 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004484 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004485 <tt>op1</tt> is greather than <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004486 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004487 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004488 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004489 <tt>op1</tt> is less than <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004490 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004491 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004492 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Gabor Greif0f75ad02008-08-07 21:46:00 +00004493 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004494 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
4495 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004496 <tt>op1</tt> is equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004497 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004498 <tt>op1</tt> is greater than <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004499 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004500 <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004501 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004502 <tt>op1</tt> is less than <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004503 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004504 <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004505 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Gabor Greif0f75ad02008-08-07 21:46:00 +00004506 <tt>op1</tt> is not equal to <tt>op2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00004507 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004508 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
4509</ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004510
4511<h5>Example:</h5>
4512<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
Dan Gohmanc579d972008-09-09 01:02:47 +00004513 &lt;result&gt; = fcmp one float 4.0, 5.0 <i>; yields: result=true</i>
4514 &lt;result&gt; = fcmp olt float 4.0, 5.0 <i>; yields: result=true</i>
4515 &lt;result&gt; = fcmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00004516</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004517
4518<p>Note that the code generator does not yet support vector types with
4519 the <tt>fcmp</tt> instruction.</p>
4520
Reid Spencerc828a0e2006-11-18 21:50:54 +00004521</div>
4522
Reid Spencer97c5fa42006-11-08 01:18:52 +00004523<!-- _______________________________________________________________________ -->
Nate Begemand2195702008-05-12 19:01:56 +00004524<div class="doc_subsubsection">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004525 <a name="i_phi">'<tt>phi</tt>' Instruction</a>
4526</div>
4527
Reid Spencer97c5fa42006-11-08 01:18:52 +00004528<div class="doc_text">
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004529
Reid Spencer97c5fa42006-11-08 01:18:52 +00004530<h5>Syntax:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004531
Reid Spencer97c5fa42006-11-08 01:18:52 +00004532<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
4533<h5>Overview:</h5>
4534<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
4535the SSA graph representing the function.</p>
4536<h5>Arguments:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004537
Jeff Cohen222a8a42007-04-29 01:07:00 +00004538<p>The type of the incoming values is specified with the first type
Reid Spencer97c5fa42006-11-08 01:18:52 +00004539field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
4540as arguments, with one pair for each predecessor basic block of the
4541current block. Only values of <a href="#t_firstclass">first class</a>
4542type may be used as the value arguments to the PHI node. Only labels
4543may be used as the label arguments.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004544
Reid Spencer97c5fa42006-11-08 01:18:52 +00004545<p>There must be no non-phi instructions between the start of a basic
4546block and the PHI instructions: i.e. PHI instructions must be first in
4547a basic block.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004548
Jay Foad1a4eea52009-06-03 10:20:10 +00004549<p>For the purposes of the SSA form, the use of each incoming value is
4550deemed to occur on the edge from the corresponding predecessor block
4551to the current block (but after any definition of an '<tt>invoke</tt>'
4552instruction's return value on the same edge).</p>
4553
Reid Spencer97c5fa42006-11-08 01:18:52 +00004554<h5>Semantics:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004555
Jeff Cohen222a8a42007-04-29 01:07:00 +00004556<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
4557specified by the pair corresponding to the predecessor basic block that executed
4558just prior to the current block.</p>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004559
Reid Spencer97c5fa42006-11-08 01:18:52 +00004560<h5>Example:</h5>
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004561<pre>
4562Loop: ; Infinite loop that counts from 0 on up...
4563 %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]
4564 %nextindvar = add i32 %indvar, 1
4565 br label %Loop
4566</pre>
Reid Spencer97c5fa42006-11-08 01:18:52 +00004567</div>
4568
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004569<!-- _______________________________________________________________________ -->
4570<div class="doc_subsubsection">
4571 <a name="i_select">'<tt>select</tt>' Instruction</a>
4572</div>
4573
4574<div class="doc_text">
4575
4576<h5>Syntax:</h5>
4577
4578<pre>
Dan Gohmanc579d972008-09-09 01:02:47 +00004579 &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>
4580
Dan Gohmanef9462f2008-10-14 16:51:45 +00004581 <i>selty</i> is either i1 or {&lt;N x i1&gt;}
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004582</pre>
4583
4584<h5>Overview:</h5>
4585
4586<p>
4587The '<tt>select</tt>' instruction is used to choose one value based on a
4588condition, without branching.
4589</p>
4590
4591
4592<h5>Arguments:</h5>
4593
4594<p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004595The '<tt>select</tt>' instruction requires an 'i1' value or
4596a vector of 'i1' values indicating the
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004597condition, and two values of the same <a href="#t_firstclass">first class</a>
Dan Gohmanc579d972008-09-09 01:02:47 +00004598type. If the val1/val2 are vectors and
4599the condition is a scalar, then entire vectors are selected, not
Chris Lattnerb54c30f2008-05-20 20:48:21 +00004600individual elements.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004601</p>
4602
4603<h5>Semantics:</h5>
4604
4605<p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004606If the condition is an i1 and it evaluates to 1, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00004607value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004608</p>
Dan Gohmanc579d972008-09-09 01:02:47 +00004609<p>
4610If the condition is a vector of i1, then the value arguments must
4611be vectors of the same size, and the selection is done element
4612by element.
4613</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004614
4615<h5>Example:</h5>
4616
4617<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00004618 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004619</pre>
Dan Gohmana5127ab2009-01-22 01:39:38 +00004620
4621<p>Note that the code generator does not yet support conditions
4622 with vector type.</p>
4623
Chris Lattnerb53c28d2004-03-12 05:50:16 +00004624</div>
4625
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00004626
4627<!-- _______________________________________________________________________ -->
4628<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00004629 <a name="i_call">'<tt>call</tt>' Instruction</a>
4630</div>
4631
Misha Brukman76307852003-11-08 01:05:38 +00004632<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00004633
Chris Lattner2f7c9632001-06-06 20:29:01 +00004634<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004635<pre>
Devang Patel02256232008-10-07 17:48:33 +00004636 &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 +00004637</pre>
4638
Chris Lattner2f7c9632001-06-06 20:29:01 +00004639<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004640
Misha Brukman76307852003-11-08 01:05:38 +00004641<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004642
Chris Lattner2f7c9632001-06-06 20:29:01 +00004643<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004644
Misha Brukman76307852003-11-08 01:05:38 +00004645<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004646
Chris Lattnera8292f32002-05-06 22:08:29 +00004647<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00004648 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00004649 <p>The optional "tail" marker indicates whether the callee function accesses
4650 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00004651 function call is eligible for tail call optimization. Note that calls may
4652 be marked "tail" even if they do not occur before a <a
Dan Gohmanef9462f2008-10-14 16:51:45 +00004653 href="#i_ret"><tt>ret</tt></a> instruction.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00004654 </li>
4655 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00004656 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00004657 convention</a> the call should use. If none is specified, the call defaults
Dan Gohmanef9462f2008-10-14 16:51:45 +00004658 to using C calling conventions.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00004659 </li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00004660
4661 <li>
4662 <p>The optional <a href="#paramattrs">Parameter Attributes</a> list for
4663 return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>',
4664 and '<tt>inreg</tt>' attributes are valid here.</p>
4665 </li>
4666
Chris Lattner0132aff2005-05-06 22:57:40 +00004667 <li>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00004668 <p>'<tt>ty</tt>': the type of the call instruction itself which is also
4669 the type of the return value. Functions that return no value are marked
4670 <tt><a href="#t_void">void</a></tt>.</p>
4671 </li>
4672 <li>
4673 <p>'<tt>fnty</tt>': shall be the signature of the pointer to function
4674 value being invoked. The argument types must match the types implied by
4675 this signature. This type can be omitted if the function is not varargs
4676 and if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004677 </li>
4678 <li>
4679 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
4680 be invoked. In most cases, this is a direct function invocation, but
4681 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00004682 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00004683 </li>
4684 <li>
4685 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00004686 function signature argument types. All arguments must be of
4687 <a href="#t_firstclass">first class</a> type. If the function signature
4688 indicates the function accepts a variable number of arguments, the extra
4689 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00004690 </li>
Devang Patel7e9b05e2008-10-06 18:50:38 +00004691 <li>
Devang Patel02256232008-10-07 17:48:33 +00004692 <p>The optional <a href="#fnattrs">function attributes</a> list. Only
Devang Patel7e9b05e2008-10-06 18:50:38 +00004693 '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and
4694 '<tt>readnone</tt>' attributes are valid here.</p>
4695 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00004696</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00004697
Chris Lattner2f7c9632001-06-06 20:29:01 +00004698<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004699
Chris Lattner48b383b02003-11-25 01:02:51 +00004700<p>The '<tt>call</tt>' instruction is used to cause control flow to
4701transfer to a specified function, with its incoming arguments bound to
4702the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
4703instruction in the called function, control flow continues with the
4704instruction after the function call, and the return value of the
Dan Gohmanef9462f2008-10-14 16:51:45 +00004705function is bound to the result argument.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00004706
Chris Lattner2f7c9632001-06-06 20:29:01 +00004707<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00004708
4709<pre>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00004710 %retval = call i32 @test(i32 %argc)
Chris Lattnerfb7c88d2008-03-21 17:24:17 +00004711 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i>
4712 %X = tail call i32 @foo() <i>; yields i32</i>
4713 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i>
4714 call void %foo(i8 97 signext)
Devang Pateld6cff512008-03-10 20:49:15 +00004715
4716 %struct.A = type { i32, i8 }
Devang Patel7e9b05e2008-10-06 18:50:38 +00004717 %r = call %struct.A @foo() <i>; yields { 32, i8 }</i>
Dan Gohmancc3132e2008-10-04 19:00:07 +00004718 %gr = extractvalue %struct.A %r, 0 <i>; yields i32</i>
4719 %gr1 = extractvalue %struct.A %r, 1 <i>; yields i8</i>
Chris Lattner6cbe8e92008-10-08 06:26:11 +00004720 %Z = call void @foo() noreturn <i>; indicates that %foo never returns normally</i>
Matthijs Kooijmaneefa7df2008-10-07 10:03:45 +00004721 %ZZ = call zeroext i32 @bar() <i>; Return value is %zero extended</i>
Chris Lattnere23c1392005-05-06 05:47:36 +00004722</pre>
4723
Misha Brukman76307852003-11-08 01:05:38 +00004724</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004725
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004726<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00004727<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00004728 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004729</div>
4730
Misha Brukman76307852003-11-08 01:05:38 +00004731<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00004732
Chris Lattner26ca62e2003-10-18 05:51:36 +00004733<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004734
4735<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004736 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00004737</pre>
4738
Chris Lattner26ca62e2003-10-18 05:51:36 +00004739<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004740
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004741<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00004742the "variable argument" area of a function call. It is used to implement the
4743<tt>va_arg</tt> macro in C.</p>
4744
Chris Lattner26ca62e2003-10-18 05:51:36 +00004745<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004746
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004747<p>This instruction takes a <tt>va_list*</tt> value and the type of
4748the argument. It returns a value of the specified argument type and
Jeff Cohen222a8a42007-04-29 01:07:00 +00004749increments the <tt>va_list</tt> to point to the next argument. The
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004750actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004751
Chris Lattner26ca62e2003-10-18 05:51:36 +00004752<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004753
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004754<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
4755type from the specified <tt>va_list</tt> and causes the
4756<tt>va_list</tt> to point to the next argument. For more information,
4757see the variable argument handling <a href="#int_varargs">Intrinsic
4758Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004759
4760<p>It is legal for this instruction to be called in a function which does not
4761take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00004762function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004763
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004764<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00004765href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00004766argument.</p>
4767
Chris Lattner26ca62e2003-10-18 05:51:36 +00004768<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00004769
4770<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4771
Dan Gohman3065b612009-01-12 23:12:39 +00004772<p>Note that the code generator does not yet fully support va_arg
4773 on many targets. Also, it does not currently support va_arg with
4774 aggregate types on any target.</p>
4775
Misha Brukman76307852003-11-08 01:05:38 +00004776</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004777
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004778<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00004779<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4780<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00004781
Misha Brukman76307852003-11-08 01:05:38 +00004782<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00004783
4784<p>LLVM supports the notion of an "intrinsic function". These functions have
Reid Spencer4eefaab2007-04-01 08:04:23 +00004785well known names and semantics and are required to follow certain restrictions.
4786Overall, these intrinsics represent an extension mechanism for the LLVM
Jeff Cohen222a8a42007-04-29 01:07:00 +00004787language that does not require changing all of the transformations in LLVM when
Gabor Greifa54634a2007-07-06 22:07:22 +00004788adding to the language (or the bitcode reader/writer, the parser, etc...).</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004789
John Criswell88190562005-05-16 16:17:45 +00004790<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Jeff Cohen222a8a42007-04-29 01:07:00 +00004791prefix is reserved in LLVM for intrinsic names; thus, function names may not
4792begin with this prefix. Intrinsic functions must always be external functions:
4793you cannot define the body of intrinsic functions. Intrinsic functions may
4794only be used in call or invoke instructions: it is illegal to take the address
4795of an intrinsic function. Additionally, because intrinsic functions are part
4796of the LLVM language, it is required if any are added that they be documented
4797here.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004798
Chandler Carruth7132e002007-08-04 01:51:18 +00004799<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents
4800a family of functions that perform the same operation but on different data
4801types. Because LLVM can represent over 8 million different integer types,
4802overloading is used commonly to allow an intrinsic function to operate on any
4803integer type. One or more of the argument types or the result type can be
4804overloaded to accept any integer type. Argument types may also be defined as
4805exactly matching a previous argument's type or the result type. This allows an
4806intrinsic function which accepts multiple arguments, but needs all of them to
4807be of the same type, to only be overloaded with respect to a single argument or
4808the result.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00004809
Chandler Carruth7132e002007-08-04 01:51:18 +00004810<p>Overloaded intrinsics will have the names of its overloaded argument types
4811encoded into its function name, each preceded by a period. Only those types
4812which are overloaded result in a name suffix. Arguments whose type is matched
4813against another type do not. For example, the <tt>llvm.ctpop</tt> function can
4814take an integer of any width and returns an integer of exactly the same integer
4815width. This leads to a family of functions such as
4816<tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>.
4817Only one type, the return type, is overloaded, and only one type suffix is
4818required. Because the argument's type is matched against the return type, it
4819does not require its own name suffix.</p>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004820
4821<p>To learn how to add an intrinsic function, please see the
4822<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00004823</p>
4824
Misha Brukman76307852003-11-08 01:05:38 +00004825</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004826
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004827<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00004828<div class="doc_subsection">
4829 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4830</div>
4831
Misha Brukman76307852003-11-08 01:05:38 +00004832<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004833
Misha Brukman76307852003-11-08 01:05:38 +00004834<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00004835 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00004836intrinsic functions. These functions are related to the similarly
4837named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004838
Chris Lattner48b383b02003-11-25 01:02:51 +00004839<p>All of these functions operate on arguments that use a
4840target-specific value type "<tt>va_list</tt>". The LLVM assembly
4841language reference manual does not define what this type is, so all
Jeff Cohen222a8a42007-04-29 01:07:00 +00004842transformations should be prepared to handle these functions regardless of
4843the type used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004844
Chris Lattner30b868d2006-05-15 17:26:46 +00004845<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00004846instruction and the variable argument handling intrinsic functions are
4847used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004848
Bill Wendling3716c5d2007-05-29 09:04:49 +00004849<div class="doc_code">
Chris Lattnerfee11462004-02-12 17:01:32 +00004850<pre>
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004851define i32 @test(i32 %X, ...) {
Chris Lattnerfee11462004-02-12 17:01:32 +00004852 ; Initialize variable argument processing
Jeff Cohen222a8a42007-04-29 01:07:00 +00004853 %ap = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004854 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004855 call void @llvm.va_start(i8* %ap2)
Chris Lattnerfee11462004-02-12 17:01:32 +00004856
4857 ; Read a single integer argument
Jeff Cohen222a8a42007-04-29 01:07:00 +00004858 %tmp = va_arg i8** %ap, i32
Chris Lattnerfee11462004-02-12 17:01:32 +00004859
4860 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Jeff Cohen222a8a42007-04-29 01:07:00 +00004861 %aq = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004862 %aq2 = bitcast i8** %aq to i8*
Jeff Cohen222a8a42007-04-29 01:07:00 +00004863 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004864 call void @llvm.va_end(i8* %aq2)
Chris Lattnerfee11462004-02-12 17:01:32 +00004865
4866 ; Stop processing of arguments.
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004867 call void @llvm.va_end(i8* %ap2)
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004868 ret i32 %tmp
Chris Lattnerfee11462004-02-12 17:01:32 +00004869}
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00004870
4871declare void @llvm.va_start(i8*)
4872declare void @llvm.va_copy(i8*, i8*)
4873declare void @llvm.va_end(i8*)
Chris Lattnerfee11462004-02-12 17:01:32 +00004874</pre>
Misha Brukman76307852003-11-08 01:05:38 +00004875</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004876
Bill Wendling3716c5d2007-05-29 09:04:49 +00004877</div>
4878
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004879<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004880<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004881 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004882</div>
4883
4884
Misha Brukman76307852003-11-08 01:05:38 +00004885<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004886<h5>Syntax:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004887<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004888<h5>Overview:</h5>
Dan Gohmanef9462f2008-10-14 16:51:45 +00004889<p>The '<tt>llvm.va_start</tt>' intrinsic initializes
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004890<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
4891href="#i_va_arg">va_arg</a></tt>.</p>
4892
4893<h5>Arguments:</h5>
4894
Dan Gohmanef9462f2008-10-14 16:51:45 +00004895<p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004896
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004897<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004898
Dan Gohmanef9462f2008-10-14 16:51:45 +00004899<p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004900macro available in C. In a target-dependent way, it initializes the
Jeff Cohen222a8a42007-04-29 01:07:00 +00004901<tt>va_list</tt> element to which the argument points, so that the next call to
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004902<tt>va_arg</tt> will produce the first variable argument passed to the function.
4903Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
Jeff Cohen222a8a42007-04-29 01:07:00 +00004904last argument of the function as the compiler can figure that out.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004905
Misha Brukman76307852003-11-08 01:05:38 +00004906</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004907
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004908<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004909<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004910 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004911</div>
4912
Misha Brukman76307852003-11-08 01:05:38 +00004913<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004914<h5>Syntax:</h5>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004915<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004916<h5>Overview:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004917
Jeff Cohen222a8a42007-04-29 01:07:00 +00004918<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Reid Spencer96a5f022007-04-04 02:42:35 +00004919which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00004920or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004921
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004922<h5>Arguments:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004923
Jeff Cohen222a8a42007-04-29 01:07:00 +00004924<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004925
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004926<h5>Semantics:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004927
Misha Brukman76307852003-11-08 01:05:38 +00004928<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004929macro available in C. In a target-dependent way, it destroys the
4930<tt>va_list</tt> element to which the argument points. Calls to <a
4931href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy">
4932<tt>llvm.va_copy</tt></a> must be matched exactly with calls to
4933<tt>llvm.va_end</tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004934
Misha Brukman76307852003-11-08 01:05:38 +00004935</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004936
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004937<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004938<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004939 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004940</div>
4941
Misha Brukman76307852003-11-08 01:05:38 +00004942<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004943
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004944<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004945
4946<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004947 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00004948</pre>
4949
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004950<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004951
Jeff Cohen222a8a42007-04-29 01:07:00 +00004952<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
4953from the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004954
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004955<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004956
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004957<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00004958The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004959
Chris Lattner757528b0b2004-05-23 21:06:01 +00004960
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004961<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004962
Jeff Cohen222a8a42007-04-29 01:07:00 +00004963<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
4964macro available in C. In a target-dependent way, it copies the source
4965<tt>va_list</tt> element into the destination <tt>va_list</tt> element. This
4966intrinsic is necessary because the <tt><a href="#int_va_start">
4967llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for
4968example, memory allocation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004969
Misha Brukman76307852003-11-08 01:05:38 +00004970</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004971
Chris Lattnerfee11462004-02-12 17:01:32 +00004972<!-- ======================================================================= -->
4973<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004974 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
4975</div>
4976
4977<div class="doc_text">
4978
4979<p>
4980LLVM support for <a href="GarbageCollection.html">Accurate Garbage
Chris Lattner67c37d12008-08-05 18:29:16 +00004981Collection</a> (GC) requires the implementation and generation of these
4982intrinsics.
Reid Spencer96a5f022007-04-04 02:42:35 +00004983These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
Chris Lattner757528b0b2004-05-23 21:06:01 +00004984stack</a>, as well as garbage collector implementations that require <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004985href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
Chris Lattner757528b0b2004-05-23 21:06:01 +00004986Front-ends for type-safe garbage collected languages should generate these
4987intrinsics to make use of the LLVM garbage collectors. For more details, see <a
4988href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
4989</p>
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00004990
4991<p>The garbage collection intrinsics only operate on objects in the generic
4992 address space (address space zero).</p>
4993
Chris Lattner757528b0b2004-05-23 21:06:01 +00004994</div>
4995
4996<!-- _______________________________________________________________________ -->
4997<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004998 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004999</div>
5000
5001<div class="doc_text">
5002
5003<h5>Syntax:</h5>
5004
5005<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005006 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005007</pre>
5008
5009<h5>Overview:</h5>
5010
John Criswelldfe6a862004-12-10 15:51:16 +00005011<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00005012the code generator, and allows some metadata to be associated with it.</p>
5013
5014<h5>Arguments:</h5>
5015
5016<p>The first argument specifies the address of a stack object that contains the
5017root pointer. The second pointer (which must be either a constant or a global
5018value address) contains the meta-data to be associated with the root.</p>
5019
5020<h5>Semantics:</h5>
5021
Chris Lattner851b7712008-04-24 05:59:56 +00005022<p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
Chris Lattner757528b0b2004-05-23 21:06:01 +00005023location. At compile-time, the code generator generates information to allow
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00005024the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
5025intrinsic may only be used in a function which <a href="#gc">specifies a GC
5026algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005027
5028</div>
5029
5030
5031<!-- _______________________________________________________________________ -->
5032<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005033 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005034</div>
5035
5036<div class="doc_text">
5037
5038<h5>Syntax:</h5>
5039
5040<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005041 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005042</pre>
5043
5044<h5>Overview:</h5>
5045
5046<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
5047locations, allowing garbage collector implementations that require read
5048barriers.</p>
5049
5050<h5>Arguments:</h5>
5051
Chris Lattnerf9228072006-03-14 20:02:51 +00005052<p>The second argument is the address to read from, which should be an address
5053allocated from the garbage collector. The first object is a pointer to the
5054start of the referenced object, if needed by the language runtime (otherwise
5055null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005056
5057<h5>Semantics:</h5>
5058
5059<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
5060instruction, but may be replaced with substantially more complex code by the
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00005061garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
5062may only be used in a function which <a href="#gc">specifies a GC
5063algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005064
5065</div>
5066
5067
5068<!-- _______________________________________________________________________ -->
5069<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005070 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005071</div>
5072
5073<div class="doc_text">
5074
5075<h5>Syntax:</h5>
5076
5077<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005078 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00005079</pre>
5080
5081<h5>Overview:</h5>
5082
5083<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
5084locations, allowing garbage collector implementations that require write
5085barriers (such as generational or reference counting collectors).</p>
5086
5087<h5>Arguments:</h5>
5088
Chris Lattnerf9228072006-03-14 20:02:51 +00005089<p>The first argument is the reference to store, the second is the start of the
5090object to store it to, and the third is the address of the field of Obj to
5091store to. If the runtime does not require a pointer to the object, Obj may be
5092null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005093
5094<h5>Semantics:</h5>
5095
5096<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
5097instruction, but may be replaced with substantially more complex code by the
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00005098garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
5099may only be used in a function which <a href="#gc">specifies a GC
5100algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00005101
5102</div>
5103
5104
5105
5106<!-- ======================================================================= -->
5107<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00005108 <a name="int_codegen">Code Generator Intrinsics</a>
5109</div>
5110
5111<div class="doc_text">
5112<p>
5113These intrinsics are provided by LLVM to expose special features that may only
5114be implemented with code generator support.
5115</p>
5116
5117</div>
5118
5119<!-- _______________________________________________________________________ -->
5120<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005121 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005122</div>
5123
5124<div class="doc_text">
5125
5126<h5>Syntax:</h5>
5127<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005128 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005129</pre>
5130
5131<h5>Overview:</h5>
5132
5133<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00005134The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
5135target-specific value indicating the return address of the current function
5136or one of its callers.
Chris Lattner3649c3a2004-02-14 04:08:35 +00005137</p>
5138
5139<h5>Arguments:</h5>
5140
5141<p>
5142The argument to this intrinsic indicates which function to return the address
5143for. Zero indicates the calling function, one indicates its caller, etc. The
5144argument is <b>required</b> to be a constant integer value.
5145</p>
5146
5147<h5>Semantics:</h5>
5148
5149<p>
5150The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
5151the return address of the specified call frame, or zero if it cannot be
5152identified. The value returned by this intrinsic is likely to be incorrect or 0
5153for arguments other than zero, so it should only be used for debugging purposes.
5154</p>
5155
5156<p>
5157Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00005158aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00005159source-language caller.
5160</p>
5161</div>
5162
5163
5164<!-- _______________________________________________________________________ -->
5165<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005166 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005167</div>
5168
5169<div class="doc_text">
5170
5171<h5>Syntax:</h5>
5172<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005173 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005174</pre>
5175
5176<h5>Overview:</h5>
5177
5178<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00005179The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
5180target-specific frame pointer value for the specified stack frame.
Chris Lattner3649c3a2004-02-14 04:08:35 +00005181</p>
5182
5183<h5>Arguments:</h5>
5184
5185<p>
5186The argument to this intrinsic indicates which function to return the frame
5187pointer for. Zero indicates the calling function, one indicates its caller,
5188etc. The argument is <b>required</b> to be a constant integer value.
5189</p>
5190
5191<h5>Semantics:</h5>
5192
5193<p>
5194The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
5195the frame address of the specified call frame, or zero if it cannot be
5196identified. The value returned by this intrinsic is likely to be incorrect or 0
5197for arguments other than zero, so it should only be used for debugging purposes.
5198</p>
5199
5200<p>
5201Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00005202aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00005203source-language caller.
5204</p>
5205</div>
5206
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005207<!-- _______________________________________________________________________ -->
5208<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005209 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005210</div>
5211
5212<div class="doc_text">
5213
5214<h5>Syntax:</h5>
5215<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005216 declare i8 *@llvm.stacksave()
Chris Lattner2f0f0012006-01-13 02:03:13 +00005217</pre>
5218
5219<h5>Overview:</h5>
5220
5221<p>
5222The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
Reid Spencer96a5f022007-04-04 02:42:35 +00005223the function stack, for use with <a href="#int_stackrestore">
Chris Lattner2f0f0012006-01-13 02:03:13 +00005224<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
5225features like scoped automatic variable sized arrays in C99.
5226</p>
5227
5228<h5>Semantics:</h5>
5229
5230<p>
5231This intrinsic returns a opaque pointer value that can be passed to <a
Reid Spencer96a5f022007-04-04 02:42:35 +00005232href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
Chris Lattner2f0f0012006-01-13 02:03:13 +00005233<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
5234<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
5235state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
5236practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
5237that were allocated after the <tt>llvm.stacksave</tt> was executed.
5238</p>
5239
5240</div>
5241
5242<!-- _______________________________________________________________________ -->
5243<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005244 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00005245</div>
5246
5247<div class="doc_text">
5248
5249<h5>Syntax:</h5>
5250<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005251 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner2f0f0012006-01-13 02:03:13 +00005252</pre>
5253
5254<h5>Overview:</h5>
5255
5256<p>
5257The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
5258the function stack to the state it was in when the corresponding <a
Reid Spencer96a5f022007-04-04 02:42:35 +00005259href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
Chris Lattner2f0f0012006-01-13 02:03:13 +00005260useful for implementing language features like scoped automatic variable sized
5261arrays in C99.
5262</p>
5263
5264<h5>Semantics:</h5>
5265
5266<p>
Reid Spencer96a5f022007-04-04 02:42:35 +00005267See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
Chris Lattner2f0f0012006-01-13 02:03:13 +00005268</p>
5269
5270</div>
5271
5272
5273<!-- _______________________________________________________________________ -->
5274<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005275 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005276</div>
5277
5278<div class="doc_text">
5279
5280<h5>Syntax:</h5>
5281<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005282 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005283</pre>
5284
5285<h5>Overview:</h5>
5286
5287
5288<p>
5289The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00005290a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
5291no
5292effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00005293characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005294</p>
5295
5296<h5>Arguments:</h5>
5297
5298<p>
5299<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
5300determining if the fetch should be for a read (0) or write (1), and
5301<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00005302locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00005303<tt>locality</tt> arguments must be constant integers.
5304</p>
5305
5306<h5>Semantics:</h5>
5307
5308<p>
5309This intrinsic does not modify the behavior of the program. In particular,
5310prefetches cannot trap and do not produce a value. On targets that support this
5311intrinsic, the prefetch can provide hints to the processor cache for better
5312performance.
5313</p>
5314
5315</div>
5316
Andrew Lenharthb4427912005-03-28 20:05:49 +00005317<!-- _______________________________________________________________________ -->
5318<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005319 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharthb4427912005-03-28 20:05:49 +00005320</div>
5321
5322<div class="doc_text">
5323
5324<h5>Syntax:</h5>
5325<pre>
Chris Lattner12477732007-09-21 17:30:40 +00005326 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Andrew Lenharthb4427912005-03-28 20:05:49 +00005327</pre>
5328
5329<h5>Overview:</h5>
5330
5331
5332<p>
John Criswell88190562005-05-16 16:17:45 +00005333The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
Chris Lattner67c37d12008-08-05 18:29:16 +00005334(PC) in a region of
5335code to simulators and other tools. The method is target specific, but it is
5336expected that the marker will use exported symbols to transmit the PC of the
5337marker.
5338The marker makes no guarantees that it will remain with any specific instruction
5339after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb40261e2006-03-24 07:16:10 +00005340optimizations. The intended use is to be inserted after optimizations to allow
John Criswell88190562005-05-16 16:17:45 +00005341correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00005342</p>
5343
5344<h5>Arguments:</h5>
5345
5346<p>
5347<tt>id</tt> is a numerical id identifying the marker.
5348</p>
5349
5350<h5>Semantics:</h5>
5351
5352<p>
5353This intrinsic does not modify the behavior of the program. Backends that do not
5354support this intrinisic may ignore it.
5355</p>
5356
5357</div>
5358
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005359<!-- _______________________________________________________________________ -->
5360<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005361 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005362</div>
5363
5364<div class="doc_text">
5365
5366<h5>Syntax:</h5>
5367<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005368 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth01aa5632005-11-11 16:47:30 +00005369</pre>
5370
5371<h5>Overview:</h5>
5372
5373
5374<p>
5375The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
5376counter register (or similar low latency, high accuracy clocks) on those targets
5377that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
5378As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
5379should only be used for small timings.
5380</p>
5381
5382<h5>Semantics:</h5>
5383
5384<p>
5385When directly supported, reading the cycle counter should not modify any memory.
5386Implementations are allowed to either return a application specific value or a
5387system wide value. On backends without support, this is lowered to a constant 0.
5388</p>
5389
5390</div>
5391
Chris Lattner3649c3a2004-02-14 04:08:35 +00005392<!-- ======================================================================= -->
5393<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00005394 <a name="int_libc">Standard C Library Intrinsics</a>
5395</div>
5396
5397<div class="doc_text">
5398<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005399LLVM provides intrinsics for a few important standard C library functions.
5400These intrinsics allow source-language front-ends to pass information about the
5401alignment of the pointer arguments to the code generator, providing opportunity
5402for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00005403</p>
5404
5405</div>
5406
5407<!-- _______________________________________________________________________ -->
5408<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005409 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattnerfee11462004-02-12 17:01:32 +00005410</div>
5411
5412<div class="doc_text">
5413
5414<h5>Syntax:</h5>
Chris Lattnerdd708342008-11-21 16:42:48 +00005415<p>This is an overloaded intrinsic. You can use llvm.memcpy on any integer bit
5416width. Not all targets support all bit widths however.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00005417<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005418 declare void @llvm.memcpy.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5419 i8 &lt;len&gt;, i32 &lt;align&gt;)
5420 declare void @llvm.memcpy.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5421 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005422 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005423 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005424 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005425 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00005426</pre>
5427
5428<h5>Overview:</h5>
5429
5430<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005431The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00005432location to the destination location.
5433</p>
5434
5435<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005436Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
5437intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00005438</p>
5439
5440<h5>Arguments:</h5>
5441
5442<p>
5443The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00005444the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00005445specifying the number of bytes to copy, and the fourth argument is the alignment
5446of the source and destination locations.
5447</p>
5448
Chris Lattner4c67c482004-02-12 21:18:15 +00005449<p>
5450If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00005451the caller guarantees that both the source and destination pointers are aligned
5452to that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00005453</p>
5454
Chris Lattnerfee11462004-02-12 17:01:32 +00005455<h5>Semantics:</h5>
5456
5457<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005458The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00005459location to the destination location, which are not allowed to overlap. It
5460copies "len" bytes of memory over. If the argument is known to be aligned to
5461some boundary, this can be specified as the fourth argument, otherwise it should
5462be set to 0 or 1.
5463</p>
5464</div>
5465
5466
Chris Lattnerf30152e2004-02-12 18:10:10 +00005467<!-- _______________________________________________________________________ -->
5468<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005469 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005470</div>
5471
5472<div class="doc_text">
5473
5474<h5>Syntax:</h5>
Chris Lattnerdd708342008-11-21 16:42:48 +00005475<p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit
5476width. Not all targets support all bit widths however.</p>
Chris Lattnerf30152e2004-02-12 18:10:10 +00005477<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005478 declare void @llvm.memmove.i8(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5479 i8 &lt;len&gt;, i32 &lt;align&gt;)
5480 declare void @llvm.memmove.i16(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
5481 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005482 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005483 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005484 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005485 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00005486</pre>
5487
5488<h5>Overview:</h5>
5489
5490<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005491The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
5492location to the destination location. It is similar to the
Chris Lattnerec564022008-01-06 19:51:52 +00005493'<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00005494</p>
5495
5496<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005497Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
5498intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00005499</p>
5500
5501<h5>Arguments:</h5>
5502
5503<p>
5504The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00005505the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00005506specifying the number of bytes to copy, and the fourth argument is the alignment
5507of the source and destination locations.
5508</p>
5509
Chris Lattner4c67c482004-02-12 21:18:15 +00005510<p>
5511If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00005512the caller guarantees that the source and destination pointers are aligned to
5513that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00005514</p>
5515
Chris Lattnerf30152e2004-02-12 18:10:10 +00005516<h5>Semantics:</h5>
5517
5518<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005519The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00005520location to the destination location, which may overlap. It
5521copies "len" bytes of memory over. If the argument is known to be aligned to
5522some boundary, this can be specified as the fourth argument, otherwise it should
5523be set to 0 or 1.
5524</p>
5525</div>
5526
Chris Lattner941515c2004-01-06 05:31:32 +00005527
Chris Lattner3649c3a2004-02-14 04:08:35 +00005528<!-- _______________________________________________________________________ -->
5529<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005530 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005531</div>
5532
5533<div class="doc_text">
5534
5535<h5>Syntax:</h5>
Chris Lattnerdd708342008-11-21 16:42:48 +00005536<p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit
5537width. Not all targets support all bit widths however.</p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00005538<pre>
Chris Lattnerdd708342008-11-21 16:42:48 +00005539 declare void @llvm.memset.i8(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5540 i8 &lt;len&gt;, i32 &lt;align&gt;)
5541 declare void @llvm.memset.i16(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
5542 i16 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005543 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005544 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005545 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005546 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00005547</pre>
5548
5549<h5>Overview:</h5>
5550
5551<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005552The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00005553byte value.
5554</p>
5555
5556<p>
5557Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
5558does not return a value, and takes an extra alignment argument.
5559</p>
5560
5561<h5>Arguments:</h5>
5562
5563<p>
5564The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00005565byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00005566argument specifying the number of bytes to fill, and the fourth argument is the
5567known alignment of destination location.
5568</p>
5569
5570<p>
5571If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00005572the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner3649c3a2004-02-14 04:08:35 +00005573</p>
5574
5575<h5>Semantics:</h5>
5576
5577<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00005578The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
5579the
Chris Lattner3649c3a2004-02-14 04:08:35 +00005580destination location. If the argument is known to be aligned to some boundary,
5581this can be specified as the fourth argument, otherwise it should be set to 0 or
55821.
5583</p>
5584</div>
5585
5586
Chris Lattner3b4f4372004-06-11 02:28:03 +00005587<!-- _______________________________________________________________________ -->
5588<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005589 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005590</div>
5591
5592<div class="doc_text">
5593
5594<h5>Syntax:</h5>
Dale Johannesendd89d272007-10-02 17:47:38 +00005595<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
Dan Gohmanb6324c12007-10-15 20:30:11 +00005596floating point or vector of floating point type. Not all targets support all
Dan Gohmanef9462f2008-10-14 16:51:45 +00005597types however.</p>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005598<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00005599 declare float @llvm.sqrt.f32(float %Val)
5600 declare double @llvm.sqrt.f64(double %Val)
5601 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
5602 declare fp128 @llvm.sqrt.f128(fp128 %Val)
5603 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005604</pre>
5605
5606<h5>Overview:</h5>
5607
5608<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005609The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Dan Gohmanb6324c12007-10-15 20:30:11 +00005610returning the same value as the libm '<tt>sqrt</tt>' functions would. Unlike
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005611<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
Chris Lattner00d7cb92008-01-29 07:00:44 +00005612negative numbers other than -0.0 (which allows for better optimization, because
5613there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is
5614defined to return -0.0 like IEEE sqrt.
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005615</p>
5616
5617<h5>Arguments:</h5>
5618
5619<p>
5620The argument and return value are floating point numbers of the same type.
5621</p>
5622
5623<h5>Semantics:</h5>
5624
5625<p>
Dan Gohman33988db2007-07-16 14:37:41 +00005626This function returns the sqrt of the specified operand if it is a nonnegative
Chris Lattner8a8f2e52005-07-21 01:29:16 +00005627floating point number.
5628</p>
5629</div>
5630
Chris Lattner33b73f92006-09-08 06:34:02 +00005631<!-- _______________________________________________________________________ -->
5632<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005633 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattner33b73f92006-09-08 06:34:02 +00005634</div>
5635
5636<div class="doc_text">
5637
5638<h5>Syntax:</h5>
Dale Johannesendd89d272007-10-02 17:47:38 +00005639<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
Dan Gohmanb6324c12007-10-15 20:30:11 +00005640floating point or vector of floating point type. Not all targets support all
Dan Gohmanef9462f2008-10-14 16:51:45 +00005641types however.</p>
Chris Lattner33b73f92006-09-08 06:34:02 +00005642<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00005643 declare float @llvm.powi.f32(float %Val, i32 %power)
5644 declare double @llvm.powi.f64(double %Val, i32 %power)
5645 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
5646 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
5647 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Chris Lattner33b73f92006-09-08 06:34:02 +00005648</pre>
5649
5650<h5>Overview:</h5>
5651
5652<p>
5653The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
5654specified (positive or negative) power. The order of evaluation of
Dan Gohmanb6324c12007-10-15 20:30:11 +00005655multiplications is not defined. When a vector of floating point type is
5656used, the second argument remains a scalar integer value.
Chris Lattner33b73f92006-09-08 06:34:02 +00005657</p>
5658
5659<h5>Arguments:</h5>
5660
5661<p>
5662The second argument is an integer power, and the first is a value to raise to
5663that power.
5664</p>
5665
5666<h5>Semantics:</h5>
5667
5668<p>
5669This function returns the first value raised to the second power with an
5670unspecified sequence of rounding operations.</p>
5671</div>
5672
Dan Gohmanb6324c12007-10-15 20:30:11 +00005673<!-- _______________________________________________________________________ -->
5674<div class="doc_subsubsection">
5675 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
5676</div>
5677
5678<div class="doc_text">
5679
5680<h5>Syntax:</h5>
5681<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
5682floating point or vector of floating point type. Not all targets support all
Dan Gohmanef9462f2008-10-14 16:51:45 +00005683types however.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005684<pre>
5685 declare float @llvm.sin.f32(float %Val)
5686 declare double @llvm.sin.f64(double %Val)
5687 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
5688 declare fp128 @llvm.sin.f128(fp128 %Val)
5689 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
5690</pre>
5691
5692<h5>Overview:</h5>
5693
5694<p>
5695The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.
5696</p>
5697
5698<h5>Arguments:</h5>
5699
5700<p>
5701The argument and return value are floating point numbers of the same type.
5702</p>
5703
5704<h5>Semantics:</h5>
5705
5706<p>
5707This function returns the sine of the specified operand, returning the
5708same values as the libm <tt>sin</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00005709conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005710</div>
5711
5712<!-- _______________________________________________________________________ -->
5713<div class="doc_subsubsection">
5714 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
5715</div>
5716
5717<div class="doc_text">
5718
5719<h5>Syntax:</h5>
5720<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
5721floating point or vector of floating point type. Not all targets support all
Dan Gohmanef9462f2008-10-14 16:51:45 +00005722types however.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005723<pre>
5724 declare float @llvm.cos.f32(float %Val)
5725 declare double @llvm.cos.f64(double %Val)
5726 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
5727 declare fp128 @llvm.cos.f128(fp128 %Val)
5728 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
5729</pre>
5730
5731<h5>Overview:</h5>
5732
5733<p>
5734The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.
5735</p>
5736
5737<h5>Arguments:</h5>
5738
5739<p>
5740The argument and return value are floating point numbers of the same type.
5741</p>
5742
5743<h5>Semantics:</h5>
5744
5745<p>
5746This function returns the cosine of the specified operand, returning the
5747same values as the libm <tt>cos</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00005748conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005749</div>
5750
5751<!-- _______________________________________________________________________ -->
5752<div class="doc_subsubsection">
5753 <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
5754</div>
5755
5756<div class="doc_text">
5757
5758<h5>Syntax:</h5>
5759<p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
5760floating point or vector of floating point type. Not all targets support all
Dan Gohmanef9462f2008-10-14 16:51:45 +00005761types however.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005762<pre>
5763 declare float @llvm.pow.f32(float %Val, float %Power)
5764 declare double @llvm.pow.f64(double %Val, double %Power)
5765 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
5766 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
5767 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
5768</pre>
5769
5770<h5>Overview:</h5>
5771
5772<p>
5773The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5774specified (positive or negative) power.
5775</p>
5776
5777<h5>Arguments:</h5>
5778
5779<p>
5780The second argument is a floating point power, and the first is a value to
5781raise to that power.
5782</p>
5783
5784<h5>Semantics:</h5>
5785
5786<p>
5787This function returns the first value raised to the second power,
5788returning the
5789same values as the libm <tt>pow</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00005790conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00005791</div>
5792
Chris Lattner33b73f92006-09-08 06:34:02 +00005793
Andrew Lenharth1d463522005-05-03 18:01:48 +00005794<!-- ======================================================================= -->
5795<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00005796 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005797</div>
5798
5799<div class="doc_text">
5800<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005801LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005802These allow efficient code generation for some algorithms.
5803</p>
5804
5805</div>
5806
5807<!-- _______________________________________________________________________ -->
5808<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00005809 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005810</div>
5811
5812<div class="doc_text">
5813
5814<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005815<p>This is an overloaded intrinsic function. You can use bswap on any integer
Dan Gohmanef9462f2008-10-14 16:51:45 +00005816type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00005817<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005818 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5819 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5820 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00005821</pre>
5822
5823<h5>Overview:</h5>
5824
5825<p>
Reid Spencerf361c4f2007-04-02 02:25:19 +00005826The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
Reid Spencer4eefaab2007-04-01 08:04:23 +00005827values with an even number of bytes (positive multiple of 16 bits). These are
5828useful for performing operations on data that is not in the target's native
5829byte order.
Nate Begeman0f223bb2006-01-13 23:26:38 +00005830</p>
5831
5832<h5>Semantics:</h5>
5833
5834<p>
Chandler Carruth7132e002007-08-04 01:51:18 +00005835The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005836and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
5837intrinsic returns an i32 value that has the four bytes of the input i32
5838swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Chandler Carruth7132e002007-08-04 01:51:18 +00005839i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>,
5840<tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to
Reid Spencer4eefaab2007-04-01 08:04:23 +00005841additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Nate Begeman0f223bb2006-01-13 23:26:38 +00005842</p>
5843
5844</div>
5845
5846<!-- _______________________________________________________________________ -->
5847<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005848 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005849</div>
5850
5851<div class="doc_text">
5852
5853<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005854<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
Dan Gohmanef9462f2008-10-14 16:51:45 +00005855width. Not all targets support all bit widths however.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005856<pre>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005857 declare i8 @llvm.ctpop.i8(i8 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005858 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005859 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005860 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5861 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00005862</pre>
5863
5864<h5>Overview:</h5>
5865
5866<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00005867The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
5868value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005869</p>
5870
5871<h5>Arguments:</h5>
5872
5873<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00005874The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00005875integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005876</p>
5877
5878<h5>Semantics:</h5>
5879
5880<p>
5881The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
5882</p>
5883</div>
5884
5885<!-- _______________________________________________________________________ -->
5886<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00005887 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005888</div>
5889
5890<div class="doc_text">
5891
5892<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005893<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
Dan Gohmanef9462f2008-10-14 16:51:45 +00005894integer bit width. Not all targets support all bit widths however.</p>
Andrew Lenharth1d463522005-05-03 18:01:48 +00005895<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005896 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
5897 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005898 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005899 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5900 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00005901</pre>
5902
5903<h5>Overview:</h5>
5904
5905<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005906The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5907leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005908</p>
5909
5910<h5>Arguments:</h5>
5911
5912<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00005913The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00005914integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005915</p>
5916
5917<h5>Semantics:</h5>
5918
5919<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005920The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
5921in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00005922of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00005923</p>
5924</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00005925
5926
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005927
5928<!-- _______________________________________________________________________ -->
5929<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00005930 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005931</div>
5932
5933<div class="doc_text">
5934
5935<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005936<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
Dan Gohmanef9462f2008-10-14 16:51:45 +00005937integer bit width. Not all targets support all bit widths however.</p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005938<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005939 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5940 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005941 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005942 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5943 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005944</pre>
5945
5946<h5>Overview:</h5>
5947
5948<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005949The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5950trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005951</p>
5952
5953<h5>Arguments:</h5>
5954
5955<p>
5956The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00005957integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005958</p>
5959
5960<h5>Semantics:</h5>
5961
5962<p>
5963The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
5964in a variable. If the src == 0 then the result is the size in bits of the type
5965of src. For example, <tt>llvm.cttz(2) = 1</tt>.
5966</p>
5967</div>
5968
Bill Wendlingf4d70622009-02-08 01:40:31 +00005969
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005970<!-- ======================================================================= -->
5971<div class="doc_subsection">
5972 <a name="int_overflow">Arithmetic with Overflow Intrinsics</a>
5973</div>
5974
5975<div class="doc_text">
5976<p>
5977LLVM provides intrinsics for some arithmetic with overflow operations.
5978</p>
5979
5980</div>
5981
Bill Wendlingf4d70622009-02-08 01:40:31 +00005982<!-- _______________________________________________________________________ -->
5983<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005984 <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005985</div>
5986
5987<div class="doc_text">
5988
5989<h5>Syntax:</h5>
5990
5991<p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00005992on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00005993
5994<pre>
5995 declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b)
5996 declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
5997 declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b)
5998</pre>
5999
6000<h5>Overview:</h5>
6001
6002<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
6003a signed addition of the two arguments, and indicate whether an overflow
6004occurred during the signed summation.</p>
6005
6006<h5>Arguments:</h5>
6007
6008<p>The arguments (%a and %b) and the first element of the result structure may
6009be of integer types of any bit width, but they must have the same bit width. The
6010second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6011and <tt>%b</tt> are the two values that will undergo signed addition.</p>
6012
6013<h5>Semantics:</h5>
6014
6015<p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform
6016a signed addition of the two variables. They return a structure &mdash; the
6017first element of which is the signed summation, and the second element of which
6018is a bit specifying if the signed summation resulted in an overflow.</p>
6019
6020<h5>Examples:</h5>
6021<pre>
6022 %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
6023 %sum = extractvalue {i32, i1} %res, 0
6024 %obit = extractvalue {i32, i1} %res, 1
6025 br i1 %obit, label %overflow, label %normal
6026</pre>
6027
6028</div>
6029
6030<!-- _______________________________________________________________________ -->
6031<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006032 <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006033</div>
6034
6035<div class="doc_text">
6036
6037<h5>Syntax:</h5>
6038
6039<p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006040on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006041
6042<pre>
6043 declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b)
6044 declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
6045 declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b)
6046</pre>
6047
6048<h5>Overview:</h5>
6049
6050<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
6051an unsigned addition of the two arguments, and indicate whether a carry occurred
6052during the unsigned summation.</p>
6053
6054<h5>Arguments:</h5>
6055
6056<p>The arguments (%a and %b) and the first element of the result structure may
6057be of integer types of any bit width, but they must have the same bit width. The
6058second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6059and <tt>%b</tt> are the two values that will undergo unsigned addition.</p>
6060
6061<h5>Semantics:</h5>
6062
6063<p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform
6064an unsigned addition of the two arguments. They return a structure &mdash; the
6065first element of which is the sum, and the second element of which is a bit
6066specifying if the unsigned summation resulted in a carry.</p>
6067
6068<h5>Examples:</h5>
6069<pre>
6070 %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
6071 %sum = extractvalue {i32, i1} %res, 0
6072 %obit = extractvalue {i32, i1} %res, 1
6073 br i1 %obit, label %carry, label %normal
6074</pre>
6075
6076</div>
6077
6078<!-- _______________________________________________________________________ -->
6079<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006080 <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006081</div>
6082
6083<div class="doc_text">
6084
6085<h5>Syntax:</h5>
6086
6087<p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006088on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006089
6090<pre>
6091 declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b)
6092 declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
6093 declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b)
6094</pre>
6095
6096<h5>Overview:</h5>
6097
6098<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
6099a signed subtraction of the two arguments, and indicate whether an overflow
6100occurred during the signed subtraction.</p>
6101
6102<h5>Arguments:</h5>
6103
6104<p>The arguments (%a and %b) and the first element of the result structure may
6105be of integer types of any bit width, but they must have the same bit width. The
6106second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6107and <tt>%b</tt> are the two values that will undergo signed subtraction.</p>
6108
6109<h5>Semantics:</h5>
6110
6111<p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform
6112a signed subtraction of the two arguments. They return a structure &mdash; the
6113first element of which is the subtraction, and the second element of which is a bit
6114specifying if the signed subtraction resulted in an overflow.</p>
6115
6116<h5>Examples:</h5>
6117<pre>
6118 %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
6119 %sum = extractvalue {i32, i1} %res, 0
6120 %obit = extractvalue {i32, i1} %res, 1
6121 br i1 %obit, label %overflow, label %normal
6122</pre>
6123
6124</div>
6125
6126<!-- _______________________________________________________________________ -->
6127<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006128 <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006129</div>
6130
6131<div class="doc_text">
6132
6133<h5>Syntax:</h5>
6134
6135<p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006136on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006137
6138<pre>
6139 declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b)
6140 declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6141 declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
6142</pre>
6143
6144<h5>Overview:</h5>
6145
6146<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6147an unsigned subtraction of the two arguments, and indicate whether an overflow
6148occurred during the unsigned subtraction.</p>
6149
6150<h5>Arguments:</h5>
6151
6152<p>The arguments (%a and %b) and the first element of the result structure may
6153be of integer types of any bit width, but they must have the same bit width. The
6154second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6155and <tt>%b</tt> are the two values that will undergo unsigned subtraction.</p>
6156
6157<h5>Semantics:</h5>
6158
6159<p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform
6160an unsigned subtraction of the two arguments. They return a structure &mdash; the
6161first element of which is the subtraction, and the second element of which is a bit
6162specifying if the unsigned subtraction resulted in an overflow.</p>
6163
6164<h5>Examples:</h5>
6165<pre>
6166 %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
6167 %sum = extractvalue {i32, i1} %res, 0
6168 %obit = extractvalue {i32, i1} %res, 1
6169 br i1 %obit, label %overflow, label %normal
6170</pre>
6171
6172</div>
6173
6174<!-- _______________________________________________________________________ -->
6175<div class="doc_subsubsection">
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006176 <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006177</div>
6178
6179<div class="doc_text">
6180
6181<h5>Syntax:</h5>
6182
6183<p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt>
Bill Wendlingfd2bd722009-02-08 04:04:40 +00006184on any integer bit width.</p>
Bill Wendlingf4d70622009-02-08 01:40:31 +00006185
6186<pre>
6187 declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b)
6188 declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6189 declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
6190</pre>
6191
6192<h5>Overview:</h5>
6193
6194<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6195a signed multiplication of the two arguments, and indicate whether an overflow
6196occurred during the signed multiplication.</p>
6197
6198<h5>Arguments:</h5>
6199
6200<p>The arguments (%a and %b) and the first element of the result structure may
6201be of integer types of any bit width, but they must have the same bit width. The
6202second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6203and <tt>%b</tt> are the two values that will undergo signed multiplication.</p>
6204
6205<h5>Semantics:</h5>
6206
6207<p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform
6208a signed multiplication of the two arguments. They return a structure &mdash;
6209the first element of which is the multiplication, and the second element of
6210which is a bit specifying if the signed multiplication resulted in an
6211overflow.</p>
6212
6213<h5>Examples:</h5>
6214<pre>
6215 %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b)
6216 %sum = extractvalue {i32, i1} %res, 0
6217 %obit = extractvalue {i32, i1} %res, 1
6218 br i1 %obit, label %overflow, label %normal
6219</pre>
6220
Reid Spencer5bf54c82007-04-11 23:23:49 +00006221</div>
6222
Bill Wendlingb9a73272009-02-08 23:00:09 +00006223<!-- _______________________________________________________________________ -->
6224<div class="doc_subsubsection">
6225 <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a>
6226</div>
6227
6228<div class="doc_text">
6229
6230<h5>Syntax:</h5>
6231
6232<p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt>
6233on any integer bit width.</p>
6234
6235<pre>
6236 declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b)
6237 declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6238 declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b)
6239</pre>
6240
6241<h5>Overview:</h5>
6242
Bill Wendlingb9a73272009-02-08 23:00:09 +00006243<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6244a unsigned multiplication of the two arguments, and indicate whether an overflow
6245occurred during the unsigned multiplication.</p>
6246
6247<h5>Arguments:</h5>
6248
6249<p>The arguments (%a and %b) and the first element of the result structure may
6250be of integer types of any bit width, but they must have the same bit width. The
6251second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt>
6252and <tt>%b</tt> are the two values that will undergo unsigned
6253multiplication.</p>
6254
6255<h5>Semantics:</h5>
6256
6257<p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform
6258an unsigned multiplication of the two arguments. They return a structure &mdash;
6259the first element of which is the multiplication, and the second element of
6260which is a bit specifying if the unsigned multiplication resulted in an
6261overflow.</p>
6262
6263<h5>Examples:</h5>
6264<pre>
6265 %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b)
6266 %sum = extractvalue {i32, i1} %res, 0
6267 %obit = extractvalue {i32, i1} %res, 1
6268 br i1 %obit, label %overflow, label %normal
6269</pre>
6270
6271</div>
6272
Chris Lattner941515c2004-01-06 05:31:32 +00006273<!-- ======================================================================= -->
6274<div class="doc_subsection">
6275 <a name="int_debugger">Debugger Intrinsics</a>
6276</div>
6277
6278<div class="doc_text">
6279<p>
6280The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
6281are described in the <a
6282href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
6283Debugging</a> document.
6284</p>
6285</div>
6286
6287
Jim Laskey2211f492007-03-14 19:31:19 +00006288<!-- ======================================================================= -->
6289<div class="doc_subsection">
6290 <a name="int_eh">Exception Handling Intrinsics</a>
6291</div>
6292
6293<div class="doc_text">
6294<p> The LLVM exception handling intrinsics (which all start with
6295<tt>llvm.eh.</tt> prefix), are described in the <a
6296href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
6297Handling</a> document. </p>
6298</div>
6299
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006300<!-- ======================================================================= -->
6301<div class="doc_subsection">
Duncan Sands86e01192007-09-11 14:10:23 +00006302 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +00006303</div>
6304
6305<div class="doc_text">
6306<p>
Duncan Sands86e01192007-09-11 14:10:23 +00006307 This intrinsic makes it possible to excise one parameter, marked with
Duncan Sands644f9172007-07-27 12:58:54 +00006308 the <tt>nest</tt> attribute, from a function. The result is a callable
6309 function pointer lacking the nest parameter - the caller does not need
6310 to provide a value for it. Instead, the value to use is stored in
6311 advance in a "trampoline", a block of memory usually allocated
6312 on the stack, which also contains code to splice the nest value into the
6313 argument list. This is used to implement the GCC nested function address
6314 extension.
6315</p>
6316<p>
6317 For example, if the function is
6318 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
Bill Wendling252570f2007-09-22 09:23:55 +00006319 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as follows:</p>
Duncan Sands644f9172007-07-27 12:58:54 +00006320<pre>
Duncan Sands86e01192007-09-11 14:10:23 +00006321 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
6322 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
6323 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
6324 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands644f9172007-07-27 12:58:54 +00006325</pre>
Bill Wendling252570f2007-09-22 09:23:55 +00006326 <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
6327 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
Duncan Sands644f9172007-07-27 12:58:54 +00006328</div>
6329
6330<!-- _______________________________________________________________________ -->
6331<div class="doc_subsubsection">
6332 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
6333</div>
6334<div class="doc_text">
6335<h5>Syntax:</h5>
6336<pre>
Duncan Sands86e01192007-09-11 14:10:23 +00006337declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands644f9172007-07-27 12:58:54 +00006338</pre>
6339<h5>Overview:</h5>
6340<p>
Duncan Sands86e01192007-09-11 14:10:23 +00006341 This fills the memory pointed to by <tt>tramp</tt> with code
6342 and returns a function pointer suitable for executing it.
Duncan Sands644f9172007-07-27 12:58:54 +00006343</p>
6344<h5>Arguments:</h5>
6345<p>
6346 The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
6347 pointers. The <tt>tramp</tt> argument must point to a sufficiently large
6348 and sufficiently aligned block of memory; this memory is written to by the
Duncan Sandsf2bcd372007-08-22 23:39:54 +00006349 intrinsic. Note that the size and the alignment are target-specific - LLVM
6350 currently provides no portable way of determining them, so a front-end that
6351 generates this intrinsic needs to have some target-specific knowledge.
6352 The <tt>func</tt> argument must hold a function bitcast to an <tt>i8*</tt>.
Duncan Sands644f9172007-07-27 12:58:54 +00006353</p>
6354<h5>Semantics:</h5>
6355<p>
6356 The block of memory pointed to by <tt>tramp</tt> is filled with target
Duncan Sands86e01192007-09-11 14:10:23 +00006357 dependent code, turning it into a function. A pointer to this function is
6358 returned, but needs to be bitcast to an
Duncan Sands644f9172007-07-27 12:58:54 +00006359 <a href="#int_trampoline">appropriate function pointer type</a>
Duncan Sands86e01192007-09-11 14:10:23 +00006360 before being called. The new function's signature is the same as that of
6361 <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute
6362 removed. At most one such <tt>nest</tt> argument is allowed, and it must be
6363 of pointer type. Calling the new function is equivalent to calling
6364 <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the
6365 missing <tt>nest</tt> argument. If, after calling
6366 <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is
6367 modified, then the effect of any later call to the returned function pointer is
6368 undefined.
Duncan Sands644f9172007-07-27 12:58:54 +00006369</p>
6370</div>
6371
6372<!-- ======================================================================= -->
6373<div class="doc_subsection">
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006374 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
6375</div>
6376
6377<div class="doc_text">
6378<p>
6379 These intrinsic functions expand the "universal IR" of LLVM to represent
6380 hardware constructs for atomic operations and memory synchronization. This
6381 provides an interface to the hardware, not an interface to the programmer. It
Chris Lattner67c37d12008-08-05 18:29:16 +00006382 is aimed at a low enough level to allow any programming models or APIs
6383 (Application Programming Interfaces) which
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006384 need atomic behaviors to map cleanly onto it. It is also modeled primarily on
6385 hardware behavior. Just as hardware provides a "universal IR" for source
6386 languages, it also provides a starting point for developing a "universal"
6387 atomic operation and synchronization IR.
6388</p>
6389<p>
6390 These do <em>not</em> form an API such as high-level threading libraries,
6391 software transaction memory systems, atomic primitives, and intrinsic
6392 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
6393 application libraries. The hardware interface provided by LLVM should allow
6394 a clean implementation of all of these APIs and parallel programming models.
6395 No one model or paradigm should be selected above others unless the hardware
6396 itself ubiquitously does so.
6397
6398</p>
6399</div>
6400
6401<!-- _______________________________________________________________________ -->
6402<div class="doc_subsubsection">
6403 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
6404</div>
6405<div class="doc_text">
6406<h5>Syntax:</h5>
6407<pre>
6408declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;,
6409i1 &lt;device&gt; )
6410
6411</pre>
6412<h5>Overview:</h5>
6413<p>
6414 The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
6415 specific pairs of memory access types.
6416</p>
6417<h5>Arguments:</h5>
6418<p>
6419 The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
6420 The first four arguments enables a specific barrier as listed below. The fith
6421 argument specifies that the barrier applies to io or device or uncached memory.
6422
6423</p>
6424 <ul>
6425 <li><tt>ll</tt>: load-load barrier</li>
6426 <li><tt>ls</tt>: load-store barrier</li>
6427 <li><tt>sl</tt>: store-load barrier</li>
6428 <li><tt>ss</tt>: store-store barrier</li>
Dan Gohmanef9462f2008-10-14 16:51:45 +00006429 <li><tt>device</tt>: barrier applies to device and uncached memory also.</li>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006430 </ul>
6431<h5>Semantics:</h5>
6432<p>
6433 This intrinsic causes the system to enforce some ordering constraints upon
6434 the loads and stores of the program. This barrier does not indicate
6435 <em>when</em> any events will occur, it only enforces an <em>order</em> in
6436 which they occur. For any of the specified pairs of load and store operations
6437 (f.ex. load-load, or store-load), all of the first operations preceding the
6438 barrier will complete before any of the second operations succeeding the
6439 barrier begin. Specifically the semantics for each pairing is as follows:
6440</p>
6441 <ul>
6442 <li><tt>ll</tt>: All loads before the barrier must complete before any load
6443 after the barrier begins.</li>
6444
6445 <li><tt>ls</tt>: All loads before the barrier must complete before any
6446 store after the barrier begins.</li>
6447 <li><tt>ss</tt>: All stores before the barrier must complete before any
6448 store after the barrier begins.</li>
6449 <li><tt>sl</tt>: All stores before the barrier must complete before any
6450 load after the barrier begins.</li>
6451 </ul>
6452<p>
6453 These semantics are applied with a logical "and" behavior when more than one
6454 is enabled in a single memory barrier intrinsic.
6455</p>
6456<p>
6457 Backends may implement stronger barriers than those requested when they do not
6458 support as fine grained a barrier as requested. Some architectures do not
6459 need all types of barriers and on such architectures, these become noops.
6460</p>
6461<h5>Example:</h5>
6462<pre>
6463%ptr = malloc i32
6464 store i32 4, %ptr
6465
6466%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
6467 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
6468 <i>; guarantee the above finishes</i>
6469 store i32 8, %ptr <i>; before this begins</i>
6470</pre>
6471</div>
6472
Andrew Lenharth95528942008-02-21 06:45:13 +00006473<!-- _______________________________________________________________________ -->
6474<div class="doc_subsubsection">
Mon P Wang6a490372008-06-25 08:15:39 +00006475 <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a>
Andrew Lenharth95528942008-02-21 06:45:13 +00006476</div>
6477<div class="doc_text">
6478<h5>Syntax:</h5>
6479<p>
Mon P Wang2c839d42008-07-30 04:36:53 +00006480 This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on
6481 any integer bit width and for different address spaces. Not all targets
6482 support all bit widths however.</p>
Andrew Lenharth95528942008-02-21 06:45:13 +00006483
6484<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006485declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
6486declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
6487declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
6488declare 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 +00006489
6490</pre>
6491<h5>Overview:</h5>
6492<p>
6493 This loads a value in memory and compares it to a given value. If they are
6494 equal, it stores a new value into the memory.
6495</p>
6496<h5>Arguments:</h5>
6497<p>
Mon P Wang6a490372008-06-25 08:15:39 +00006498 The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result as
Andrew Lenharth95528942008-02-21 06:45:13 +00006499 well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
6500 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
6501 this integer type. While any bit width integer may be used, targets may only
6502 lower representations they support in hardware.
6503
6504</p>
6505<h5>Semantics:</h5>
6506<p>
6507 This entire intrinsic must be executed atomically. It first loads the value
6508 in memory pointed to by <tt>ptr</tt> and compares it with the value
6509 <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The
6510 loaded value is yielded in all cases. This provides the equivalent of an
6511 atomic compare-and-swap operation within the SSA framework.
6512</p>
6513<h5>Examples:</h5>
6514
6515<pre>
6516%ptr = malloc i32
6517 store i32 4, %ptr
6518
6519%val1 = add i32 4, 4
Mon P Wang2c839d42008-07-30 04:36:53 +00006520%result1 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006521 <i>; yields {i32}:result1 = 4</i>
6522%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6523%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6524
6525%val2 = add i32 1, 1
Mon P Wang2c839d42008-07-30 04:36:53 +00006526%result2 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006527 <i>; yields {i32}:result2 = 8</i>
6528%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
6529
6530%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
6531</pre>
6532</div>
6533
6534<!-- _______________________________________________________________________ -->
6535<div class="doc_subsubsection">
6536 <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
6537</div>
6538<div class="doc_text">
6539<h5>Syntax:</h5>
6540
6541<p>
6542 This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
6543 integer bit width. Not all targets support all bit widths however.</p>
6544<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006545declare i8 @llvm.atomic.swap.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
6546declare i16 @llvm.atomic.swap.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
6547declare i32 @llvm.atomic.swap.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
6548declare i64 @llvm.atomic.swap.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
Andrew Lenharth95528942008-02-21 06:45:13 +00006549
6550</pre>
6551<h5>Overview:</h5>
6552<p>
6553 This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
6554 the value from memory. It then stores the value in <tt>val</tt> in the memory
6555 at <tt>ptr</tt>.
6556</p>
6557<h5>Arguments:</h5>
6558
6559<p>
Mon P Wang6a490372008-06-25 08:15:39 +00006560 The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both the
Andrew Lenharth95528942008-02-21 06:45:13 +00006561 <tt>val</tt> argument and the result must be integers of the same bit width.
6562 The first argument, <tt>ptr</tt>, must be a pointer to a value of this
6563 integer type. The targets may only lower integer representations they
6564 support.
6565</p>
6566<h5>Semantics:</h5>
6567<p>
6568 This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
6569 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
6570 equivalent of an atomic swap operation within the SSA framework.
6571
6572</p>
6573<h5>Examples:</h5>
6574<pre>
6575%ptr = malloc i32
6576 store i32 4, %ptr
6577
6578%val1 = add i32 4, 4
Mon P Wang2c839d42008-07-30 04:36:53 +00006579%result1 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006580 <i>; yields {i32}:result1 = 4</i>
6581%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
6582%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
6583
6584%val2 = add i32 1, 1
Mon P Wang2c839d42008-07-30 04:36:53 +00006585%result2 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006586 <i>; yields {i32}:result2 = 8</i>
6587
6588%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
6589%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
6590</pre>
6591</div>
6592
6593<!-- _______________________________________________________________________ -->
6594<div class="doc_subsubsection">
Mon P Wang6a490372008-06-25 08:15:39 +00006595 <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a>
Andrew Lenharth95528942008-02-21 06:45:13 +00006596
6597</div>
6598<div class="doc_text">
6599<h5>Syntax:</h5>
6600<p>
Mon P Wang6a490372008-06-25 08:15:39 +00006601 This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on any
Andrew Lenharth95528942008-02-21 06:45:13 +00006602 integer bit width. Not all targets support all bit widths however.</p>
6603<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006604declare i8 @llvm.atomic.load.add.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6605declare i16 @llvm.atomic.load.add.i16..p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6606declare i32 @llvm.atomic.load.add.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6607declare i64 @llvm.atomic.load.add.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Andrew Lenharth95528942008-02-21 06:45:13 +00006608
6609</pre>
6610<h5>Overview:</h5>
6611<p>
6612 This intrinsic adds <tt>delta</tt> to the value stored in memory at
6613 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
6614</p>
6615<h5>Arguments:</h5>
6616<p>
6617
6618 The intrinsic takes two arguments, the first a pointer to an integer value
6619 and the second an integer value. The result is also an integer value. These
6620 integer types can have any bit width, but they must all have the same bit
6621 width. The targets may only lower integer representations they support.
6622</p>
6623<h5>Semantics:</h5>
6624<p>
6625 This intrinsic does a series of operations atomically. It first loads the
6626 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
6627 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
6628</p>
6629
6630<h5>Examples:</h5>
6631<pre>
6632%ptr = malloc i32
6633 store i32 4, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006634%result1 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006635 <i>; yields {i32}:result1 = 4</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006636%result2 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006637 <i>; yields {i32}:result2 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006638%result3 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 )
Andrew Lenharth95528942008-02-21 06:45:13 +00006639 <i>; yields {i32}:result3 = 10</i>
Mon P Wang6a490372008-06-25 08:15:39 +00006640%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
Andrew Lenharth95528942008-02-21 06:45:13 +00006641</pre>
6642</div>
6643
Mon P Wang6a490372008-06-25 08:15:39 +00006644<!-- _______________________________________________________________________ -->
6645<div class="doc_subsubsection">
6646 <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a>
6647
6648</div>
6649<div class="doc_text">
6650<h5>Syntax:</h5>
6651<p>
6652 This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on
Mon P Wang2c839d42008-07-30 04:36:53 +00006653 any integer bit width and for different address spaces. Not all targets
6654 support all bit widths however.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006655<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006656declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6657declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6658declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6659declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006660
6661</pre>
6662<h5>Overview:</h5>
6663<p>
6664 This intrinsic subtracts <tt>delta</tt> to the value stored in memory at
6665 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
6666</p>
6667<h5>Arguments:</h5>
6668<p>
6669
6670 The intrinsic takes two arguments, the first a pointer to an integer value
6671 and the second an integer value. The result is also an integer value. These
6672 integer types can have any bit width, but they must all have the same bit
6673 width. The targets may only lower integer representations they support.
6674</p>
6675<h5>Semantics:</h5>
6676<p>
6677 This intrinsic does a series of operations atomically. It first loads the
6678 value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the
6679 result to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
6680</p>
6681
6682<h5>Examples:</h5>
6683<pre>
6684%ptr = malloc i32
6685 store i32 8, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006686%result1 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 )
Mon P Wang6a490372008-06-25 08:15:39 +00006687 <i>; yields {i32}:result1 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006688%result2 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 )
Mon P Wang6a490372008-06-25 08:15:39 +00006689 <i>; yields {i32}:result2 = 4</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006690%result3 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 )
Mon P Wang6a490372008-06-25 08:15:39 +00006691 <i>; yields {i32}:result3 = 2</i>
6692%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = -3</i>
6693</pre>
6694</div>
6695
6696<!-- _______________________________________________________________________ -->
6697<div class="doc_subsubsection">
6698 <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br>
6699 <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br>
6700 <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br>
6701 <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br>
6702
6703</div>
6704<div class="doc_text">
6705<h5>Syntax:</h5>
6706<p>
6707 These are overloaded intrinsics. You can use <tt>llvm.atomic.load_and</tt>,
6708 <tt>llvm.atomic.load_nand</tt>, <tt>llvm.atomic.load_or</tt>, and
Mon P Wang2c839d42008-07-30 04:36:53 +00006709 <tt>llvm.atomic.load_xor</tt> on any integer bit width and for different
6710 address spaces. Not all targets support all bit widths however.</p>
Mon P Wang6a490372008-06-25 08:15:39 +00006711<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006712declare i8 @llvm.atomic.load.and.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6713declare i16 @llvm.atomic.load.and.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6714declare i32 @llvm.atomic.load.and.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6715declare i64 @llvm.atomic.load.and.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006716
6717</pre>
6718
6719<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006720declare i8 @llvm.atomic.load.or.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6721declare i16 @llvm.atomic.load.or.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6722declare i32 @llvm.atomic.load.or.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6723declare i64 @llvm.atomic.load.or.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006724
6725</pre>
6726
6727<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006728declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6729declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6730declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6731declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006732
6733</pre>
6734
6735<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006736declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6737declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6738declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6739declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006740
6741</pre>
6742<h5>Overview:</h5>
6743<p>
6744 These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to
6745 the value stored in memory at <tt>ptr</tt>. It yields the original value
6746 at <tt>ptr</tt>.
6747</p>
6748<h5>Arguments:</h5>
6749<p>
6750
6751 These intrinsics take two arguments, the first a pointer to an integer value
6752 and the second an integer value. The result is also an integer value. These
6753 integer types can have any bit width, but they must all have the same bit
6754 width. The targets may only lower integer representations they support.
6755</p>
6756<h5>Semantics:</h5>
6757<p>
6758 These intrinsics does a series of operations atomically. They first load the
6759 value stored at <tt>ptr</tt>. They then do the bitwise operation
6760 <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the original
6761 value stored at <tt>ptr</tt>.
6762</p>
6763
6764<h5>Examples:</h5>
6765<pre>
6766%ptr = malloc i32
6767 store i32 0x0F0F, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006768%result0 = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6a490372008-06-25 08:15:39 +00006769 <i>; yields {i32}:result0 = 0x0F0F</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006770%result1 = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF )
Mon P Wang6a490372008-06-25 08:15:39 +00006771 <i>; yields {i32}:result1 = 0xFFFFFFF0</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006772%result2 = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6a490372008-06-25 08:15:39 +00006773 <i>; yields {i32}:result2 = 0xF0</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006774%result3 = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F )
Mon P Wang6a490372008-06-25 08:15:39 +00006775 <i>; yields {i32}:result3 = FF</i>
6776%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = F0</i>
6777</pre>
6778</div>
6779
6780
6781<!-- _______________________________________________________________________ -->
6782<div class="doc_subsubsection">
6783 <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br>
6784 <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br>
6785 <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br>
6786 <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br>
6787
6788</div>
6789<div class="doc_text">
6790<h5>Syntax:</h5>
6791<p>
6792 These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>,
6793 <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and
Mon P Wang2c839d42008-07-30 04:36:53 +00006794 <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different
6795 address spaces. Not all targets
Mon P Wang6a490372008-06-25 08:15:39 +00006796 support all bit widths however.</p>
6797<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006798declare i8 @llvm.atomic.load.max.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6799declare i16 @llvm.atomic.load.max.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6800declare i32 @llvm.atomic.load.max.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6801declare i64 @llvm.atomic.load.max.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006802
6803</pre>
6804
6805<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006806declare i8 @llvm.atomic.load.min.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6807declare i16 @llvm.atomic.load.min.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6808declare i32 @llvm.atomic.load.min.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6809declare i64 @llvm.atomic.load.min.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006810
6811</pre>
6812
6813<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006814declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6815declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6816declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6817declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006818
6819</pre>
6820
6821<pre>
Mon P Wang2c839d42008-07-30 04:36:53 +00006822declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
6823declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
6824declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
6825declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
Mon P Wang6a490372008-06-25 08:15:39 +00006826
6827</pre>
6828<h5>Overview:</h5>
6829<p>
6830 These intrinsics takes the signed or unsigned minimum or maximum of
6831 <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the
6832 original value at <tt>ptr</tt>.
6833</p>
6834<h5>Arguments:</h5>
6835<p>
6836
6837 These intrinsics take two arguments, the first a pointer to an integer value
6838 and the second an integer value. The result is also an integer value. These
6839 integer types can have any bit width, but they must all have the same bit
6840 width. The targets may only lower integer representations they support.
6841</p>
6842<h5>Semantics:</h5>
6843<p>
6844 These intrinsics does a series of operations atomically. They first load the
6845 value stored at <tt>ptr</tt>. They then do the signed or unsigned min or max
6846 <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They yield
6847 the original value stored at <tt>ptr</tt>.
6848</p>
6849
6850<h5>Examples:</h5>
6851<pre>
6852%ptr = malloc i32
6853 store i32 7, %ptr
Mon P Wang2c839d42008-07-30 04:36:53 +00006854%result0 = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 )
Mon P Wang6a490372008-06-25 08:15:39 +00006855 <i>; yields {i32}:result0 = 7</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006856%result1 = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 )
Mon P Wang6a490372008-06-25 08:15:39 +00006857 <i>; yields {i32}:result1 = -2</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006858%result2 = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 )
Mon P Wang6a490372008-06-25 08:15:39 +00006859 <i>; yields {i32}:result2 = 8</i>
Mon P Wang2c839d42008-07-30 04:36:53 +00006860%result3 = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 )
Mon P Wang6a490372008-06-25 08:15:39 +00006861 <i>; yields {i32}:result3 = 8</i>
6862%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 30</i>
6863</pre>
6864</div>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00006865
6866<!-- ======================================================================= -->
6867<div class="doc_subsection">
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006868 <a name="int_general">General Intrinsics</a>
6869</div>
6870
6871<div class="doc_text">
6872<p> This class of intrinsics is designed to be generic and has
6873no specific purpose. </p>
6874</div>
6875
6876<!-- _______________________________________________________________________ -->
6877<div class="doc_subsubsection">
6878 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
6879</div>
6880
6881<div class="doc_text">
6882
6883<h5>Syntax:</h5>
6884<pre>
Tanya Lattnerbed1d4d2007-06-18 23:42:37 +00006885 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 +00006886</pre>
6887
6888<h5>Overview:</h5>
6889
6890<p>
6891The '<tt>llvm.var.annotation</tt>' intrinsic
6892</p>
6893
6894<h5>Arguments:</h5>
6895
6896<p>
Tanya Lattnerbed1d4d2007-06-18 23:42:37 +00006897The first argument is a pointer to a value, the second is a pointer to a
6898global string, the third is a pointer to a global string which is the source
6899file name, and the last argument is the line number.
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006900</p>
6901
6902<h5>Semantics:</h5>
6903
6904<p>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006905This intrinsic allows annotation of local variables with arbitrary strings.
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006906This can be useful for special purpose optimizations that want to look for these
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006907annotations. These have no other defined use, they are ignored by code
6908generation and optimization.
6909</p>
Tanya Lattnercb1b9602007-06-15 20:50:54 +00006910</div>
6911
Tanya Lattner293c0372007-09-21 22:59:12 +00006912<!-- _______________________________________________________________________ -->
6913<div class="doc_subsubsection">
Tanya Lattner0186a652007-09-21 23:57:59 +00006914 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattner293c0372007-09-21 22:59:12 +00006915</div>
6916
6917<div class="doc_text">
6918
6919<h5>Syntax:</h5>
Tanya Lattner23dbd572007-09-21 23:56:27 +00006920<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
6921any integer bit width.
6922</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00006923<pre>
Tanya Lattnercf3e26f2007-09-22 00:03:01 +00006924 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6925 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6926 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6927 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
6928 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 +00006929</pre>
6930
6931<h5>Overview:</h5>
Tanya Lattner23dbd572007-09-21 23:56:27 +00006932
6933<p>
6934The '<tt>llvm.annotation</tt>' intrinsic.
Tanya Lattner293c0372007-09-21 22:59:12 +00006935</p>
6936
6937<h5>Arguments:</h5>
6938
6939<p>
6940The first argument is an integer value (result of some expression),
6941the second is a pointer to a global string, the third is a pointer to a global
6942string which is the source file name, and the last argument is the line number.
Tanya Lattner23dbd572007-09-21 23:56:27 +00006943It returns the value of the first argument.
Tanya Lattner293c0372007-09-21 22:59:12 +00006944</p>
6945
6946<h5>Semantics:</h5>
6947
6948<p>
6949This intrinsic allows annotations to be put on arbitrary expressions
6950with arbitrary strings. This can be useful for special purpose optimizations
6951that want to look for these annotations. These have no other defined use, they
6952are ignored by code generation and optimization.
Dan Gohmanef9462f2008-10-14 16:51:45 +00006953</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00006954</div>
Jim Laskey2211f492007-03-14 19:31:19 +00006955
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00006956<!-- _______________________________________________________________________ -->
6957<div class="doc_subsubsection">
6958 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
6959</div>
6960
6961<div class="doc_text">
6962
6963<h5>Syntax:</h5>
6964<pre>
6965 declare void @llvm.trap()
6966</pre>
6967
6968<h5>Overview:</h5>
6969
6970<p>
6971The '<tt>llvm.trap</tt>' intrinsic
6972</p>
6973
6974<h5>Arguments:</h5>
6975
6976<p>
6977None
6978</p>
6979
6980<h5>Semantics:</h5>
6981
6982<p>
6983This intrinsics is lowered to the target dependent trap instruction. If the
6984target does not have a trap instruction, this intrinsic will be lowered to the
6985call of the abort() function.
6986</p>
6987</div>
6988
Bill Wendling14313312008-11-19 05:56:17 +00006989<!-- _______________________________________________________________________ -->
6990<div class="doc_subsubsection">
Misha Brukman50de2b22008-11-22 23:55:29 +00006991 <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a>
Bill Wendling14313312008-11-19 05:56:17 +00006992</div>
6993<div class="doc_text">
6994<h5>Syntax:</h5>
6995<pre>
6996declare void @llvm.stackprotector( i8* &lt;guard&gt;, i8** &lt;slot&gt; )
6997
6998</pre>
6999<h5>Overview:</h5>
7000<p>
7001 The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and stores
7002 it onto the stack at <tt>slot</tt>. The stack slot is adjusted to ensure that
7003 it is placed on the stack before local variables.
7004</p>
7005<h5>Arguments:</h5>
7006<p>
7007 The <tt>llvm.stackprotector</tt> intrinsic requires two pointer arguments. The
7008 first argument is the value loaded from the stack guard
7009 <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt> that
7010 has enough space to hold the value of the guard.
7011</p>
7012<h5>Semantics:</h5>
7013<p>
7014 This intrinsic causes the prologue/epilogue inserter to force the position of
7015 the <tt>AllocaInst</tt> stack slot to be before local variables on the
7016 stack. This is to ensure that if a local variable on the stack is overwritten,
7017 it will destroy the value of the guard. When the function exits, the guard on
7018 the stack is checked against the original guard. If they're different, then
7019 the program aborts by calling the <tt>__stack_chk_fail()</tt> function.
7020</p>
7021</div>
7022
Chris Lattner2f7c9632001-06-06 20:29:01 +00007023<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00007024<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00007025<address>
7026 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00007027 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Misha Brukmanc501f552004-03-01 17:47:27 +00007028 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman86242e12008-12-11 17:34:48 +00007029 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Misha Brukmanc501f552004-03-01 17:47:27 +00007030
7031 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00007032 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00007033 Last modified: $Date$
7034</address>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00007035
Misha Brukman76307852003-11-08 01:05:38 +00007036</body>
7037</html>