blob: 515f956ed00af196ed413edf7cd5af19bdf00840 [file] [log] [blame]
Misha Brukmanc501f552004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner0132aff2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
Anton Korobeynikov546ea7e2007-04-29 18:02:48 +000027 <li><a href="#aliasstructure">Aliases</a>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +000028 <li><a href="#paramattrs">Parameter Attributes</a></li>
Gordon Henriksen71183b62007-12-10 03:18:06 +000029 <li><a href="#gc">Garbage Collector Names</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000030 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Reid Spencer50c723a2007-02-19 23:54:10 +000031 <li><a href="#datalayout">Data Layout</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000032 </ol>
33 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000034 <li><a href="#typesystem">Type System</a>
35 <ol>
Chris Lattner7824d182008-01-04 04:32:38 +000036 <li><a href="#t_classifications">Type Classifications</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000037 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000038 <ol>
Chris Lattner7824d182008-01-04 04:32:38 +000039 <li><a href="#t_floating">Floating Point Types</a></li>
40 <li><a href="#t_void">Void Type</a></li>
41 <li><a href="#t_label">Label Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000042 </ol>
43 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000044 <li><a href="#t_derived">Derived Types</a>
45 <ol>
Chris Lattner9a2e3cb2007-12-18 06:18:21 +000046 <li><a href="#t_integer">Integer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000047 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000048 <li><a href="#t_function">Function Type</a></li>
49 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000050 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth8df88e22006-12-08 17:13:00 +000051 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer404a3252007-02-15 03:07:05 +000052 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000053 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000054 </ol>
55 </li>
56 </ol>
57 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000058 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000059 <ol>
60 <li><a href="#simpleconstants">Simple Constants</a>
61 <li><a href="#aggregateconstants">Aggregate Constants</a>
62 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
63 <li><a href="#undefvalues">Undefined Values</a>
64 <li><a href="#constantexprs">Constant Expressions</a>
65 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000066 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000067 <li><a href="#othervalues">Other Values</a>
68 <ol>
69 <li><a href="#inlineasm">Inline Assembler Expressions</a>
70 </ol>
71 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000072 <li><a href="#instref">Instruction Reference</a>
73 <ol>
74 <li><a href="#terminators">Terminator Instructions</a>
75 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000076 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
77 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000078 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
79 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000080 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000081 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000082 </ol>
83 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000084 <li><a href="#binaryops">Binary Operations</a>
85 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000086 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
87 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
88 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +000089 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
90 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
91 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +000092 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
93 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
94 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000095 </ol>
96 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000097 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
98 <ol>
Reid Spencer2ab01932007-02-02 13:57:07 +000099 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
100 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
101 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000102 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000103 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +0000104 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000105 </ol>
106 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000107 <li><a href="#vectorops">Vector Operations</a>
108 <ol>
109 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
110 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
111 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000112 </ol>
113 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000114 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000115 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000116 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
117 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
118 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000119 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
120 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
121 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000122 </ol>
123 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000124 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000125 <ol>
126 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
127 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
128 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
129 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
130 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000131 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
132 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
133 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
134 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000135 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
136 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000137 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000138 </ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000139 <li><a href="#otherops">Other Operations</a>
140 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000141 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
142 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000143 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000144 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000145 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000146 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000147 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000148 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000149 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000150 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000151 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000152 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000153 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
154 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000155 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
156 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
157 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000158 </ol>
159 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000160 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
161 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000162 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
163 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
164 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000165 </ol>
166 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000167 <li><a href="#int_codegen">Code Generator Intrinsics</a>
168 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000169 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
170 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
171 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
172 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
173 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
174 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
175 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000176 </ol>
177 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000178 <li><a href="#int_libc">Standard C Library Intrinsics</a>
179 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000180 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
181 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
182 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
183 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
184 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Dan Gohmanb6324c12007-10-15 20:30:11 +0000185 <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li>
186 <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li>
187 <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000188 </ol>
189 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000190 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000191 <ol>
Reid Spencer96a5f022007-04-04 02:42:35 +0000192 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000193 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
194 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
195 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Reid Spencer5bf54c82007-04-11 23:23:49 +0000196 <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li>
197 <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000198 </ol>
199 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000200 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskey2211f492007-03-14 19:31:19 +0000201 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Duncan Sands86e01192007-09-11 14:10:23 +0000202 <li><a href="#int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +0000203 <ol>
204 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
Duncan Sands644f9172007-07-27 12:58:54 +0000205 </ol>
206 </li>
Andrew Lenharth9b254ee2008-02-16 01:24:58 +0000207 <li><a href="#int_atomics">Atomic intrinsics</a>
208 <ol>
209 <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></li>
210 </ol>
211 </li>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000212 <li><a href="#int_general">General intrinsics</a>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000213 <ol>
Reid Spencer5b2cb0f2007-07-20 19:59:11 +0000214 <li><a href="#int_var_annotation">
Tanya Lattner08abc812007-09-22 00:01:26 +0000215 <tt>llvm.var.annotation</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000216 <li><a href="#int_annotation">
Tanya Lattner08abc812007-09-22 00:01:26 +0000217 <tt>llvm.annotation.*</tt>' Intrinsic</a></li>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +0000218 <li><a href="#int_trap">
219 <tt>llvm.trap</tt>' Intrinsic</a></li>
Tanya Lattner293c0372007-09-21 22:59:12 +0000220 </ol>
Tanya Lattnercb1b9602007-06-15 20:50:54 +0000221 </li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000222 </ol>
223 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000224</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000225
226<div class="doc_author">
227 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
228 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000229</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000230
Chris Lattner2f7c9632001-06-06 20:29:01 +0000231<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000232<div class="doc_section"> <a name="abstract">Abstract </a></div>
233<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000234
Misha Brukman76307852003-11-08 01:05:38 +0000235<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000236<p>This document is a reference manual for the LLVM assembly language.
237LLVM is an SSA based representation that provides type safety,
238low-level operations, flexibility, and the capability of representing
239'all' high-level languages cleanly. It is the common code
240representation used throughout all phases of the LLVM compilation
241strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000242</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000243
Chris Lattner2f7c9632001-06-06 20:29:01 +0000244<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000245<div class="doc_section"> <a name="introduction">Introduction</a> </div>
246<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000247
Misha Brukman76307852003-11-08 01:05:38 +0000248<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000249
Chris Lattner48b383b02003-11-25 01:02:51 +0000250<p>The LLVM code representation is designed to be used in three
Gabor Greifa54634a2007-07-06 22:07:22 +0000251different forms: as an in-memory compiler IR, as an on-disk bitcode
Chris Lattner48b383b02003-11-25 01:02:51 +0000252representation (suitable for fast loading by a Just-In-Time compiler),
253and as a human readable assembly language representation. This allows
254LLVM to provide a powerful intermediate representation for efficient
255compiler transformations and analysis, while providing a natural means
256to debug and visualize the transformations. The three different forms
257of LLVM are all equivalent. This document describes the human readable
258representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000259
John Criswell4a3327e2005-05-13 22:25:59 +0000260<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000261while being expressive, typed, and extensible at the same time. It
262aims to be a "universal IR" of sorts, by being at a low enough level
263that high-level ideas may be cleanly mapped to it (similar to how
264microprocessors are "universal IR's", allowing many source languages to
265be mapped to them). By providing type information, LLVM can be used as
266the target of optimizations: for example, through pointer analysis, it
267can be proven that a C automatic variable is never accessed outside of
268the current function... allowing it to be promoted to a simple SSA
269value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000270
Misha Brukman76307852003-11-08 01:05:38 +0000271</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000272
Chris Lattner2f7c9632001-06-06 20:29:01 +0000273<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000274<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000275
Misha Brukman76307852003-11-08 01:05:38 +0000276<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000277
Chris Lattner48b383b02003-11-25 01:02:51 +0000278<p>It is important to note that this document describes 'well formed'
279LLVM assembly language. There is a difference between what the parser
280accepts and what is considered 'well formed'. For example, the
281following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000282
Bill Wendling3716c5d2007-05-29 09:04:49 +0000283<div class="doc_code">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000284<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000285%x = <a href="#i_add">add</a> i32 1, %x
Chris Lattner757528b0b2004-05-23 21:06:01 +0000286</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000287</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000288
Chris Lattner48b383b02003-11-25 01:02:51 +0000289<p>...because the definition of <tt>%x</tt> does not dominate all of
290its uses. The LLVM infrastructure provides a verification pass that may
291be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000292automatically run by the parser after parsing input assembly and by
Gabor Greifa54634a2007-07-06 22:07:22 +0000293the optimizer before it outputs bitcode. The violations pointed out
Chris Lattner48b383b02003-11-25 01:02:51 +0000294by the verifier pass indicate bugs in transformation passes or input to
295the parser.</p>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000296</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000297
Chris Lattner87a3dbe2007-10-03 17:34:29 +0000298<!-- Describe the typesetting conventions here. -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000299
Chris Lattner2f7c9632001-06-06 20:29:01 +0000300<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000301<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000302<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000303
Misha Brukman76307852003-11-08 01:05:38 +0000304<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000305
Reid Spencerb23b65f2007-08-07 14:34:28 +0000306 <p>LLVM identifiers come in two basic types: global and local. Global
307 identifiers (functions, global variables) begin with the @ character. Local
308 identifiers (register names, types) begin with the % character. Additionally,
309 there are three different formats for identifiers, for different purposes:
Chris Lattner757528b0b2004-05-23 21:06:01 +0000310
Chris Lattner2f7c9632001-06-06 20:29:01 +0000311<ol>
Reid Spencerb23b65f2007-08-07 14:34:28 +0000312 <li>Named values are represented as a string of characters with their prefix.
313 For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual
314 regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
Chris Lattnerd79749a2004-12-09 16:36:40 +0000315 Identifiers which require other characters in their names can be surrounded
Reid Spencerb23b65f2007-08-07 14:34:28 +0000316 with quotes. In this way, anything except a <tt>&quot;</tt> character can
317 be used in a named value.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000318
Reid Spencerb23b65f2007-08-07 14:34:28 +0000319 <li>Unnamed values are represented as an unsigned numeric value with their
320 prefix. For example, %12, @2, %44.</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000321
Reid Spencer8f08d802004-12-09 18:02:53 +0000322 <li>Constants, which are described in a <a href="#constants">section about
323 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000324</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000325
Reid Spencerb23b65f2007-08-07 14:34:28 +0000326<p>LLVM requires that values start with a prefix for two reasons: Compilers
Chris Lattnerd79749a2004-12-09 16:36:40 +0000327don't need to worry about name clashes with reserved words, and the set of
328reserved words may be expanded in the future without penalty. Additionally,
329unnamed identifiers allow a compiler to quickly come up with a temporary
330variable without having to avoid symbol table conflicts.</p>
331
Chris Lattner48b383b02003-11-25 01:02:51 +0000332<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5b950642006-11-11 23:08:07 +0000333languages. There are keywords for different opcodes
334('<tt><a href="#i_add">add</a></tt>',
335 '<tt><a href="#i_bitcast">bitcast</a></tt>',
336 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000337href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnerd79749a2004-12-09 16:36:40 +0000338and others. These reserved words cannot conflict with variable names, because
Reid Spencerb23b65f2007-08-07 14:34:28 +0000339none of them start with a prefix character ('%' or '@').</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000340
341<p>Here is an example of LLVM code to multiply the integer variable
342'<tt>%X</tt>' by 8:</p>
343
Misha Brukman76307852003-11-08 01:05:38 +0000344<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000345
Bill Wendling3716c5d2007-05-29 09:04:49 +0000346<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000347<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000348%result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnerd79749a2004-12-09 16:36:40 +0000349</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000350</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000351
Misha Brukman76307852003-11-08 01:05:38 +0000352<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000353
Bill Wendling3716c5d2007-05-29 09:04:49 +0000354<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000355<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000356%result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnerd79749a2004-12-09 16:36:40 +0000357</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000358</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000359
Misha Brukman76307852003-11-08 01:05:38 +0000360<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000361
Bill Wendling3716c5d2007-05-29 09:04:49 +0000362<div class="doc_code">
Chris Lattnerd79749a2004-12-09 16:36:40 +0000363<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000364<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
365<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
366%result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnerd79749a2004-12-09 16:36:40 +0000367</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000368</div>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000369
Chris Lattner48b383b02003-11-25 01:02:51 +0000370<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
371important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000372
Chris Lattner2f7c9632001-06-06 20:29:01 +0000373<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000374
375 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
376 line.</li>
377
378 <li>Unnamed temporaries are created when the result of a computation is not
379 assigned to a named value.</li>
380
Misha Brukman76307852003-11-08 01:05:38 +0000381 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000382
Misha Brukman76307852003-11-08 01:05:38 +0000383</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000384
John Criswell02fdc6f2005-05-12 16:52:32 +0000385<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000386demonstrating instructions, we will follow an instruction with a comment that
387defines the type and name of value produced. Comments are shown in italic
388text.</p>
389
Misha Brukman76307852003-11-08 01:05:38 +0000390</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000391
392<!-- *********************************************************************** -->
393<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
394<!-- *********************************************************************** -->
395
396<!-- ======================================================================= -->
397<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
398</div>
399
400<div class="doc_text">
401
402<p>LLVM programs are composed of "Module"s, each of which is a
403translation unit of the input programs. Each module consists of
404functions, global variables, and symbol table entries. Modules may be
405combined together with the LLVM linker, which merges function (and
406global variable) definitions, resolves forward declarations, and merges
407symbol table entries. Here is an example of the "hello world" module:</p>
408
Bill Wendling3716c5d2007-05-29 09:04:49 +0000409<div class="doc_code">
Chris Lattner6af02f32004-12-09 16:11:40 +0000410<pre><i>; Declare the string constant as a global constant...</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000411<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
412 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 +0000413
414<i>; External declaration of the puts function</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000415<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000416
417<i>; Definition of main function</i>
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000418define i32 @main() { <i>; i32()* </i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000419 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000420 %cast210 = <a
Chris Lattner2150cde2007-06-12 17:01:15 +0000421 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000422
423 <i>; Call puts function to write out the string to stdout...</i>
424 <a
Chris Lattner2b0bf4f2007-06-12 17:00:26 +0000425 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000426 <a
Bill Wendling3716c5d2007-05-29 09:04:49 +0000427 href="#i_ret">ret</a> i32 0<br>}<br>
428</pre>
429</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000430
431<p>This example is made up of a <a href="#globalvars">global variable</a>
432named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
433function, and a <a href="#functionstructure">function definition</a>
434for "<tt>main</tt>".</p>
435
Chris Lattnerd79749a2004-12-09 16:36:40 +0000436<p>In general, a module is made up of a list of global values,
437where both functions and global variables are global values. Global values are
438represented by a pointer to a memory location (in this case, a pointer to an
439array of char, and a pointer to a function), and have one of the following <a
440href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000441
Chris Lattnerd79749a2004-12-09 16:36:40 +0000442</div>
443
444<!-- ======================================================================= -->
445<div class="doc_subsection">
446 <a name="linkage">Linkage Types</a>
447</div>
448
449<div class="doc_text">
450
451<p>
452All Global Variables and Functions have one of the following types of linkage:
453</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000454
455<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000456
Chris Lattner6af02f32004-12-09 16:11:40 +0000457 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000458
459 <dd>Global values with internal linkage are only directly accessible by
460 objects in the current module. In particular, linking code into a module with
461 an internal global value may cause the internal to be renamed as necessary to
462 avoid collisions. Because the symbol is internal to the module, all
463 references can be updated. This corresponds to the notion of the
Chris Lattnere20b4702007-01-14 06:51:48 +0000464 '<tt>static</tt>' keyword in C.
Chris Lattner6af02f32004-12-09 16:11:40 +0000465 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000466
Chris Lattner6af02f32004-12-09 16:11:40 +0000467 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000468
Chris Lattnere20b4702007-01-14 06:51:48 +0000469 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
470 the same name when linkage occurs. This is typically used to implement
471 inline functions, templates, or other code which must be generated in each
472 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
473 allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000474 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000475
Chris Lattner6af02f32004-12-09 16:11:40 +0000476 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000477
478 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
479 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattnere20b4702007-01-14 06:51:48 +0000480 used for globals that may be emitted in multiple translation units, but that
481 are not guaranteed to be emitted into every translation unit that uses them.
482 One example of this are common globals in C, such as "<tt>int X;</tt>" at
483 global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000484 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000485
Chris Lattner6af02f32004-12-09 16:11:40 +0000486 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000487
488 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
489 pointer to array type. When two global variables with appending linkage are
490 linked together, the two global arrays are appended together. This is the
491 LLVM, typesafe, equivalent of having the system linker append together
492 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000493 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000494
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000495 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
496 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
497 until linked, if not linked, the symbol becomes null instead of being an
498 undefined reference.
499 </dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000500
Chris Lattner6af02f32004-12-09 16:11:40 +0000501 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000502
503 <dd>If none of the above identifiers are used, the global is externally
504 visible, meaning that it participates in linkage and can be used to resolve
505 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000506 </dd>
Reid Spencer7972c472007-04-11 23:49:50 +0000507</dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000508
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000509 <p>
510 The next two types of linkage are targeted for Microsoft Windows platform
511 only. They are designed to support importing (exporting) symbols from (to)
512 DLLs.
513 </p>
514
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000515 <dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000516 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
517
518 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
519 or variable via a global pointer to a pointer that is set up by the DLL
520 exporting the symbol. On Microsoft Windows targets, the pointer name is
521 formed by combining <code>_imp__</code> and the function or variable name.
522 </dd>
523
524 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
525
526 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
527 pointer to a pointer in a DLL, so that it can be referenced with the
528 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
529 name is formed by combining <code>_imp__</code> and the function or variable
530 name.
531 </dd>
532
Chris Lattner6af02f32004-12-09 16:11:40 +0000533</dl>
534
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000535<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattner6af02f32004-12-09 16:11:40 +0000536variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
537variable and was linked with this one, one of the two would be renamed,
538preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
539external (i.e., lacking any linkage declarations), they are accessible
Reid Spencer92c671e2007-01-05 00:59:10 +0000540outside of the current module.</p>
541<p>It is illegal for a function <i>declaration</i>
542to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000543or <tt>extern_weak</tt>.</p>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000544<p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt>
545linkages.
Chris Lattner6af02f32004-12-09 16:11:40 +0000546</div>
547
548<!-- ======================================================================= -->
549<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000550 <a name="callingconv">Calling Conventions</a>
551</div>
552
553<div class="doc_text">
554
555<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
556and <a href="#i_invoke">invokes</a> can all have an optional calling convention
557specified for the call. The calling convention of any pair of dynamic
558caller/callee must match, or the behavior of the program is undefined. The
559following calling conventions are supported by LLVM, and more may be added in
560the future:</p>
561
562<dl>
563 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
564
565 <dd>This calling convention (the default if no other calling convention is
566 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000567 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencer72ba4992006-12-31 21:30:18 +0000568 prototype and implemented declaration of the function (as does normal C).
Chris Lattner0132aff2005-05-06 22:57:40 +0000569 </dd>
570
571 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
572
573 <dd>This calling convention attempts to make calls as fast as possible
574 (e.g. by passing things in registers). This calling convention allows the
575 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000576 without having to conform to an externally specified ABI. Implementations of
577 this convention should allow arbitrary tail call optimization to be supported.
578 This calling convention does not support varargs and requires the prototype of
579 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000580 </dd>
581
582 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
583
584 <dd>This calling convention attempts to make code in the caller as efficient
585 as possible under the assumption that the call is not commonly executed. As
586 such, these calls often preserve all registers so that the call does not break
587 any live ranges in the caller side. This calling convention does not support
588 varargs and requires the prototype of all callees to exactly match the
589 prototype of the function definition.
590 </dd>
591
Chris Lattner573f64e2005-05-07 01:46:40 +0000592 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000593
594 <dd>Any calling convention may be specified by number, allowing
595 target-specific calling conventions to be used. Target specific calling
596 conventions start at 64.
597 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000598</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000599
600<p>More calling conventions can be added/defined on an as-needed basis, to
601support pascal conventions or any other well-known target-independent
602convention.</p>
603
604</div>
605
606<!-- ======================================================================= -->
607<div class="doc_subsection">
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000608 <a name="visibility">Visibility Styles</a>
609</div>
610
611<div class="doc_text">
612
613<p>
614All Global Variables and Functions have one of the following visibility styles:
615</p>
616
617<dl>
618 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
619
620 <dd>On ELF, default visibility means that the declaration is visible to other
621 modules and, in shared libraries, means that the declared entity may be
622 overridden. On Darwin, default visibility means that the declaration is
623 visible to other modules. Default visibility corresponds to "external
624 linkage" in the language.
625 </dd>
626
627 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
628
629 <dd>Two declarations of an object with hidden visibility refer to the same
630 object if they are in the same shared object. Usually, hidden visibility
631 indicates that the symbol will not be placed into the dynamic symbol table,
632 so no other module (executable or shared library) can reference it
633 directly.
634 </dd>
635
Anton Korobeynikov39f3cff2007-04-29 18:35:00 +0000636 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
637
638 <dd>On ELF, protected visibility indicates that the symbol will be placed in
639 the dynamic symbol table, but that references within the defining module will
640 bind to the local symbol. That is, the symbol cannot be overridden by another
641 module.
642 </dd>
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000643</dl>
644
645</div>
646
647<!-- ======================================================================= -->
648<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000649 <a name="globalvars">Global Variables</a>
650</div>
651
652<div class="doc_text">
653
Chris Lattner5d5aede2005-02-12 19:30:21 +0000654<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000655instead of run-time. Global variables may optionally be initialized, may have
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000656an explicit section to be placed in, and may have an optional explicit alignment
657specified. A variable may be defined as "thread_local", which means that it
658will not be shared by threads (each thread will have a separated copy of the
659variable). A variable may be defined as a global "constant," which indicates
660that the contents of the variable will <b>never</b> be modified (enabling better
Chris Lattner5d5aede2005-02-12 19:30:21 +0000661optimization, allowing the global data to be placed in the read-only section of
662an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000663cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000664
665<p>
666LLVM explicitly allows <em>declarations</em> of global variables to be marked
667constant, even if the final definition of the global is not. This capability
668can be used to enable slightly better optimization of the program, but requires
669the language definition to guarantee that optimizations based on the
670'constantness' are valid for the translation units that do not include the
671definition.
672</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000673
674<p>As SSA values, global variables define pointer values that are in
675scope (i.e. they dominate) all basic blocks in the program. Global
676variables always define a pointer to their "content" type because they
677describe a region of memory, and all memory objects in LLVM are
678accessed through pointers.</p>
679
Christopher Lamb308121c2007-12-11 09:31:00 +0000680<p>A global variable may be declared to reside in a target-specifc numbered
681address space. For targets that support them, address spaces may affect how
682optimizations are performed and/or what target instructions are used to access
Christopher Lamb25f50762007-12-12 08:44:39 +0000683the variable. The default address space is zero. The address space qualifier
684must precede any other attributes.</p>
Christopher Lamb308121c2007-12-11 09:31:00 +0000685
Chris Lattner662c8722005-11-12 00:45:07 +0000686<p>LLVM allows an explicit section to be specified for globals. If the target
687supports it, it will emit globals to the section specified.</p>
688
Chris Lattner54611b42005-11-06 08:02:57 +0000689<p>An explicit alignment may be specified for a global. If not present, or if
690the alignment is set to zero, the alignment of the global is set by the target
691to whatever it feels convenient. If an explicit alignment is specified, the
692global is forced to have at least that much alignment. All alignments must be
693a power of 2.</p>
694
Christopher Lamb308121c2007-12-11 09:31:00 +0000695<p>For example, the following defines a global in a numbered address space with
696an initializer, section, and alignment:</p>
Chris Lattner5760c502007-01-14 00:27:09 +0000697
Bill Wendling3716c5d2007-05-29 09:04:49 +0000698<div class="doc_code">
Chris Lattner5760c502007-01-14 00:27:09 +0000699<pre>
Christopher Lamb308121c2007-12-11 09:31:00 +0000700@G = constant float 1.0 addrspace(5), section "foo", align 4
Chris Lattner5760c502007-01-14 00:27:09 +0000701</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000702</div>
Chris Lattner5760c502007-01-14 00:27:09 +0000703
Chris Lattner6af02f32004-12-09 16:11:40 +0000704</div>
705
706
707<!-- ======================================================================= -->
708<div class="doc_subsection">
709 <a name="functionstructure">Functions</a>
710</div>
711
712<div class="doc_text">
713
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000714<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
715an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000716<a href="#visibility">visibility style</a>, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000717<a href="#callingconv">calling convention</a>, a return type, an optional
718<a href="#paramattrs">parameter attribute</a> for the return type, a function
719name, a (possibly empty) argument list (each with optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000720<a href="#paramattrs">parameter attributes</a>), an optional section, an
Gordon Henriksendc5cafb2007-12-10 03:30:21 +0000721optional alignment, an optional <a href="#gc">garbage collector name</a>, an
Gordon Henriksen71183b62007-12-10 03:18:06 +0000722opening curly brace, a list of basic blocks, and a closing curly brace.
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000723
724LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
725optional <a href="#linkage">linkage type</a>, an optional
726<a href="#visibility">visibility style</a>, an optional
727<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000728<a href="#paramattrs">parameter attribute</a> for the return type, a function
Gordon Henriksen71183b62007-12-10 03:18:06 +0000729name, a possibly empty list of arguments, an optional alignment, and an optional
Gordon Henriksendc5cafb2007-12-10 03:30:21 +0000730<a href="#gc">garbage collector name</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000731
732<p>A function definition contains a list of basic blocks, forming the CFG for
733the function. Each basic block may optionally start with a label (giving the
734basic block a symbol table entry), contains a list of instructions, and ends
735with a <a href="#terminators">terminator</a> instruction (such as a branch or
736function return).</p>
737
Chris Lattnera59fb102007-06-08 16:52:14 +0000738<p>The first basic block in a function is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000739executed on entrance to the function, and it is not allowed to have predecessor
740basic blocks (i.e. there can not be any branches to the entry block of a
741function). Because the block can have no predecessors, it also cannot have any
742<a href="#i_phi">PHI nodes</a>.</p>
743
Chris Lattner662c8722005-11-12 00:45:07 +0000744<p>LLVM allows an explicit section to be specified for functions. If the target
745supports it, it will emit functions to the section specified.</p>
746
Chris Lattner54611b42005-11-06 08:02:57 +0000747<p>An explicit alignment may be specified for a function. If not present, or if
748the alignment is set to zero, the alignment of the function is set by the target
749to whatever it feels convenient. If an explicit alignment is specified, the
750function is forced to have at least that much alignment. All alignments must be
751a power of 2.</p>
752
Chris Lattner6af02f32004-12-09 16:11:40 +0000753</div>
754
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000755
756<!-- ======================================================================= -->
757<div class="doc_subsection">
758 <a name="aliasstructure">Aliases</a>
759</div>
760<div class="doc_text">
761 <p>Aliases act as "second name" for the aliasee value (which can be either
Anton Korobeynikovb18f8f82007-04-28 13:45:00 +0000762 function or global variable or bitcast of global value). Aliases may have an
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000763 optional <a href="#linkage">linkage type</a>, and an
764 optional <a href="#visibility">visibility style</a>.</p>
765
766 <h5>Syntax:</h5>
767
Bill Wendling3716c5d2007-05-29 09:04:49 +0000768<div class="doc_code">
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000769<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000770@&lt;Name&gt; = [Linkage] [Visibility] alias &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Bill Wendling2d8b9a82007-05-29 09:42:13 +0000771</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +0000772</div>
Anton Korobeynikova97b6942007-04-25 14:27:10 +0000773
774</div>
775
776
777
Chris Lattner91c15c42006-01-23 23:23:47 +0000778<!-- ======================================================================= -->
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000779<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
780<div class="doc_text">
781 <p>The return type and each parameter of a function type may have a set of
782 <i>parameter attributes</i> associated with them. Parameter attributes are
783 used to communicate additional information about the result or parameters of
Duncan Sandsad0ea2d2007-11-27 13:23:08 +0000784 a function. Parameter attributes are considered to be part of the function,
785 not of the function type, so functions with different parameter attributes
786 can have the same function type.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000787
Reid Spencercf7ebf52007-01-15 18:27:39 +0000788 <p>Parameter attributes are simple keywords that follow the type specified. If
789 multiple parameter attributes are needed, they are space separated. For
Bill Wendling3716c5d2007-05-29 09:04:49 +0000790 example:</p>
791
792<div class="doc_code">
793<pre>
Duncan Sandsad0ea2d2007-11-27 13:23:08 +0000794declare i32 @printf(i8* noalias , ...) nounwind
795declare i32 @atoi(i8*) nounwind readonly
Bill Wendling3716c5d2007-05-29 09:04:49 +0000796</pre>
797</div>
798
Duncan Sandsad0ea2d2007-11-27 13:23:08 +0000799 <p>Note that any attributes for the function result (<tt>nounwind</tt>,
800 <tt>readonly</tt>) come immediately after the argument list.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000801
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000802 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000803 <dl>
Reid Spencer314e1cb2007-07-19 23:13:04 +0000804 <dt><tt>zeroext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000805 <dd>This indicates that the parameter should be zero extended just before
806 a call to this function.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000807
Reid Spencer314e1cb2007-07-19 23:13:04 +0000808 <dt><tt>signext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000809 <dd>This indicates that the parameter should be sign extended just before
810 a call to this function.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000811
Anton Korobeynikove8166852007-01-28 14:30:45 +0000812 <dt><tt>inreg</tt></dt>
813 <dd>This indicates that the parameter should be placed in register (if
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000814 possible) during assembling function call. Support for this attribute is
815 target-specific</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000816
817 <dt><tt>byval</tt></dt>
Chris Lattner352ab9b2008-01-15 04:34:22 +0000818 <dd>This indicates that the pointer parameter should really be passed by
819 value to the function. The attribute implies that a hidden copy of the
820 pointee is made between the caller and the callee, so the callee is unable
821 to modify the value in the callee. This attribute is only valid on llvm
822 pointer arguments. It is generally used to pass structs and arrays by
823 value, but is also valid on scalars (even though this is silly).</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000824
Anton Korobeynikove8166852007-01-28 14:30:45 +0000825 <dt><tt>sret</tt></dt>
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000826 <dd>This indicates that the parameter specifies the address of a structure
Reid Spencer05dbb9d2007-03-22 02:02:11 +0000827 that is the return value of the function in the source program.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000828
Zhou Sheng2444a9a2007-06-05 05:28:26 +0000829 <dt><tt>noalias</tt></dt>
Owen Anderson61101282008-02-18 04:09:01 +0000830 <dd>This indicates that the parameter does not alias any global or any other
831 parameter. The caller is responsible for ensuring that this is the case,
832 usually by placing the value in a stack allocation.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000833
Reid Spencer9d1700e2007-03-22 02:18:56 +0000834 <dt><tt>noreturn</tt></dt>
835 <dd>This function attribute indicates that the function never returns. This
836 indicates to LLVM that every call to this function should be treated as if
837 an <tt>unreachable</tt> instruction immediately followed the call.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000838
Reid Spencer05dbb9d2007-03-22 02:02:11 +0000839 <dt><tt>nounwind</tt></dt>
840 <dd>This function attribute indicates that the function type does not use
841 the unwind instruction and does not allow stack unwinding to propagate
842 through it.</dd>
Chris Lattner5cee13f2008-01-11 06:20:47 +0000843
Duncan Sands27e91592007-07-27 19:57:41 +0000844 <dt><tt>nest</tt></dt>
845 <dd>This indicates that the parameter can be excised using the
846 <a href="#int_trampoline">trampoline intrinsics</a>.</dd>
Duncan Sandsa89a1132007-11-22 20:23:04 +0000847 <dt><tt>readonly</tt></dt>
Duncan Sands730a3262007-11-14 21:14:02 +0000848 <dd>This function attribute indicates that the function has no side-effects
Duncan Sandsa89a1132007-11-22 20:23:04 +0000849 except for producing a return value or throwing an exception. The value
850 returned must only depend on the function arguments and/or global variables.
851 It may use values obtained by dereferencing pointers.</dd>
852 <dt><tt>readnone</tt></dt>
853 <dd>A <tt>readnone</tt> function has the same restrictions as a <tt>readonly</tt>
Duncan Sands730a3262007-11-14 21:14:02 +0000854 function, but in addition it is not allowed to dereference any pointer arguments
855 or global variables.
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000856 </dl>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000857
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000858</div>
859
860<!-- ======================================================================= -->
Chris Lattner91c15c42006-01-23 23:23:47 +0000861<div class="doc_subsection">
Gordon Henriksen71183b62007-12-10 03:18:06 +0000862 <a name="gc">Garbage Collector Names</a>
863</div>
864
865<div class="doc_text">
866<p>Each function may specify a garbage collector name, which is simply a
867string.</p>
868
869<div class="doc_code"><pre
870>define void @f() gc "name" { ...</pre></div>
871
872<p>The compiler declares the supported values of <i>name</i>. Specifying a
873collector which will cause the compiler to alter its output in order to support
874the named garbage collection algorithm.</p>
875</div>
876
877<!-- ======================================================================= -->
878<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +0000879 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +0000880</div>
881
882<div class="doc_text">
883<p>
884Modules may contain "module-level inline asm" blocks, which corresponds to the
885GCC "file scope inline asm" blocks. These blocks are internally concatenated by
886LLVM and treated as a single unit, but may be separated in the .ll file if
887desired. The syntax is very simple:
888</p>
889
Bill Wendling3716c5d2007-05-29 09:04:49 +0000890<div class="doc_code">
891<pre>
892module asm "inline asm code goes here"
893module asm "more can go here"
894</pre>
895</div>
Chris Lattner91c15c42006-01-23 23:23:47 +0000896
897<p>The strings can contain any character by escaping non-printable characters.
898 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
899 for the number.
900</p>
901
902<p>
903 The inline asm code is simply printed to the machine code .s file when
904 assembly code is generated.
905</p>
906</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000907
Reid Spencer50c723a2007-02-19 23:54:10 +0000908<!-- ======================================================================= -->
909<div class="doc_subsection">
910 <a name="datalayout">Data Layout</a>
911</div>
912
913<div class="doc_text">
914<p>A module may specify a target specific data layout string that specifies how
Reid Spencer7972c472007-04-11 23:49:50 +0000915data is to be laid out in memory. The syntax for the data layout is simply:</p>
916<pre> target datalayout = "<i>layout specification</i>"</pre>
917<p>The <i>layout specification</i> consists of a list of specifications
918separated by the minus sign character ('-'). Each specification starts with a
919letter and may include other information after the letter to define some
920aspect of the data layout. The specifications accepted are as follows: </p>
Reid Spencer50c723a2007-02-19 23:54:10 +0000921<dl>
922 <dt><tt>E</tt></dt>
923 <dd>Specifies that the target lays out data in big-endian form. That is, the
924 bits with the most significance have the lowest address location.</dd>
925 <dt><tt>e</tt></dt>
926 <dd>Specifies that hte target lays out data in little-endian form. That is,
927 the bits with the least significance have the lowest address location.</dd>
928 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
929 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
930 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
931 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
932 too.</dd>
933 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
934 <dd>This specifies the alignment for an integer type of a given bit
935 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
936 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
937 <dd>This specifies the alignment for a vector type of a given bit
938 <i>size</i>.</dd>
939 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
940 <dd>This specifies the alignment for a floating point type of a given bit
941 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
942 (double).</dd>
943 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
944 <dd>This specifies the alignment for an aggregate type of a given bit
945 <i>size</i>.</dd>
946</dl>
947<p>When constructing the data layout for a given target, LLVM starts with a
948default set of specifications which are then (possibly) overriden by the
949specifications in the <tt>datalayout</tt> keyword. The default specifications
950are given in this list:</p>
951<ul>
952 <li><tt>E</tt> - big endian</li>
953 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
954 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
955 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
956 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
957 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
958 <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred
959 alignment of 64-bits</li>
960 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
961 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
962 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
963 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
964 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
965</ul>
966<p>When llvm is determining the alignment for a given type, it uses the
967following rules:
968<ol>
969 <li>If the type sought is an exact match for one of the specifications, that
970 specification is used.</li>
971 <li>If no match is found, and the type sought is an integer type, then the
972 smallest integer type that is larger than the bitwidth of the sought type is
973 used. If none of the specifications are larger than the bitwidth then the the
974 largest integer type is used. For example, given the default specifications
975 above, the i7 type will use the alignment of i8 (next largest) while both
976 i65 and i256 will use the alignment of i64 (largest specified).</li>
977 <li>If no match is found, and the type sought is a vector type, then the
978 largest vector type that is smaller than the sought vector type will be used
979 as a fall back. This happens because <128 x double> can be implemented in
980 terms of 64 <2 x double>, for example.</li>
981</ol>
982</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000983
Chris Lattner2f7c9632001-06-06 20:29:01 +0000984<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000985<div class="doc_section"> <a name="typesystem">Type System</a> </div>
986<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000987
Misha Brukman76307852003-11-08 01:05:38 +0000988<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000989
Misha Brukman76307852003-11-08 01:05:38 +0000990<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000991intermediate representation. Being typed enables a number of
992optimizations to be performed on the IR directly, without having to do
993extra analyses on the side before the transformation. A strong type
994system makes it easier to read the generated code and enables novel
995analyses and transformations that are not feasible to perform on normal
996three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000997
998</div>
999
Chris Lattner2f7c9632001-06-06 20:29:01 +00001000<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001001<div class="doc_subsection"> <a name="t_classifications">Type
Chris Lattner48b383b02003-11-25 01:02:51 +00001002Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001003<div class="doc_text">
Chris Lattner7824d182008-01-04 04:32:38 +00001004<p>The types fall into a few useful
Chris Lattner48b383b02003-11-25 01:02:51 +00001005classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001006
1007<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001008 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001009 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001010 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001011 <td><a href="#t_integer">integer</a></td>
Reid Spencer138249b2007-05-16 18:44:01 +00001012 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001013 </tr>
1014 <tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001015 <td><a href="#t_floating">floating point</a></td>
1016 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001017 </tr>
1018 <tr>
1019 <td><a name="t_firstclass">first class</a></td>
Chris Lattner7824d182008-01-04 04:32:38 +00001020 <td><a href="#t_integer">integer</a>,
1021 <a href="#t_floating">floating point</a>,
1022 <a href="#t_pointer">pointer</a>,
1023 <a href="#t_vector">vector</a>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001024 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +00001025 </tr>
Chris Lattner7824d182008-01-04 04:32:38 +00001026 <tr>
1027 <td><a href="#t_primitive">primitive</a></td>
1028 <td><a href="#t_label">label</a>,
1029 <a href="#t_void">void</a>,
1030 <a href="#t_integer">integer</a>,
1031 <a href="#t_floating">floating point</a>.</td>
1032 </tr>
1033 <tr>
1034 <td><a href="#t_derived">derived</a></td>
1035 <td><a href="#t_integer">integer</a>,
1036 <a href="#t_array">array</a>,
1037 <a href="#t_function">function</a>,
1038 <a href="#t_pointer">pointer</a>,
1039 <a href="#t_struct">structure</a>,
1040 <a href="#t_pstruct">packed structure</a>,
1041 <a href="#t_vector">vector</a>,
1042 <a href="#t_opaque">opaque</a>.
1043 </tr>
Chris Lattner48b383b02003-11-25 01:02:51 +00001044 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +00001045</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001046
Chris Lattner48b383b02003-11-25 01:02:51 +00001047<p>The <a href="#t_firstclass">first class</a> types are perhaps the
1048most important. Values of these types are the only ones which can be
1049produced by instructions, passed as arguments, or used as operands to
1050instructions. This means that all structures and arrays must be
1051manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001052</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001053
Chris Lattner2f7c9632001-06-06 20:29:01 +00001054<!-- ======================================================================= -->
Chris Lattner7824d182008-01-04 04:32:38 +00001055<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner43542b32008-01-04 04:34:14 +00001056
Chris Lattner7824d182008-01-04 04:32:38 +00001057<div class="doc_text">
1058<p>The primitive types are the fundamental building blocks of the LLVM
1059system.</p>
1060
Chris Lattner43542b32008-01-04 04:34:14 +00001061</div>
1062
Chris Lattner7824d182008-01-04 04:32:38 +00001063<!-- _______________________________________________________________________ -->
1064<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1065
1066<div class="doc_text">
1067 <table>
1068 <tbody>
1069 <tr><th>Type</th><th>Description</th></tr>
1070 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1071 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1072 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1073 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1074 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1075 </tbody>
1076 </table>
1077</div>
1078
1079<!-- _______________________________________________________________________ -->
1080<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1081
1082<div class="doc_text">
1083<h5>Overview:</h5>
1084<p>The void type does not represent any value and has no size.</p>
1085
1086<h5>Syntax:</h5>
1087
1088<pre>
1089 void
1090</pre>
1091</div>
1092
1093<!-- _______________________________________________________________________ -->
1094<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1095
1096<div class="doc_text">
1097<h5>Overview:</h5>
1098<p>The label type represents code labels.</p>
1099
1100<h5>Syntax:</h5>
1101
1102<pre>
1103 label
1104</pre>
1105</div>
1106
1107
1108<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001109<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001110
Misha Brukman76307852003-11-08 01:05:38 +00001111<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001112
Chris Lattner48b383b02003-11-25 01:02:51 +00001113<p>The real power in LLVM comes from the derived types in the system.
1114This is what allows a programmer to represent arrays, functions,
1115pointers, and other useful types. Note that these derived types may be
1116recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001117
Misha Brukman76307852003-11-08 01:05:38 +00001118</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001119
Chris Lattner2f7c9632001-06-06 20:29:01 +00001120<!-- _______________________________________________________________________ -->
Reid Spencer138249b2007-05-16 18:44:01 +00001121<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1122
1123<div class="doc_text">
1124
1125<h5>Overview:</h5>
1126<p>The integer type is a very simple derived type that simply specifies an
1127arbitrary bit width for the integer type desired. Any bit width from 1 bit to
11282^23-1 (about 8 million) can be specified.</p>
1129
1130<h5>Syntax:</h5>
1131
1132<pre>
1133 iN
1134</pre>
1135
1136<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1137value.</p>
1138
1139<h5>Examples:</h5>
1140<table class="layout">
Chris Lattner9a2e3cb2007-12-18 06:18:21 +00001141 <tbody>
1142 <tr>
1143 <td><tt>i1</tt></td>
1144 <td>a single-bit integer.</td>
1145 </tr><tr>
1146 <td><tt>i32</tt></td>
1147 <td>a 32-bit integer.</td>
1148 </tr><tr>
1149 <td><tt>i1942652</tt></td>
1150 <td>a really big integer of over 1 million bits.</td>
Reid Spencer138249b2007-05-16 18:44:01 +00001151 </tr>
Chris Lattner9a2e3cb2007-12-18 06:18:21 +00001152 </tbody>
Reid Spencer138249b2007-05-16 18:44:01 +00001153</table>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001154</div>
Reid Spencer138249b2007-05-16 18:44:01 +00001155
1156<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001157<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001158
Misha Brukman76307852003-11-08 01:05:38 +00001159<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001160
Chris Lattner2f7c9632001-06-06 20:29:01 +00001161<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +00001162
Misha Brukman76307852003-11-08 01:05:38 +00001163<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +00001164sequentially in memory. The array type requires a size (number of
1165elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001166
Chris Lattner590645f2002-04-14 06:13:44 +00001167<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +00001168
1169<pre>
1170 [&lt;# elements&gt; x &lt;elementtype&gt;]
1171</pre>
1172
John Criswell02fdc6f2005-05-12 16:52:32 +00001173<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +00001174be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001175
Chris Lattner590645f2002-04-14 06:13:44 +00001176<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001177<table class="layout">
1178 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001179 <td class="left"><tt>[40 x i32]</tt></td>
1180 <td class="left">Array of 40 32-bit integer values.</td>
1181 </tr>
1182 <tr class="layout">
1183 <td class="left"><tt>[41 x i32]</tt></td>
1184 <td class="left">Array of 41 32-bit integer values.</td>
1185 </tr>
1186 <tr class="layout">
1187 <td class="left"><tt>[4 x i8]</tt></td>
1188 <td class="left">Array of 4 8-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001189 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001190</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001191<p>Here are some examples of multidimensional arrays:</p>
1192<table class="layout">
1193 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001194 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1195 <td class="left">3x4 array of 32-bit integer values.</td>
1196 </tr>
1197 <tr class="layout">
1198 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1199 <td class="left">12x10 array of single precision floating point values.</td>
1200 </tr>
1201 <tr class="layout">
1202 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1203 <td class="left">2x3x4 array of 16-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001204 </tr>
1205</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001206
John Criswell4c0cf7f2005-10-24 16:17:18 +00001207<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1208length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001209LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1210As a special case, however, zero length arrays are recognized to be variable
1211length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001212type "{ i32, [0 x float]}", for example.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00001213
Misha Brukman76307852003-11-08 01:05:38 +00001214</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001215
Chris Lattner2f7c9632001-06-06 20:29:01 +00001216<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001217<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001218<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001219<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001220<p>The function type can be thought of as a function signature. It
1221consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +00001222Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +00001223(which are structures of pointers to functions), for indirect function
1224calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +00001225<p>
1226The return type of a function type cannot be an aggregate type.
1227</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001228<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001229<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +00001230<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +00001231specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +00001232which indicates that the function takes a variable number of arguments.
1233Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001234 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001235<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001236<table class="layout">
1237 <tr class="layout">
Reid Spencer58c08712006-12-31 07:18:34 +00001238 <td class="left"><tt>i32 (i32)</tt></td>
1239 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001240 </td>
Reid Spencer58c08712006-12-31 07:18:34 +00001241 </tr><tr class="layout">
Reid Spencer314e1cb2007-07-19 23:13:04 +00001242 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencer655dcc62006-12-31 07:20:23 +00001243 </tt></td>
Reid Spencer58c08712006-12-31 07:18:34 +00001244 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1245 an <tt>i16</tt> that should be sign extended and a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001246 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer58c08712006-12-31 07:18:34 +00001247 <tt>float</tt>.
1248 </td>
1249 </tr><tr class="layout">
1250 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1251 <td class="left">A vararg function that takes at least one
Reid Spencer3e628eb92007-01-04 16:43:23 +00001252 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer58c08712006-12-31 07:18:34 +00001253 which returns an integer. This is the signature for <tt>printf</tt> in
1254 LLVM.
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001255 </td>
1256 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001257</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001258
Misha Brukman76307852003-11-08 01:05:38 +00001259</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001260<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001261<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001262<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001263<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001264<p>The structure type is used to represent a collection of data members
1265together in memory. The packing of the field types is defined to match
1266the ABI of the underlying processor. The elements of a structure may
1267be any type that has a size.</p>
1268<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1269and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1270field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1271instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001272<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001273<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001274<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001275<table class="layout">
1276 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001277 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1278 <td class="left">A triple of three <tt>i32</tt> values</td>
1279 </tr><tr class="layout">
1280 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1281 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1282 second element is a <a href="#t_pointer">pointer</a> to a
1283 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1284 an <tt>i32</tt>.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001285 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001286</table>
Misha Brukman76307852003-11-08 01:05:38 +00001287</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001288
Chris Lattner2f7c9632001-06-06 20:29:01 +00001289<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001290<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1291</div>
1292<div class="doc_text">
1293<h5>Overview:</h5>
1294<p>The packed structure type is used to represent a collection of data members
1295together in memory. There is no padding between fields. Further, the alignment
1296of a packed structure is 1 byte. The elements of a packed structure may
1297be any type that has a size.</p>
1298<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1299and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1300field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1301instruction.</p>
1302<h5>Syntax:</h5>
1303<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1304<h5>Examples:</h5>
1305<table class="layout">
1306 <tr class="layout">
Jeff Cohen5819f182007-04-22 01:17:39 +00001307 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1308 <td class="left">A triple of three <tt>i32</tt> values</td>
1309 </tr><tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001310 <td class="left"><tt>&lt; { float, i32 (i32)* } &gt;</tt></td>
Jeff Cohen5819f182007-04-22 01:17:39 +00001311 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1312 second element is a <a href="#t_pointer">pointer</a> to a
1313 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1314 an <tt>i32</tt>.</td>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001315 </tr>
1316</table>
1317</div>
1318
1319<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001320<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001321<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001322<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001323<p>As in many languages, the pointer type represents a pointer or
Christopher Lamb308121c2007-12-11 09:31:00 +00001324reference to another object, which must live in memory. Pointer types may have
1325an optional address space attribute defining the target-specific numbered
1326address space where the pointed-to object resides. The default address space is
1327zero.</p>
Chris Lattner590645f2002-04-14 06:13:44 +00001328<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001329<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001330<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001331<table class="layout">
1332 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001333 <td class="left"><tt>[4x i32]*</tt></td>
1334 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1335 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1336 </tr>
1337 <tr class="layout">
1338 <td class="left"><tt>i32 (i32 *) *</tt></td>
1339 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001340 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner747359f2007-12-19 05:04:11 +00001341 <tt>i32</tt>.</td>
1342 </tr>
1343 <tr class="layout">
1344 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1345 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1346 that resides in address space #5.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001347 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001348</table>
Misha Brukman76307852003-11-08 01:05:38 +00001349</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001350
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001351<!-- _______________________________________________________________________ -->
Reid Spencer404a3252007-02-15 03:07:05 +00001352<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001353<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001354
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001355<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001356
Reid Spencer404a3252007-02-15 03:07:05 +00001357<p>A vector type is a simple derived type that represents a vector
1358of elements. Vector types are used when multiple primitive data
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001359are operated in parallel using a single instruction (SIMD).
Reid Spencer404a3252007-02-15 03:07:05 +00001360A vector type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +00001361elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer404a3252007-02-15 03:07:05 +00001362of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001363considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001364
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001365<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001366
1367<pre>
1368 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1369</pre>
1370
John Criswell4a3327e2005-05-13 22:25:59 +00001371<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001372be any integer or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001373
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001374<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001375
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001376<table class="layout">
1377 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001378 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1379 <td class="left">Vector of 4 32-bit integer values.</td>
1380 </tr>
1381 <tr class="layout">
1382 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1383 <td class="left">Vector of 8 32-bit floating-point values.</td>
1384 </tr>
1385 <tr class="layout">
1386 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1387 <td class="left">Vector of 2 64-bit integer values.</td>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001388 </tr>
1389</table>
Misha Brukman76307852003-11-08 01:05:38 +00001390</div>
1391
Chris Lattner37b6b092005-04-25 17:34:15 +00001392<!-- _______________________________________________________________________ -->
1393<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1394<div class="doc_text">
1395
1396<h5>Overview:</h5>
1397
1398<p>Opaque types are used to represent unknown types in the system. This
Gordon Henriksena699c4d2007-10-14 00:34:53 +00001399corresponds (for example) to the C notion of a forward declared structure type.
Chris Lattner37b6b092005-04-25 17:34:15 +00001400In LLVM, opaque types can eventually be resolved to any type (not just a
1401structure type).</p>
1402
1403<h5>Syntax:</h5>
1404
1405<pre>
1406 opaque
1407</pre>
1408
1409<h5>Examples:</h5>
1410
1411<table class="layout">
1412 <tr class="layout">
Chris Lattner747359f2007-12-19 05:04:11 +00001413 <td class="left"><tt>opaque</tt></td>
1414 <td class="left">An opaque type.</td>
Chris Lattner37b6b092005-04-25 17:34:15 +00001415 </tr>
1416</table>
1417</div>
1418
1419
Chris Lattner74d3f822004-12-09 17:30:23 +00001420<!-- *********************************************************************** -->
1421<div class="doc_section"> <a name="constants">Constants</a> </div>
1422<!-- *********************************************************************** -->
1423
1424<div class="doc_text">
1425
1426<p>LLVM has several different basic types of constants. This section describes
1427them all and their syntax.</p>
1428
1429</div>
1430
1431<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001432<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001433
1434<div class="doc_text">
1435
1436<dl>
1437 <dt><b>Boolean constants</b></dt>
1438
1439 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencer36a15422007-01-12 03:35:51 +00001440 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattner74d3f822004-12-09 17:30:23 +00001441 </dd>
1442
1443 <dt><b>Integer constants</b></dt>
1444
Reid Spencer8f08d802004-12-09 18:02:53 +00001445 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencer3e628eb92007-01-04 16:43:23 +00001446 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattner74d3f822004-12-09 17:30:23 +00001447 integer types.
1448 </dd>
1449
1450 <dt><b>Floating point constants</b></dt>
1451
1452 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1453 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +00001454 notation (see below). Floating point constants must have a <a
1455 href="#t_floating">floating point</a> type. </dd>
1456
1457 <dt><b>Null pointer constants</b></dt>
1458
John Criswelldfe6a862004-12-10 15:51:16 +00001459 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001460 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1461
1462</dl>
1463
John Criswelldfe6a862004-12-10 15:51:16 +00001464<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001465of floating point constants. For example, the form '<tt>double
14660x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
14674.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001468(and the only time that they are generated by the disassembler) is when a
1469floating point constant must be emitted but it cannot be represented as a
1470decimal floating point number. For example, NaN's, infinities, and other
1471special values are represented in their IEEE hexadecimal format so that
1472assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001473
1474</div>
1475
1476<!-- ======================================================================= -->
1477<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1478</div>
1479
1480<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +00001481<p>Aggregate constants arise from aggregation of simple constants
1482and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001483
1484<dl>
1485 <dt><b>Structure constants</b></dt>
1486
1487 <dd>Structure constants are represented with notation similar to structure
1488 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattnerbea11172007-12-25 20:34:52 +00001489 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1490 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>". Structure constants
Chris Lattner455fc8c2005-03-07 22:13:59 +00001491 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001492 types of elements must match those specified by the type.
1493 </dd>
1494
1495 <dt><b>Array constants</b></dt>
1496
1497 <dd>Array constants are represented with notation similar to array type
1498 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001499 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001500 constants must have <a href="#t_array">array type</a>, and the number and
1501 types of elements must match those specified by the type.
1502 </dd>
1503
Reid Spencer404a3252007-02-15 03:07:05 +00001504 <dt><b>Vector constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001505
Reid Spencer404a3252007-02-15 03:07:05 +00001506 <dd>Vector constants are represented with notation similar to vector type
Chris Lattner74d3f822004-12-09 17:30:23 +00001507 definitions (a comma separated list of elements, surrounded by
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001508 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Jeff Cohen5819f182007-04-22 01:17:39 +00001509 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
Reid Spencer404a3252007-02-15 03:07:05 +00001510 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattner74d3f822004-12-09 17:30:23 +00001511 match those specified by the type.
1512 </dd>
1513
1514 <dt><b>Zero initialization</b></dt>
1515
1516 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1517 value to zero of <em>any</em> type, including scalar and aggregate types.
1518 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001519 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001520 initializers.
1521 </dd>
1522</dl>
1523
1524</div>
1525
1526<!-- ======================================================================= -->
1527<div class="doc_subsection">
1528 <a name="globalconstants">Global Variable and Function Addresses</a>
1529</div>
1530
1531<div class="doc_text">
1532
1533<p>The addresses of <a href="#globalvars">global variables</a> and <a
1534href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001535constants. These constants are explicitly referenced when the <a
1536href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001537href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1538file:</p>
1539
Bill Wendling3716c5d2007-05-29 09:04:49 +00001540<div class="doc_code">
Chris Lattner74d3f822004-12-09 17:30:23 +00001541<pre>
Chris Lattner00538a12007-06-06 18:28:13 +00001542@X = global i32 17
1543@Y = global i32 42
1544@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
Chris Lattner74d3f822004-12-09 17:30:23 +00001545</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001546</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001547
1548</div>
1549
1550<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001551<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001552<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001553 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001554 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001555 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001556
Reid Spencer641f5c92004-12-09 18:13:12 +00001557 <p>Undefined values indicate to the compiler that the program is well defined
1558 no matter what value is used, giving the compiler more freedom to optimize.
1559 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001560</div>
1561
1562<!-- ======================================================================= -->
1563<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1564</div>
1565
1566<div class="doc_text">
1567
1568<p>Constant expressions are used to allow expressions involving other constants
1569to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001570href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001571that does not have side effects (e.g. load and call are not supported). The
1572following is the syntax for constant expressions:</p>
1573
1574<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001575 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1576 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001577 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001578
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001579 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1580 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001581 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001582
1583 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1584 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001585 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001586
1587 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1588 <dd>Truncate a floating point constant to another floating point type. The
1589 size of CST must be larger than the size of TYPE. Both types must be
1590 floating point.</dd>
1591
1592 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1593 <dd>Floating point extend a constant to another type. The size of CST must be
1594 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1595
Reid Spencer753163d2007-07-31 14:40:14 +00001596 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001597 <dd>Convert a floating point constant to the corresponding unsigned integer
Nate Begemand4d45c22007-11-17 03:58:34 +00001598 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
1599 or vector floating point type. Both CST and TYPE must be scalars, or vectors
1600 of the same number of elements. If the value won't fit in the integer type,
1601 the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001602
Reid Spencer51b07252006-11-09 23:03:26 +00001603 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001604 <dd>Convert a floating point constant to the corresponding signed integer
Nate Begemand4d45c22007-11-17 03:58:34 +00001605 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
1606 or vector floating point type. Both CST and TYPE must be scalars, or vectors
1607 of the same number of elements. If the value won't fit in the integer type,
1608 the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001609
Reid Spencer51b07252006-11-09 23:03:26 +00001610 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001611 <dd>Convert an unsigned integer constant to the corresponding floating point
Nate Begemand4d45c22007-11-17 03:58:34 +00001612 constant. TYPE must be a scalar or vector floating point type. CST must be of
1613 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
1614 of the same number of elements. If the value won't fit in the floating point
1615 type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001616
Reid Spencer51b07252006-11-09 23:03:26 +00001617 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001618 <dd>Convert a signed integer constant to the corresponding floating point
Nate Begemand4d45c22007-11-17 03:58:34 +00001619 constant. TYPE must be a scalar or vector floating point type. CST must be of
1620 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
1621 of the same number of elements. If the value won't fit in the floating point
1622 type, the results are undefined.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001623
Reid Spencer5b950642006-11-11 23:08:07 +00001624 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1625 <dd>Convert a pointer typed constant to the corresponding integer constant
1626 TYPE must be an integer type. CST must be of pointer type. The CST value is
1627 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1628
1629 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1630 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1631 pointer type. CST must be of integer type. The CST value is zero extended,
1632 truncated, or unchanged to make it fit in a pointer size. This one is
1633 <i>really</i> dangerous!</dd>
1634
1635 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001636 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1637 identical (same number of bits). The conversion is done as if the CST value
1638 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5b950642006-11-11 23:08:07 +00001639 with this operator, just the type. This can be used for conversion of
Reid Spencer404a3252007-02-15 03:07:05 +00001640 vector types to any other type, as long as they have the same bit width. For
Reid Spencer5b950642006-11-11 23:08:07 +00001641 pointers it is only valid to cast to another pointer type.
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001642 </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001643
1644 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1645
1646 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1647 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1648 instruction, the index list may have zero or more indexes, which are required
1649 to make sense for the type of "CSTPTR".</dd>
1650
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001651 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1652
1653 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer9965ee72006-12-04 19:23:19 +00001654 constants.</dd>
1655
1656 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1657 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1658
1659 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1660 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001661
1662 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1663
1664 <dd>Perform the <a href="#i_extractelement">extractelement
1665 operation</a> on constants.
1666
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001667 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1668
1669 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer9965ee72006-12-04 19:23:19 +00001670 operation</a> on constants.</dd>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001671
Chris Lattner016a0e52006-04-08 00:13:41 +00001672
1673 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1674
1675 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer9965ee72006-12-04 19:23:19 +00001676 operation</a> on constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00001677
Chris Lattner74d3f822004-12-09 17:30:23 +00001678 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1679
Reid Spencer641f5c92004-12-09 18:13:12 +00001680 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1681 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001682 binary</a> operations. The constraints on operands are the same as those for
1683 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001684 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001685</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001686</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001687
Chris Lattner2f7c9632001-06-06 20:29:01 +00001688<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00001689<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1690<!-- *********************************************************************** -->
1691
1692<!-- ======================================================================= -->
1693<div class="doc_subsection">
1694<a name="inlineasm">Inline Assembler Expressions</a>
1695</div>
1696
1697<div class="doc_text">
1698
1699<p>
1700LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1701Module-Level Inline Assembly</a>) through the use of a special value. This
1702value represents the inline assembler as a string (containing the instructions
1703to emit), a list of operand constraints (stored as a string), and a flag that
1704indicates whether or not the inline asm expression has side effects. An example
1705inline assembler expression is:
1706</p>
1707
Bill Wendling3716c5d2007-05-29 09:04:49 +00001708<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00001709<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001710i32 (i32) asm "bswap $0", "=r,r"
Chris Lattner98f013c2006-01-25 23:47:57 +00001711</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001712</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00001713
1714<p>
1715Inline assembler expressions may <b>only</b> be used as the callee operand of
1716a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1717</p>
1718
Bill Wendling3716c5d2007-05-29 09:04:49 +00001719<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00001720<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001721%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattner98f013c2006-01-25 23:47:57 +00001722</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001723</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00001724
1725<p>
1726Inline asms with side effects not visible in the constraint list must be marked
1727as having side effects. This is done through the use of the
1728'<tt>sideeffect</tt>' keyword, like so:
1729</p>
1730
Bill Wendling3716c5d2007-05-29 09:04:49 +00001731<div class="doc_code">
Chris Lattner98f013c2006-01-25 23:47:57 +00001732<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001733call void asm sideeffect "eieio", ""()
Chris Lattner98f013c2006-01-25 23:47:57 +00001734</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00001735</div>
Chris Lattner98f013c2006-01-25 23:47:57 +00001736
1737<p>TODO: The format of the asm and constraints string still need to be
1738documented here. Constraints on what can be done (e.g. duplication, moving, etc
1739need to be documented).
1740</p>
1741
1742</div>
1743
1744<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001745<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1746<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001747
Misha Brukman76307852003-11-08 01:05:38 +00001748<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001749
Chris Lattner48b383b02003-11-25 01:02:51 +00001750<p>The LLVM instruction set consists of several different
1751classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001752instructions</a>, <a href="#binaryops">binary instructions</a>,
1753<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001754 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1755instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001756
Misha Brukman76307852003-11-08 01:05:38 +00001757</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001758
Chris Lattner2f7c9632001-06-06 20:29:01 +00001759<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001760<div class="doc_subsection"> <a name="terminators">Terminator
1761Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001762
Misha Brukman76307852003-11-08 01:05:38 +00001763<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001764
Chris Lattner48b383b02003-11-25 01:02:51 +00001765<p>As mentioned <a href="#functionstructure">previously</a>, every
1766basic block in a program ends with a "Terminator" instruction, which
1767indicates which block should be executed after the current block is
1768finished. These terminator instructions typically yield a '<tt>void</tt>'
1769value: they produce control flow, not values (the one exception being
1770the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001771<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001772 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1773instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001774the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1775 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1776 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001777
Misha Brukman76307852003-11-08 01:05:38 +00001778</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001779
Chris Lattner2f7c9632001-06-06 20:29:01 +00001780<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001781<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1782Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001783<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001784<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001785<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001786 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001787</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001788<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001789<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001790value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001791<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001792returns a value and then causes control flow, and one that just causes
1793control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001794<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001795<p>The '<tt>ret</tt>' instruction may return any '<a
1796 href="#t_firstclass">first class</a>' type. Notice that a function is
1797not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1798instruction inside of the function that returns a value that does not
1799match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001800<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001801<p>When the '<tt>ret</tt>' instruction is executed, control flow
1802returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001803 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001804the instruction after the call. If the caller was an "<a
1805 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001806at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001807returns a value, that value shall set the call or invoke instruction's
1808return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001809<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001810<pre> ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001811 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001812</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001813</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001814<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001815<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001816<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001817<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001818<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 +00001819</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001820<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001821<p>The '<tt>br</tt>' instruction is used to cause control flow to
1822transfer to a different basic block in the current function. There are
1823two forms of this instruction, corresponding to a conditional branch
1824and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001825<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001826<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencer36a15422007-01-12 03:35:51 +00001827single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Reid Spencer50c723a2007-02-19 23:54:10 +00001828unconditional form of the '<tt>br</tt>' instruction takes a single
1829'<tt>label</tt>' value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001830<h5>Semantics:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001831<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001832argument is evaluated. If the value is <tt>true</tt>, control flows
1833to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1834control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001835<h5>Example:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001836<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 +00001837 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 +00001838</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001839<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001840<div class="doc_subsubsection">
1841 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1842</div>
1843
Misha Brukman76307852003-11-08 01:05:38 +00001844<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001845<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001846
1847<pre>
1848 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1849</pre>
1850
Chris Lattner2f7c9632001-06-06 20:29:01 +00001851<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001852
1853<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1854several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001855instruction, allowing a branch to occur to one of many possible
1856destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001857
1858
Chris Lattner2f7c9632001-06-06 20:29:01 +00001859<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001860
1861<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1862comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1863an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1864table is not allowed to contain duplicate constant entries.</p>
1865
Chris Lattner2f7c9632001-06-06 20:29:01 +00001866<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001867
Chris Lattner48b383b02003-11-25 01:02:51 +00001868<p>The <tt>switch</tt> instruction specifies a table of values and
1869destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001870table is searched for the given value. If the value is found, control flow is
1871transfered to the corresponding destination; otherwise, control flow is
1872transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001873
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001874<h5>Implementation:</h5>
1875
1876<p>Depending on properties of the target machine and the particular
1877<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001878ways. For example, it could be generated as a series of chained conditional
1879branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001880
1881<h5>Example:</h5>
1882
1883<pre>
1884 <i>; Emulate a conditional br instruction</i>
Reid Spencer36a15422007-01-12 03:35:51 +00001885 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001886 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001887
1888 <i>; Emulate an unconditional br instruction</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001889 switch i32 0, label %dest [ ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001890
1891 <i>; Implement a jump table:</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001892 switch i32 %val, label %otherwise [ i32 0, label %onzero
1893 i32 1, label %onone
1894 i32 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001895</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001896</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001897
Chris Lattner2f7c9632001-06-06 20:29:01 +00001898<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001899<div class="doc_subsubsection">
1900 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1901</div>
1902
Misha Brukman76307852003-11-08 01:05:38 +00001903<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001904
Chris Lattner2f7c9632001-06-06 20:29:01 +00001905<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001906
1907<pre>
1908 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
Chris Lattner6b7a0082006-05-14 18:23:06 +00001909 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00001910</pre>
1911
Chris Lattnera8292f32002-05-06 22:08:29 +00001912<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001913
1914<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1915function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001916'<tt>normal</tt>' label or the
1917'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001918"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1919"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001920href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1921continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001922
Chris Lattner2f7c9632001-06-06 20:29:01 +00001923<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001924
Misha Brukman76307852003-11-08 01:05:38 +00001925<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001926
Chris Lattner2f7c9632001-06-06 20:29:01 +00001927<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001928 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00001929 The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001930 convention</a> the call should use. If none is specified, the call defaults
1931 to using C calling conventions.
1932 </li>
1933 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1934 function value being invoked. In most cases, this is a direct function
1935 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1936 an arbitrary pointer to function value.
1937 </li>
1938
1939 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1940 function to be invoked. </li>
1941
1942 <li>'<tt>function args</tt>': argument list whose types match the function
1943 signature argument types. If the function signature indicates the function
1944 accepts a variable number of arguments, the extra arguments can be
1945 specified. </li>
1946
1947 <li>'<tt>normal label</tt>': the label reached when the called function
1948 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1949
1950 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1951 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1952
Chris Lattner2f7c9632001-06-06 20:29:01 +00001953</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001954
Chris Lattner2f7c9632001-06-06 20:29:01 +00001955<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001956
Misha Brukman76307852003-11-08 01:05:38 +00001957<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001958href="#i_call">call</a></tt>' instruction in most regards. The primary
1959difference is that it establishes an association with a label, which is used by
1960the runtime library to unwind the stack.</p>
1961
1962<p>This instruction is used in languages with destructors to ensure that proper
1963cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1964exception. Additionally, this is important for implementation of
1965'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1966
Chris Lattner2f7c9632001-06-06 20:29:01 +00001967<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001968<pre>
Jeff Cohen5819f182007-04-22 01:17:39 +00001969 %retval = invoke i32 %Test(i32 15) to label %Continue
1970 unwind label %TestCleanup <i>; {i32}:retval set</i>
1971 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Test(i32 15) to label %Continue
1972 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001973</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001974</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001975
1976
Chris Lattner5ed60612003-09-03 00:41:47 +00001977<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001978
Chris Lattner48b383b02003-11-25 01:02:51 +00001979<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1980Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001981
Misha Brukman76307852003-11-08 01:05:38 +00001982<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001983
Chris Lattner5ed60612003-09-03 00:41:47 +00001984<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001985<pre>
1986 unwind
1987</pre>
1988
Chris Lattner5ed60612003-09-03 00:41:47 +00001989<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001990
1991<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1992at the first callee in the dynamic call stack which used an <a
1993href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1994primarily used to implement exception handling.</p>
1995
Chris Lattner5ed60612003-09-03 00:41:47 +00001996<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001997
1998<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1999immediately halt. The dynamic call stack is then searched for the first <a
2000href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
2001execution continues at the "exceptional" destination block specified by the
2002<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
2003dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002004</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00002005
2006<!-- _______________________________________________________________________ -->
2007
2008<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2009Instruction</a> </div>
2010
2011<div class="doc_text">
2012
2013<h5>Syntax:</h5>
2014<pre>
2015 unreachable
2016</pre>
2017
2018<h5>Overview:</h5>
2019
2020<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
2021instruction is used to inform the optimizer that a particular portion of the
2022code is not reachable. This can be used to indicate that the code after a
2023no-return function cannot be reached, and other facts.</p>
2024
2025<h5>Semantics:</h5>
2026
2027<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
2028</div>
2029
2030
2031
Chris Lattner2f7c9632001-06-06 20:29:01 +00002032<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002033<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002034<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00002035<p>Binary operators are used to do most of the computation in a
2036program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00002037produce a single value. The operands might represent
Reid Spencer404a3252007-02-15 03:07:05 +00002038multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002039The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00002040necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002041<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00002042</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002043<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002044<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
2045Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002046<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002047<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002048<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002049</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002050<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002051<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002052<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002053<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002054 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
Reid Spencer404a3252007-02-15 03:07:05 +00002055 This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002056Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002057<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002058<p>The value produced is the integer or floating point sum of the two
2059operands.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002060<p>If an integer sum has unsigned overflow, the result returned is the
2061mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2062the result.</p>
2063<p>Because LLVM integers use a two's complement representation, this
2064instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002065<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002066<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002067</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002068</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002069<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002070<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
2071Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002072<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002073<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002074<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002075</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002076<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002077<p>The '<tt>sub</tt>' instruction returns the difference of its two
2078operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002079<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
2080instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002081<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002082<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002083 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002084values.
Reid Spencer404a3252007-02-15 03:07:05 +00002085This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002086Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002087<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002088<p>The value produced is the integer or floating point difference of
2089the two operands.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002090<p>If an integer difference has unsigned overflow, the result returned is the
2091mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2092the result.</p>
2093<p>Because LLVM integers use a two's complement representation, this
2094instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002095<h5>Example:</h5>
Bill Wendling2d8b9a82007-05-29 09:42:13 +00002096<pre>
2097 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002098 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002099</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002100</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002101<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002102<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
2103Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002104<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002105<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002106<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002107</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002108<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002109<p>The '<tt>mul</tt>' instruction returns the product of its two
2110operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002111<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002112<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002113 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002114values.
Reid Spencer404a3252007-02-15 03:07:05 +00002115This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00002116Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002117<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002118<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00002119two operands.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002120<p>If the result of an integer multiplication has unsigned overflow,
2121the result returned is the mathematical result modulo
21222<sup>n</sup>, where n is the bit width of the result.</p>
2123<p>Because LLVM integers use a two's complement representation, and the
2124result is the same width as the operands, this instruction returns the
2125correct result for both signed and unsigned integers. If a full product
2126(e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands
2127should be sign-extended or zero-extended as appropriate to the
2128width of the full product.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002129<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002130<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002131</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002132</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002133<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002134<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2135</a></div>
2136<div class="doc_text">
2137<h5>Syntax:</h5>
2138<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2139</pre>
2140<h5>Overview:</h5>
2141<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
2142operands.</p>
2143<h5>Arguments:</h5>
2144<p>The two arguments to the '<tt>udiv</tt>' instruction must be
2145<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00002146types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002147of the values in which case the elements must be integers.</p>
2148<h5>Semantics:</h5>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002149<p>The value produced is the unsigned integer quotient of the two operands.</p>
2150<p>Note that unsigned integer division and signed integer division are distinct
2151operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2152<p>Division by zero leads to undefined behavior.</p>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002153<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002154<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002155</pre>
2156</div>
2157<!-- _______________________________________________________________________ -->
2158<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2159</a> </div>
2160<div class="doc_text">
2161<h5>Syntax:</h5>
2162<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2163</pre>
2164<h5>Overview:</h5>
2165<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
2166operands.</p>
2167<h5>Arguments:</h5>
2168<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
2169<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00002170types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002171of the values in which case the elements must be integers.</p>
2172<h5>Semantics:</h5>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002173<p>The value produced is the signed integer quotient of the two operands.</p>
2174<p>Note that signed integer division and unsigned integer division are distinct
2175operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2176<p>Division by zero leads to undefined behavior. Overflow also leads to
2177undefined behavior; this is a rare case, but can occur, for example,
2178by doing a 32-bit division of -2147483648 by -1.</p>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002179<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002180<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002181</pre>
2182</div>
2183<!-- _______________________________________________________________________ -->
2184<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002185Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002186<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002187<h5>Syntax:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002188<pre> &lt;result&gt; = fdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002189</pre>
2190<h5>Overview:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002191<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner48b383b02003-11-25 01:02:51 +00002192operands.</p>
2193<h5>Arguments:</h5>
Jeff Cohen5819f182007-04-22 01:17:39 +00002194<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002195<a href="#t_floating">floating point</a> values. Both arguments must have
Reid Spencer404a3252007-02-15 03:07:05 +00002196identical types. This instruction can also take <a href="#t_vector">vector</a>
Jeff Cohen5819f182007-04-22 01:17:39 +00002197versions of floating point values.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002198<h5>Semantics:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002199<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002200<h5>Example:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00002201<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002202</pre>
2203</div>
2204<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00002205<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2206</div>
2207<div class="doc_text">
2208<h5>Syntax:</h5>
2209<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2210</pre>
2211<h5>Overview:</h5>
2212<p>The '<tt>urem</tt>' instruction returns the remainder from the
2213unsigned division of its two arguments.</p>
2214<h5>Arguments:</h5>
2215<p>The two arguments to the '<tt>urem</tt>' instruction must be
2216<a href="#t_integer">integer</a> values. Both arguments must have identical
Dan Gohman08143e32007-11-05 23:35:22 +00002217types. This instruction can also take <a href="#t_vector">vector</a> versions
2218of the values in which case the elements must be integers.</p>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002219<h5>Semantics:</h5>
2220<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
2221This instruction always performs an unsigned division to get the remainder,
2222regardless of whether the arguments are unsigned or not.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002223<p>Note that unsigned integer remainder and signed integer remainder are
2224distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2225<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002226<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002227<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002228</pre>
2229
2230</div>
2231<!-- _______________________________________________________________________ -->
2232<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002233Instruction</a> </div>
2234<div class="doc_text">
2235<h5>Syntax:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002236<pre> &lt;result&gt; = srem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002237</pre>
2238<h5>Overview:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002239<p>The '<tt>srem</tt>' instruction returns the remainder from the
Dan Gohman08143e32007-11-05 23:35:22 +00002240signed division of its two operands. This instruction can also take
2241<a href="#t_vector">vector</a> versions of the values in which case
2242the elements must be integers.</p>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00002243
Chris Lattner48b383b02003-11-25 01:02:51 +00002244<h5>Arguments:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002245<p>The two arguments to the '<tt>srem</tt>' instruction must be
2246<a href="#t_integer">integer</a> values. Both arguments must have identical
2247types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002248<h5>Semantics:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002249<p>This instruction returns the <i>remainder</i> of a division (where the result
Reid Spencer806ad6a2007-03-24 22:23:39 +00002250has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i>
2251operator (where the result has the same sign as the divisor, <tt>var2</tt>) of
2252a value. For more information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002253 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
Reid Spencer806ad6a2007-03-24 22:23:39 +00002254Math Forum</a>. For a table of how this is implemented in various languages,
Reid Spencerdb3b93b2007-03-24 22:40:44 +00002255please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
Reid Spencer806ad6a2007-03-24 22:23:39 +00002256Wikipedia: modulo operation</a>.</p>
Chris Lattner2f2427e2008-01-28 00:36:27 +00002257<p>Note that signed integer remainder and unsigned integer remainder are
2258distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2259<p>Taking the remainder of a division by zero leads to undefined behavior.
2260Overflow also leads to undefined behavior; this is a rare case, but can occur,
2261for example, by taking the remainder of a 32-bit division of -2147483648 by -1.
2262(The remainder doesn't actually overflow, but this rule lets srem be
2263implemented using instructions that return both the result of the division
2264and the remainder.)</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002265<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002266<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002267</pre>
2268
2269</div>
2270<!-- _______________________________________________________________________ -->
2271<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
2272Instruction</a> </div>
2273<div class="doc_text">
2274<h5>Syntax:</h5>
2275<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2276</pre>
2277<h5>Overview:</h5>
2278<p>The '<tt>frem</tt>' instruction returns the remainder from the
2279division of its two operands.</p>
2280<h5>Arguments:</h5>
2281<p>The two arguments to the '<tt>frem</tt>' instruction must be
2282<a href="#t_floating">floating point</a> values. Both arguments must have
Dan Gohman08143e32007-11-05 23:35:22 +00002283identical types. This instruction can also take <a href="#t_vector">vector</a>
2284versions of floating point values.</p>
Reid Spencer7eb55b32006-11-02 01:53:59 +00002285<h5>Semantics:</h5>
2286<p>This instruction returns the <i>remainder</i> of a division.</p>
2287<h5>Example:</h5>
2288<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002289</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002290</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00002291
Reid Spencer2ab01932007-02-02 13:57:07 +00002292<!-- ======================================================================= -->
2293<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2294Operations</a> </div>
2295<div class="doc_text">
2296<p>Bitwise binary operators are used to do various forms of
2297bit-twiddling in a program. They are generally very efficient
2298instructions and can commonly be strength reduced from other
2299instructions. They require two operands, execute an operation on them,
2300and produce a single value. The resulting value of the bitwise binary
2301operators is always the same type as its first operand.</p>
2302</div>
2303
Reid Spencer04e259b2007-01-31 21:39:12 +00002304<!-- _______________________________________________________________________ -->
2305<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2306Instruction</a> </div>
2307<div class="doc_text">
2308<h5>Syntax:</h5>
2309<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2310</pre>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002311
Reid Spencer04e259b2007-01-31 21:39:12 +00002312<h5>Overview:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002313
Reid Spencer04e259b2007-01-31 21:39:12 +00002314<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2315the left a specified number of bits.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002316
Reid Spencer04e259b2007-01-31 21:39:12 +00002317<h5>Arguments:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002318
Reid Spencer04e259b2007-01-31 21:39:12 +00002319<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
2320 href="#t_integer">integer</a> type.</p>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002321
Reid Spencer04e259b2007-01-31 21:39:12 +00002322<h5>Semantics:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002323
2324<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>. If
2325<tt>var2</tt> is (statically or dynamically) equal to or larger than the number
2326of bits in <tt>var1</tt>, the result is undefined.</p>
2327
Reid Spencer04e259b2007-01-31 21:39:12 +00002328<h5>Example:</h5><pre>
2329 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2330 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2331 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002332 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00002333</pre>
2334</div>
2335<!-- _______________________________________________________________________ -->
2336<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2337Instruction</a> </div>
2338<div class="doc_text">
2339<h5>Syntax:</h5>
2340<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2341</pre>
2342
2343<h5>Overview:</h5>
2344<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00002345operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002346
2347<h5>Arguments:</h5>
2348<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
2349<a href="#t_integer">integer</a> type.</p>
2350
2351<h5>Semantics:</h5>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002352
Reid Spencer04e259b2007-01-31 21:39:12 +00002353<p>This instruction always performs a logical shift right operation. The most
2354significant bits of the result will be filled with zero bits after the
Chris Lattnerf0e50112007-10-03 21:01:14 +00002355shift. If <tt>var2</tt> is (statically or dynamically) equal to or larger than
2356the number of bits in <tt>var1</tt>, the result is undefined.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002357
2358<h5>Example:</h5>
2359<pre>
2360 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
2361 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
2362 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
2363 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002364 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00002365</pre>
2366</div>
2367
Reid Spencer2ab01932007-02-02 13:57:07 +00002368<!-- _______________________________________________________________________ -->
Reid Spencer04e259b2007-01-31 21:39:12 +00002369<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2370Instruction</a> </div>
2371<div class="doc_text">
2372
2373<h5>Syntax:</h5>
2374<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2375</pre>
2376
2377<h5>Overview:</h5>
2378<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
Jeff Cohen5819f182007-04-22 01:17:39 +00002379operand shifted to the right a specified number of bits with sign extension.</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002380
2381<h5>Arguments:</h5>
2382<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
2383<a href="#t_integer">integer</a> type.</p>
2384
2385<h5>Semantics:</h5>
2386<p>This instruction always performs an arithmetic shift right operation,
2387The most significant bits of the result will be filled with the sign bit
Chris Lattnerf0e50112007-10-03 21:01:14 +00002388of <tt>var1</tt>. If <tt>var2</tt> is (statically or dynamically) equal to or
2389larger than the number of bits in <tt>var1</tt>, the result is undefined.
2390</p>
Reid Spencer04e259b2007-01-31 21:39:12 +00002391
2392<h5>Example:</h5>
2393<pre>
2394 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
2395 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
2396 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
2397 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattnerf0e50112007-10-03 21:01:14 +00002398 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Reid Spencer04e259b2007-01-31 21:39:12 +00002399</pre>
2400</div>
2401
Chris Lattner2f7c9632001-06-06 20:29:01 +00002402<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002403<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
2404Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002405<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002406<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002407<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002408</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002409<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002410<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
2411its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002412<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002413<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002414 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002415identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002416<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002417<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002418<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002419<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00002420<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00002421 <tbody>
2422 <tr>
2423 <td>In0</td>
2424 <td>In1</td>
2425 <td>Out</td>
2426 </tr>
2427 <tr>
2428 <td>0</td>
2429 <td>0</td>
2430 <td>0</td>
2431 </tr>
2432 <tr>
2433 <td>0</td>
2434 <td>1</td>
2435 <td>0</td>
2436 </tr>
2437 <tr>
2438 <td>1</td>
2439 <td>0</td>
2440 <td>0</td>
2441 </tr>
2442 <tr>
2443 <td>1</td>
2444 <td>1</td>
2445 <td>1</td>
2446 </tr>
2447 </tbody>
2448</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002449</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002450<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002451<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
2452 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
2453 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002454</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002455</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002456<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002457<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002458<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002459<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002460<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002461</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00002462<h5>Overview:</h5>
2463<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2464or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002465<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002466<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002467 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002468identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002469<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002470<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002471<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002472<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002473<table border="1" cellspacing="0" cellpadding="4">
2474 <tbody>
2475 <tr>
2476 <td>In0</td>
2477 <td>In1</td>
2478 <td>Out</td>
2479 </tr>
2480 <tr>
2481 <td>0</td>
2482 <td>0</td>
2483 <td>0</td>
2484 </tr>
2485 <tr>
2486 <td>0</td>
2487 <td>1</td>
2488 <td>1</td>
2489 </tr>
2490 <tr>
2491 <td>1</td>
2492 <td>0</td>
2493 <td>1</td>
2494 </tr>
2495 <tr>
2496 <td>1</td>
2497 <td>1</td>
2498 <td>1</td>
2499 </tr>
2500 </tbody>
2501</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002502</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002503<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002504<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2505 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2506 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002507</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002508</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002509<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002510<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2511Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002512<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002513<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002514<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002515</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002516<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002517<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2518or of its two operands. The <tt>xor</tt> is used to implement the
2519"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002520<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002521<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002522 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002523identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002524<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002525<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002526<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002527<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002528<table border="1" cellspacing="0" cellpadding="4">
2529 <tbody>
2530 <tr>
2531 <td>In0</td>
2532 <td>In1</td>
2533 <td>Out</td>
2534 </tr>
2535 <tr>
2536 <td>0</td>
2537 <td>0</td>
2538 <td>0</td>
2539 </tr>
2540 <tr>
2541 <td>0</td>
2542 <td>1</td>
2543 <td>1</td>
2544 </tr>
2545 <tr>
2546 <td>1</td>
2547 <td>0</td>
2548 <td>1</td>
2549 </tr>
2550 <tr>
2551 <td>1</td>
2552 <td>1</td>
2553 <td>0</td>
2554 </tr>
2555 </tbody>
2556</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002557</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00002558<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002559<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002560<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2561 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2562 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2563 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002564</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002565</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002566
Chris Lattner2f7c9632001-06-06 20:29:01 +00002567<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00002568<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00002569 <a name="vectorops">Vector Operations</a>
2570</div>
2571
2572<div class="doc_text">
2573
2574<p>LLVM supports several instructions to represent vector operations in a
Jeff Cohen5819f182007-04-22 01:17:39 +00002575target-independent manner. These instructions cover the element-access and
Chris Lattnerce83bff2006-04-08 23:07:04 +00002576vector-specific operations needed to process vectors effectively. While LLVM
2577does directly support these vector operations, many sophisticated algorithms
2578will want to use target-specific intrinsics to take full advantage of a specific
2579target.</p>
2580
2581</div>
2582
2583<!-- _______________________________________________________________________ -->
2584<div class="doc_subsubsection">
2585 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2586</div>
2587
2588<div class="doc_text">
2589
2590<h5>Syntax:</h5>
2591
2592<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002593 &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 +00002594</pre>
2595
2596<h5>Overview:</h5>
2597
2598<p>
2599The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002600element from a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002601</p>
2602
2603
2604<h5>Arguments:</h5>
2605
2606<p>
2607The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002608value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattnerce83bff2006-04-08 23:07:04 +00002609an index indicating the position from which to extract the element.
2610The index may be a variable.</p>
2611
2612<h5>Semantics:</h5>
2613
2614<p>
2615The result is a scalar of the same type as the element type of
2616<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2617<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2618results are undefined.
2619</p>
2620
2621<h5>Example:</h5>
2622
2623<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002624 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002625</pre>
2626</div>
2627
2628
2629<!-- _______________________________________________________________________ -->
2630<div class="doc_subsubsection">
2631 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2632</div>
2633
2634<div class="doc_text">
2635
2636<h5>Syntax:</h5>
2637
2638<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002639 &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 +00002640</pre>
2641
2642<h5>Overview:</h5>
2643
2644<p>
2645The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002646element into a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002647</p>
2648
2649
2650<h5>Arguments:</h5>
2651
2652<p>
2653The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002654value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattnerce83bff2006-04-08 23:07:04 +00002655scalar value whose type must equal the element type of the first
2656operand. The third operand is an index indicating the position at
2657which to insert the value. The index may be a variable.</p>
2658
2659<h5>Semantics:</h5>
2660
2661<p>
Reid Spencer404a3252007-02-15 03:07:05 +00002662The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattnerce83bff2006-04-08 23:07:04 +00002663element values are those of <tt>val</tt> except at position
2664<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2665exceeds the length of <tt>val</tt>, the results are undefined.
2666</p>
2667
2668<h5>Example:</h5>
2669
2670<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002671 %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 +00002672</pre>
2673</div>
2674
2675<!-- _______________________________________________________________________ -->
2676<div class="doc_subsubsection">
2677 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2678</div>
2679
2680<div class="doc_text">
2681
2682<h5>Syntax:</h5>
2683
2684<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002685 &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;n x i32&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002686</pre>
2687
2688<h5>Overview:</h5>
2689
2690<p>
2691The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2692from two input vectors, returning a vector of the same type.
2693</p>
2694
2695<h5>Arguments:</h5>
2696
2697<p>
2698The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2699with types that match each other and types that match the result of the
2700instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002701of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002702</p>
2703
2704<p>
2705The shuffle mask operand is required to be a constant vector with either
2706constant integer or undef values.
2707</p>
2708
2709<h5>Semantics:</h5>
2710
2711<p>
2712The elements of the two input vectors are numbered from left to right across
2713both of the vectors. The shuffle mask operand specifies, for each element of
2714the result vector, which element of the two input registers the result element
2715gets. The element selector may be undef (meaning "don't care") and the second
2716operand may be undef if performing a shuffle from only one vector.
2717</p>
2718
2719<h5>Example:</h5>
2720
2721<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002722 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen5819f182007-04-22 01:17:39 +00002723 &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 +00002724 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2725 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002726</pre>
2727</div>
2728
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00002729
Chris Lattnerce83bff2006-04-08 23:07:04 +00002730<!-- ======================================================================= -->
2731<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00002732 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00002733</div>
2734
Misha Brukman76307852003-11-08 01:05:38 +00002735<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002736
Chris Lattner48b383b02003-11-25 01:02:51 +00002737<p>A key design point of an SSA-based representation is how it
2738represents memory. In LLVM, no memory locations are in SSA form, which
2739makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00002740allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002741
Misha Brukman76307852003-11-08 01:05:38 +00002742</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002743
Chris Lattner2f7c9632001-06-06 20:29:01 +00002744<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002745<div class="doc_subsubsection">
2746 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2747</div>
2748
Misha Brukman76307852003-11-08 01:05:38 +00002749<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002750
Chris Lattner2f7c9632001-06-06 20:29:01 +00002751<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002752
2753<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002754 &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 +00002755</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002756
Chris Lattner2f7c9632001-06-06 20:29:01 +00002757<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002758
Chris Lattner48b383b02003-11-25 01:02:51 +00002759<p>The '<tt>malloc</tt>' instruction allocates memory from the system
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00002760heap and returns a pointer to it. The object is always allocated in the generic
2761address space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002762
Chris Lattner2f7c9632001-06-06 20:29:01 +00002763<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002764
2765<p>The '<tt>malloc</tt>' instruction allocates
2766<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00002767bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002768appropriate type to the program. If "NumElements" is specified, it is the
Gabor Greifdd1fc982008-02-09 22:24:34 +00002769number of elements allocated, otherwise "NumElements" is defaulted to be one.
2770If an alignment is specified, the value result of the allocation is guaranteed to
2771be aligned to at least that boundary. If not specified, or if zero, the target can
2772choose to align the allocation on any convenient boundary.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002773
Misha Brukman76307852003-11-08 01:05:38 +00002774<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002775
Chris Lattner2f7c9632001-06-06 20:29:01 +00002776<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002777
Chris Lattner48b383b02003-11-25 01:02:51 +00002778<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2779a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002780
Chris Lattner54611b42005-11-06 08:02:57 +00002781<h5>Example:</h5>
2782
2783<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002784 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002785
Bill Wendling2d8b9a82007-05-29 09:42:13 +00002786 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2787 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2788 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2789 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2790 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002791</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002792</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002793
Chris Lattner2f7c9632001-06-06 20:29:01 +00002794<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002795<div class="doc_subsubsection">
2796 <a name="i_free">'<tt>free</tt>' Instruction</a>
2797</div>
2798
Misha Brukman76307852003-11-08 01:05:38 +00002799<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002800
Chris Lattner2f7c9632001-06-06 20:29:01 +00002801<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002802
2803<pre>
2804 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002805</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002806
Chris Lattner2f7c9632001-06-06 20:29:01 +00002807<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002808
Chris Lattner48b383b02003-11-25 01:02:51 +00002809<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00002810memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002811
Chris Lattner2f7c9632001-06-06 20:29:01 +00002812<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002813
Chris Lattner48b383b02003-11-25 01:02:51 +00002814<p>'<tt>value</tt>' shall be a pointer value that points to a value
2815that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2816instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002817
Chris Lattner2f7c9632001-06-06 20:29:01 +00002818<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002819
John Criswelldfe6a862004-12-10 15:51:16 +00002820<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00002821after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002822
Chris Lattner2f7c9632001-06-06 20:29:01 +00002823<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002824
2825<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002826 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2827 free [4 x i8]* %array
Chris Lattner2f7c9632001-06-06 20:29:01 +00002828</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002829</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002830
Chris Lattner2f7c9632001-06-06 20:29:01 +00002831<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002832<div class="doc_subsubsection">
2833 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2834</div>
2835
Misha Brukman76307852003-11-08 01:05:38 +00002836<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002837
Chris Lattner2f7c9632001-06-06 20:29:01 +00002838<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002839
2840<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002841 &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 +00002842</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002843
Chris Lattner2f7c9632001-06-06 20:29:01 +00002844<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002845
Jeff Cohen5819f182007-04-22 01:17:39 +00002846<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
2847currently executing function, to be automatically released when this function
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00002848returns to its caller. The object is always allocated in the generic address
2849space (address space zero).</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002850
Chris Lattner2f7c9632001-06-06 20:29:01 +00002851<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002852
John Criswelldfe6a862004-12-10 15:51:16 +00002853<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002854bytes of memory on the runtime stack, returning a pointer of the
Gabor Greifdd1fc982008-02-09 22:24:34 +00002855appropriate type to the program. If "NumElements" is specified, it is the
2856number of elements allocated, otherwise "NumElements" is defaulted to be one.
2857If an alignment is specified, the value result of the allocation is guaranteed
2858to be aligned to at least that boundary. If not specified, or if zero, the target
2859can choose to align the allocation on any convenient boundary.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002860
Misha Brukman76307852003-11-08 01:05:38 +00002861<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002862
Chris Lattner2f7c9632001-06-06 20:29:01 +00002863<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002864
John Criswell4a3327e2005-05-13 22:25:59 +00002865<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00002866memory is automatically released when the function returns. The '<tt>alloca</tt>'
2867instruction is commonly used to represent automatic variables that must
2868have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00002869 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00002870instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002871
Chris Lattner2f7c9632001-06-06 20:29:01 +00002872<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002873
2874<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002875 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002876 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2877 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002878 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002879</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002880</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002881
Chris Lattner2f7c9632001-06-06 20:29:01 +00002882<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002883<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2884Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002885<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002886<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00002887<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 +00002888<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002889<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002890<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002891<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00002892address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00002893 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00002894marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00002895the number or order of execution of this <tt>load</tt> with other
2896volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2897instructions. </p>
Chris Lattner2a1993f2008-01-06 21:04:43 +00002898<p>
2899The optional "align" argument specifies the alignment of the operation
2900(that is, the alignment of the memory address). A value of 0 or an
2901omitted "align" argument means that the operation has the preferential
2902alignment for the target. It is the responsibility of the code emitter
2903to ensure that the alignment information is correct. Overestimating
2904the alignment results in an undefined behavior. Underestimating the
2905alignment may produce less efficient code. An alignment of 1 is always
2906safe.
2907</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002908<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002909<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002910<h5>Examples:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002911<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002912 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002913 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2914 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002915</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002916</div>
Chris Lattner095735d2002-05-06 03:03:22 +00002917<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002918<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2919Instruction</a> </div>
Reid Spencera89fb182006-11-09 21:18:01 +00002920<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002921<h5>Syntax:</h5>
Christopher Lambbff50202007-04-21 08:16:25 +00002922<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
2923 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 +00002924</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002925<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002926<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002927<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002928<p>There are two arguments to the '<tt>store</tt>' instruction: a value
Jeff Cohen5819f182007-04-22 01:17:39 +00002929to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002930operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00002931operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00002932optimizer is not allowed to modify the number or order of execution of
2933this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2934 href="#i_store">store</a></tt> instructions.</p>
Chris Lattner2a1993f2008-01-06 21:04:43 +00002935<p>
2936The optional "align" argument specifies the alignment of the operation
2937(that is, the alignment of the memory address). A value of 0 or an
2938omitted "align" argument means that the operation has the preferential
2939alignment for the target. It is the responsibility of the code emitter
2940to ensure that the alignment information is correct. Overestimating
2941the alignment results in an undefined behavior. Underestimating the
2942alignment may produce less efficient code. An alignment of 1 is always
2943safe.
2944</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002945<h5>Semantics:</h5>
2946<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2947at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002948<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002949<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling8830ffe2007-10-22 05:10:05 +00002950 store i32 3, i32* %ptr <i>; yields {void}</i>
2951 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002952</pre>
Reid Spencer443460a2006-11-09 21:15:49 +00002953</div>
2954
Chris Lattner095735d2002-05-06 03:03:22 +00002955<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00002956<div class="doc_subsubsection">
2957 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2958</div>
2959
Misha Brukman76307852003-11-08 01:05:38 +00002960<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00002961<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002962<pre>
2963 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2964</pre>
2965
Chris Lattner590645f2002-04-14 06:13:44 +00002966<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002967
2968<p>
2969The '<tt>getelementptr</tt>' instruction is used to get the address of a
2970subelement of an aggregate data structure.</p>
2971
Chris Lattner590645f2002-04-14 06:13:44 +00002972<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002973
Reid Spencercee005c2006-12-04 21:29:24 +00002974<p>This instruction takes a list of integer operands that indicate what
Chris Lattner33fd7022004-04-05 01:30:49 +00002975elements of the aggregate object to index to. The actual types of the arguments
2976provided depend on the type of the first pointer argument. The
2977'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002978levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002979structure, only <tt>i32</tt> integer constants are allowed. When indexing
Reid Spencercee005c2006-12-04 21:29:24 +00002980into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2981be sign extended to 64-bit values.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002982
Chris Lattner48b383b02003-11-25 01:02:51 +00002983<p>For example, let's consider a C code fragment and how it gets
2984compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002985
Bill Wendling3716c5d2007-05-29 09:04:49 +00002986<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00002987<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00002988struct RT {
2989 char A;
Chris Lattnera446f1b2007-05-29 15:43:56 +00002990 int B[10][20];
Bill Wendling3716c5d2007-05-29 09:04:49 +00002991 char C;
2992};
2993struct ST {
Chris Lattnera446f1b2007-05-29 15:43:56 +00002994 int X;
Bill Wendling3716c5d2007-05-29 09:04:49 +00002995 double Y;
2996 struct RT Z;
2997};
Chris Lattner33fd7022004-04-05 01:30:49 +00002998
Chris Lattnera446f1b2007-05-29 15:43:56 +00002999int *foo(struct ST *s) {
Bill Wendling3716c5d2007-05-29 09:04:49 +00003000 return &amp;s[1].Z.B[5][13];
3001}
Chris Lattner33fd7022004-04-05 01:30:49 +00003002</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003003</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003004
Misha Brukman76307852003-11-08 01:05:38 +00003005<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003006
Bill Wendling3716c5d2007-05-29 09:04:49 +00003007<div class="doc_code">
Chris Lattner33fd7022004-04-05 01:30:49 +00003008<pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003009%RT = type { i8 , [10 x [20 x i32]], i8 }
3010%ST = type { i32, double, %RT }
Chris Lattner33fd7022004-04-05 01:30:49 +00003011
Bill Wendling3716c5d2007-05-29 09:04:49 +00003012define i32* %foo(%ST* %s) {
3013entry:
3014 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3015 ret i32* %reg
3016}
Chris Lattner33fd7022004-04-05 01:30:49 +00003017</pre>
Bill Wendling3716c5d2007-05-29 09:04:49 +00003018</div>
Chris Lattner33fd7022004-04-05 01:30:49 +00003019
Chris Lattner590645f2002-04-14 06:13:44 +00003020<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00003021
3022<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00003023on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencercee005c2006-12-04 21:29:24 +00003024and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencerc0312692006-12-03 16:53:48 +00003025<a href="#t_integer">integer</a> type but the value will always be sign extended
Jeff Cohen5819f182007-04-22 01:17:39 +00003026to 64-bits. <a href="#t_struct">Structure</a> types require <tt>i32</tt>
Reid Spencerc0312692006-12-03 16:53:48 +00003027<b>constants</b>.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003028
Misha Brukman76307852003-11-08 01:05:38 +00003029<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003030type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattner33fd7022004-04-05 01:30:49 +00003031}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003032the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3033i8 }</tt>' type, another structure. The third index indexes into the second
3034element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattner33fd7022004-04-05 01:30:49 +00003035array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003036'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
3037to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003038
Chris Lattner48b383b02003-11-25 01:02:51 +00003039<p>Note that it is perfectly legal to index partially through a
3040structure, returning a pointer to an inner element. Because of this,
3041the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00003042
3043<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003044 define i32* %foo(%ST* %s) {
3045 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen5819f182007-04-22 01:17:39 +00003046 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3047 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003048 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3049 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3050 ret i32* %t5
Chris Lattner33fd7022004-04-05 01:30:49 +00003051 }
Chris Lattnera8292f32002-05-06 22:08:29 +00003052</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003053
3054<p>Note that it is undefined to access an array out of bounds: array and
3055pointer indexes must always be within the defined bounds of the array type.
3056The one exception for this rules is zero length arrays. These arrays are
3057defined to be accessible as variable length arrays, which requires access
3058beyond the zero'th element.</p>
3059
Chris Lattner6ab66722006-08-15 00:45:58 +00003060<p>The getelementptr instruction is often confusing. For some more insight
3061into how it works, see <a href="GetElementPtr.html">the getelementptr
3062FAQ</a>.</p>
3063
Chris Lattner590645f2002-04-14 06:13:44 +00003064<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00003065
Chris Lattner33fd7022004-04-05 01:30:49 +00003066<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003067 <i>; yields [12 x i8]*:aptr</i>
3068 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattner33fd7022004-04-05 01:30:49 +00003069</pre>
Chris Lattner33fd7022004-04-05 01:30:49 +00003070</div>
Reid Spencer443460a2006-11-09 21:15:49 +00003071
Chris Lattner2f7c9632001-06-06 20:29:01 +00003072<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00003073<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00003074</div>
Misha Brukman76307852003-11-08 01:05:38 +00003075<div class="doc_text">
Reid Spencer97c5fa42006-11-08 01:18:52 +00003076<p>The instructions in this category are the conversion instructions (casting)
3077which all take a single operand and a type. They perform various bit conversions
3078on the operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00003079</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003080
Chris Lattnera8292f32002-05-06 22:08:29 +00003081<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003082<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003083 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3084</div>
3085<div class="doc_text">
3086
3087<h5>Syntax:</h5>
3088<pre>
3089 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3090</pre>
3091
3092<h5>Overview:</h5>
3093<p>
3094The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
3095</p>
3096
3097<h5>Arguments:</h5>
3098<p>
3099The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3100be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003101and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencer51b07252006-11-09 23:03:26 +00003102type. The bit size of <tt>value</tt> must be larger than the bit size of
3103<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003104
3105<h5>Semantics:</h5>
3106<p>
3107The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencer51b07252006-11-09 23:03:26 +00003108and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
3109larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
3110It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003111
3112<h5>Example:</h5>
3113<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003114 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003115 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3116 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003117</pre>
3118</div>
3119
3120<!-- _______________________________________________________________________ -->
3121<div class="doc_subsubsection">
3122 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3123</div>
3124<div class="doc_text">
3125
3126<h5>Syntax:</h5>
3127<pre>
3128 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3129</pre>
3130
3131<h5>Overview:</h5>
3132<p>The '<tt>zext</tt>' instruction zero extends its operand to type
3133<tt>ty2</tt>.</p>
3134
3135
3136<h5>Arguments:</h5>
3137<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003138<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3139also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00003140<tt>value</tt> must be smaller than the bit size of the destination type,
3141<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003142
3143<h5>Semantics:</h5>
3144<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Chris Lattnerc87f3df2007-05-24 19:13:27 +00003145bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003146
Reid Spencer07c9c682007-01-12 15:46:11 +00003147<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003148
3149<h5>Example:</h5>
3150<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003151 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003152 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003153</pre>
3154</div>
3155
3156<!-- _______________________________________________________________________ -->
3157<div class="doc_subsubsection">
3158 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
3159</div>
3160<div class="doc_text">
3161
3162<h5>Syntax:</h5>
3163<pre>
3164 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3165</pre>
3166
3167<h5>Overview:</h5>
3168<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
3169
3170<h5>Arguments:</h5>
3171<p>
3172The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003173<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3174also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00003175<tt>value</tt> must be smaller than the bit size of the destination type,
3176<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003177
3178<h5>Semantics:</h5>
3179<p>
3180The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
3181bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
Chris Lattnerc87f3df2007-05-24 19:13:27 +00003182the type <tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003183
Reid Spencer36a15422007-01-12 03:35:51 +00003184<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003185
3186<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003187<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003188 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencer36a15422007-01-12 03:35:51 +00003189 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003190</pre>
3191</div>
3192
3193<!-- _______________________________________________________________________ -->
3194<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00003195 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
3196</div>
3197
3198<div class="doc_text">
3199
3200<h5>Syntax:</h5>
3201
3202<pre>
3203 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3204</pre>
3205
3206<h5>Overview:</h5>
3207<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
3208<tt>ty2</tt>.</p>
3209
3210
3211<h5>Arguments:</h5>
3212<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
3213 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
3214cast it to. The size of <tt>value</tt> must be larger than the size of
3215<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
3216<i>no-op cast</i>.</p>
3217
3218<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003219<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
3220<a href="#t_floating">floating point</a> type to a smaller
3221<a href="#t_floating">floating point</a> type. If the value cannot fit within
3222the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00003223
3224<h5>Example:</h5>
3225<pre>
3226 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
3227 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
3228</pre>
3229</div>
3230
3231<!-- _______________________________________________________________________ -->
3232<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003233 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
3234</div>
3235<div class="doc_text">
3236
3237<h5>Syntax:</h5>
3238<pre>
3239 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3240</pre>
3241
3242<h5>Overview:</h5>
3243<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
3244floating point value.</p>
3245
3246<h5>Arguments:</h5>
3247<p>The '<tt>fpext</tt>' instruction takes a
3248<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencer51b07252006-11-09 23:03:26 +00003249and a <a href="#t_floating">floating point</a> type to cast it to. The source
3250type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003251
3252<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003253<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Duncan Sands16f122e2007-03-30 12:22:09 +00003254<a href="#t_floating">floating point</a> type to a larger
3255<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
Reid Spencer51b07252006-11-09 23:03:26 +00003256used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5b950642006-11-11 23:08:07 +00003257<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003258
3259<h5>Example:</h5>
3260<pre>
3261 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
3262 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
3263</pre>
3264</div>
3265
3266<!-- _______________________________________________________________________ -->
3267<div class="doc_subsubsection">
Reid Spencer2eadb532007-01-21 00:29:26 +00003268 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003269</div>
3270<div class="doc_text">
3271
3272<h5>Syntax:</h5>
3273<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00003274 &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 +00003275</pre>
3276
3277<h5>Overview:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00003278<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003279unsigned integer equivalent of type <tt>ty2</tt>.
3280</p>
3281
3282<h5>Arguments:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00003283<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
Nate Begemand4d45c22007-11-17 03:58:34 +00003284scalar or vector <a href="#t_floating">floating point</a> value, and a type
3285to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
3286type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
3287vector integer type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003288
3289<h5>Semantics:</h5>
Reid Spencer753163d2007-07-31 14:40:14 +00003290<p> The '<tt>fptoui</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003291<a href="#t_floating">floating point</a> operand into the nearest (rounding
3292towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
3293the results are undefined.</p>
3294
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003295<h5>Example:</h5>
3296<pre>
Reid Spencer753163d2007-07-31 14:40:14 +00003297 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00003298 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencer753163d2007-07-31 14:40:14 +00003299 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003300</pre>
3301</div>
3302
3303<!-- _______________________________________________________________________ -->
3304<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003305 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003306</div>
3307<div class="doc_text">
3308
3309<h5>Syntax:</h5>
3310<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003311 &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 +00003312</pre>
3313
3314<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003315<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003316<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003317</p>
3318
Chris Lattnera8292f32002-05-06 22:08:29 +00003319<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003320<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Nate Begemand4d45c22007-11-17 03:58:34 +00003321scalar or vector <a href="#t_floating">floating point</a> value, and a type
3322to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
3323type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
3324vector integer type with the same number of elements as <tt>ty</tt></p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003325
Chris Lattnera8292f32002-05-06 22:08:29 +00003326<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003327<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003328<a href="#t_floating">floating point</a> operand into the nearest (rounding
3329towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
3330the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003331
Chris Lattner70de6632001-07-09 00:26:23 +00003332<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003333<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003334 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner5b95a172007-09-22 03:17:52 +00003335 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003336 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003337</pre>
3338</div>
3339
3340<!-- _______________________________________________________________________ -->
3341<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003342 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003343</div>
3344<div class="doc_text">
3345
3346<h5>Syntax:</h5>
3347<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003348 &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 +00003349</pre>
3350
3351<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003352<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003353integer and converts that value to the <tt>ty2</tt> type.</p>
3354
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003355<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00003356<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
3357scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
3358to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
3359type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
3360floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003361
3362<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003363<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003364integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00003365the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003366
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003367<h5>Example:</h5>
3368<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003369 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003370 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003371</pre>
3372</div>
3373
3374<!-- _______________________________________________________________________ -->
3375<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003376 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003377</div>
3378<div class="doc_text">
3379
3380<h5>Syntax:</h5>
3381<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003382 &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 +00003383</pre>
3384
3385<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003386<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003387integer and converts that value to the <tt>ty2</tt> type.</p>
3388
3389<h5>Arguments:</h5>
Nate Begemand4d45c22007-11-17 03:58:34 +00003390<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
3391scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
3392to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
3393type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
3394floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003395
3396<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003397<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003398integer quantity and converts it to the corresponding floating point value. If
Jeff Cohenbeccb742007-04-22 14:56:37 +00003399the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003400
3401<h5>Example:</h5>
3402<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003403 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003404 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003405</pre>
3406</div>
3407
3408<!-- _______________________________________________________________________ -->
3409<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00003410 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3411</div>
3412<div class="doc_text">
3413
3414<h5>Syntax:</h5>
3415<pre>
3416 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3417</pre>
3418
3419<h5>Overview:</h5>
3420<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3421the integer type <tt>ty2</tt>.</p>
3422
3423<h5>Arguments:</h5>
3424<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
Duncan Sands16f122e2007-03-30 12:22:09 +00003425must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Reid Spencerb7344ff2006-11-11 21:00:47 +00003426<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3427
3428<h5>Semantics:</h5>
3429<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3430<tt>ty2</tt> by interpreting the pointer value as an integer and either
3431truncating or zero extending that value to the size of the integer type. If
3432<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3433<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
Jeff Cohen222a8a42007-04-29 01:07:00 +00003434are the same size, then nothing is done (<i>no-op cast</i>) other than a type
3435change.</p>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003436
3437<h5>Example:</h5>
3438<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003439 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
3440 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003441</pre>
3442</div>
3443
3444<!-- _______________________________________________________________________ -->
3445<div class="doc_subsubsection">
3446 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3447</div>
3448<div class="doc_text">
3449
3450<h5>Syntax:</h5>
3451<pre>
3452 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3453</pre>
3454
3455<h5>Overview:</h5>
3456<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3457a pointer type, <tt>ty2</tt>.</p>
3458
3459<h5>Arguments:</h5>
Duncan Sands16f122e2007-03-30 12:22:09 +00003460<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003461value to cast, and a type to cast it to, which must be a
Anton Korobeynikova0554d92007-01-12 19:20:47 +00003462<a href="#t_pointer">pointer</a> type.
Reid Spencerb7344ff2006-11-11 21:00:47 +00003463
3464<h5>Semantics:</h5>
3465<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3466<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3467the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3468size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3469the size of a pointer then a zero extension is done. If they are the same size,
3470nothing is done (<i>no-op cast</i>).</p>
3471
3472<h5>Example:</h5>
3473<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003474 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
3475 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
3476 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003477</pre>
3478</div>
3479
3480<!-- _______________________________________________________________________ -->
3481<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00003482 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003483</div>
3484<div class="doc_text">
3485
3486<h5>Syntax:</h5>
3487<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00003488 &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 +00003489</pre>
3490
3491<h5>Overview:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003492<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003493<tt>ty2</tt> without changing any bits.</p>
3494
3495<h5>Arguments:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003496<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003497a first class value, and a type to cast it to, which must also be a <a
3498 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencere3db84c2007-01-09 20:08:58 +00003499and the destination type, <tt>ty2</tt>, must be identical. If the source
3500type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003501
3502<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003503<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencerb7344ff2006-11-11 21:00:47 +00003504<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3505this conversion. The conversion is done as if the <tt>value</tt> had been
3506stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3507converted to other pointer types with this instruction. To convert pointers to
3508other types, use the <a href="#i_inttoptr">inttoptr</a> or
3509<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003510
3511<h5>Example:</h5>
3512<pre>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003513 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003514 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3515 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00003516</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003517</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003518
Reid Spencer97c5fa42006-11-08 01:18:52 +00003519<!-- ======================================================================= -->
3520<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3521<div class="doc_text">
3522<p>The instructions in this category are the "miscellaneous"
3523instructions, which defy better classification.</p>
3524</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003525
3526<!-- _______________________________________________________________________ -->
3527<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3528</div>
3529<div class="doc_text">
3530<h5>Syntax:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003531<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003532</pre>
3533<h5>Overview:</h5>
3534<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3535of its two integer operands.</p>
3536<h5>Arguments:</h5>
3537<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Jeff Cohen222a8a42007-04-29 01:07:00 +00003538the condition code indicating the kind of comparison to perform. It is not
3539a value, just a keyword. The possible condition code are:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003540<ol>
3541 <li><tt>eq</tt>: equal</li>
3542 <li><tt>ne</tt>: not equal </li>
3543 <li><tt>ugt</tt>: unsigned greater than</li>
3544 <li><tt>uge</tt>: unsigned greater or equal</li>
3545 <li><tt>ult</tt>: unsigned less than</li>
3546 <li><tt>ule</tt>: unsigned less or equal</li>
3547 <li><tt>sgt</tt>: signed greater than</li>
3548 <li><tt>sge</tt>: signed greater or equal</li>
3549 <li><tt>slt</tt>: signed less than</li>
3550 <li><tt>sle</tt>: signed less or equal</li>
3551</ol>
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003552<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Reid Spencer784ef792007-01-04 05:19:58 +00003553<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003554<h5>Semantics:</h5>
3555<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3556the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003557yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003558<ol>
3559 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3560 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3561 </li>
3562 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3563 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3564 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3565 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3566 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3567 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3568 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3569 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3570 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3571 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3572 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3573 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3574 <li><tt>sge</tt>: interprets the operands as signed values and yields
3575 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3576 <li><tt>slt</tt>: interprets the operands as signed values and yields
3577 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3578 <li><tt>sle</tt>: interprets the operands as signed values and yields
3579 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003580</ol>
3581<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Jeff Cohen222a8a42007-04-29 01:07:00 +00003582values are compared as if they were integers.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003583
3584<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003585<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3586 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3587 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3588 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3589 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3590 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003591</pre>
3592</div>
3593
3594<!-- _______________________________________________________________________ -->
3595<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3596</div>
3597<div class="doc_text">
3598<h5>Syntax:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003599<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003600</pre>
3601<h5>Overview:</h5>
3602<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3603of its floating point operands.</p>
3604<h5>Arguments:</h5>
3605<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Jeff Cohen222a8a42007-04-29 01:07:00 +00003606the condition code indicating the kind of comparison to perform. It is not
3607a value, just a keyword. The possible condition code are:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003608<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00003609 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003610 <li><tt>oeq</tt>: ordered and equal</li>
3611 <li><tt>ogt</tt>: ordered and greater than </li>
3612 <li><tt>oge</tt>: ordered and greater than or equal</li>
3613 <li><tt>olt</tt>: ordered and less than </li>
3614 <li><tt>ole</tt>: ordered and less than or equal</li>
3615 <li><tt>one</tt>: ordered and not equal</li>
3616 <li><tt>ord</tt>: ordered (no nans)</li>
3617 <li><tt>ueq</tt>: unordered or equal</li>
3618 <li><tt>ugt</tt>: unordered or greater than </li>
3619 <li><tt>uge</tt>: unordered or greater than or equal</li>
3620 <li><tt>ult</tt>: unordered or less than </li>
3621 <li><tt>ule</tt>: unordered or less than or equal</li>
3622 <li><tt>une</tt>: unordered or not equal</li>
3623 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003624 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003625</ol>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003626<p><i>Ordered</i> means that neither operand is a QNAN while
Reid Spencer02e0d1d2006-12-06 07:08:07 +00003627<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer784ef792007-01-04 05:19:58 +00003628<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3629<a href="#t_floating">floating point</a> typed. They must have identical
3630types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003631<h5>Semantics:</h5>
3632<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3633the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003634yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003635<ol>
3636 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003637 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003638 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003639 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003640 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003641 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003642 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003643 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003644 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003645 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003646 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003647 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003648 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003649 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3650 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003651 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003652 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003653 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003654 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003655 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003656 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003657 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003658 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003659 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003660 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003661 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003662 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003663 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3664</ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003665
3666<h5>Example:</h5>
3667<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3668 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3669 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3670 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3671</pre>
3672</div>
3673
Reid Spencer97c5fa42006-11-08 01:18:52 +00003674<!-- _______________________________________________________________________ -->
3675<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3676Instruction</a> </div>
3677<div class="doc_text">
3678<h5>Syntax:</h5>
3679<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3680<h5>Overview:</h5>
3681<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3682the SSA graph representing the function.</p>
3683<h5>Arguments:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003684<p>The type of the incoming values is specified with the first type
Reid Spencer97c5fa42006-11-08 01:18:52 +00003685field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3686as arguments, with one pair for each predecessor basic block of the
3687current block. Only values of <a href="#t_firstclass">first class</a>
3688type may be used as the value arguments to the PHI node. Only labels
3689may be used as the label arguments.</p>
3690<p>There must be no non-phi instructions between the start of a basic
3691block and the PHI instructions: i.e. PHI instructions must be first in
3692a basic block.</p>
3693<h5>Semantics:</h5>
Jeff Cohen222a8a42007-04-29 01:07:00 +00003694<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
3695specified by the pair corresponding to the predecessor basic block that executed
3696just prior to the current block.</p>
Reid Spencer97c5fa42006-11-08 01:18:52 +00003697<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003698<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add i32 %indvar, 1<br> br label %Loop<br></pre>
Reid Spencer97c5fa42006-11-08 01:18:52 +00003699</div>
3700
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003701<!-- _______________________________________________________________________ -->
3702<div class="doc_subsubsection">
3703 <a name="i_select">'<tt>select</tt>' Instruction</a>
3704</div>
3705
3706<div class="doc_text">
3707
3708<h5>Syntax:</h5>
3709
3710<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003711 &lt;result&gt; = select i1 &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003712</pre>
3713
3714<h5>Overview:</h5>
3715
3716<p>
3717The '<tt>select</tt>' instruction is used to choose one value based on a
3718condition, without branching.
3719</p>
3720
3721
3722<h5>Arguments:</h5>
3723
3724<p>
3725The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type.
3726</p>
3727
3728<h5>Semantics:</h5>
3729
3730<p>
3731If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00003732value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003733</p>
3734
3735<h5>Example:</h5>
3736
3737<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003738 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003739</pre>
3740</div>
3741
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00003742
3743<!-- _______________________________________________________________________ -->
3744<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00003745 <a name="i_call">'<tt>call</tt>' Instruction</a>
3746</div>
3747
Misha Brukman76307852003-11-08 01:05:38 +00003748<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00003749
Chris Lattner2f7c9632001-06-06 20:29:01 +00003750<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003751<pre>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00003752 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt; [&lt;fnty&gt;*] &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattnere23c1392005-05-06 05:47:36 +00003753</pre>
3754
Chris Lattner2f7c9632001-06-06 20:29:01 +00003755<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003756
Misha Brukman76307852003-11-08 01:05:38 +00003757<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003758
Chris Lattner2f7c9632001-06-06 20:29:01 +00003759<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003760
Misha Brukman76307852003-11-08 01:05:38 +00003761<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003762
Chris Lattnera8292f32002-05-06 22:08:29 +00003763<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00003764 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003765 <p>The optional "tail" marker indicates whether the callee function accesses
3766 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00003767 function call is eligible for tail call optimization. Note that calls may
3768 be marked "tail" even if they do not occur before a <a
3769 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00003770 </li>
3771 <li>
Duncan Sands16f122e2007-03-30 12:22:09 +00003772 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00003773 convention</a> the call should use. If none is specified, the call defaults
3774 to using C calling conventions.
3775 </li>
3776 <li>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00003777 <p>'<tt>ty</tt>': the type of the call instruction itself which is also
3778 the type of the return value. Functions that return no value are marked
3779 <tt><a href="#t_void">void</a></tt>.</p>
3780 </li>
3781 <li>
3782 <p>'<tt>fnty</tt>': shall be the signature of the pointer to function
3783 value being invoked. The argument types must match the types implied by
3784 this signature. This type can be omitted if the function is not varargs
3785 and if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003786 </li>
3787 <li>
3788 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3789 be invoked. In most cases, this is a direct function invocation, but
3790 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00003791 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003792 </li>
3793 <li>
3794 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00003795 function signature argument types. All arguments must be of
3796 <a href="#t_firstclass">first class</a> type. If the function signature
3797 indicates the function accepts a variable number of arguments, the extra
3798 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003799 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00003800</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00003801
Chris Lattner2f7c9632001-06-06 20:29:01 +00003802<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003803
Chris Lattner48b383b02003-11-25 01:02:51 +00003804<p>The '<tt>call</tt>' instruction is used to cause control flow to
3805transfer to a specified function, with its incoming arguments bound to
3806the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3807instruction in the called function, control flow continues with the
3808instruction after the function call, and the return value of the
3809function is bound to the result argument. This is a simpler case of
3810the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003811
Chris Lattner2f7c9632001-06-06 20:29:01 +00003812<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003813
3814<pre>
Nick Lewyckya9b13d52007-09-08 13:57:50 +00003815 %retval = call i32 @test(i32 %argc)
3816 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42);
3817 %X = tail call i32 @foo()
3818 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo()
3819 %Z = call void %foo(i8 97 signext)
Chris Lattnere23c1392005-05-06 05:47:36 +00003820</pre>
3821
Misha Brukman76307852003-11-08 01:05:38 +00003822</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003823
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003824<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00003825<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00003826 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003827</div>
3828
Misha Brukman76307852003-11-08 01:05:38 +00003829<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00003830
Chris Lattner26ca62e2003-10-18 05:51:36 +00003831<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003832
3833<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003834 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00003835</pre>
3836
Chris Lattner26ca62e2003-10-18 05:51:36 +00003837<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003838
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003839<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00003840the "variable argument" area of a function call. It is used to implement the
3841<tt>va_arg</tt> macro in C.</p>
3842
Chris Lattner26ca62e2003-10-18 05:51:36 +00003843<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003844
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003845<p>This instruction takes a <tt>va_list*</tt> value and the type of
3846the argument. It returns a value of the specified argument type and
Jeff Cohen222a8a42007-04-29 01:07:00 +00003847increments the <tt>va_list</tt> to point to the next argument. The
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003848actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003849
Chris Lattner26ca62e2003-10-18 05:51:36 +00003850<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003851
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003852<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3853type from the specified <tt>va_list</tt> and causes the
3854<tt>va_list</tt> to point to the next argument. For more information,
3855see the variable argument handling <a href="#int_varargs">Intrinsic
3856Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003857
3858<p>It is legal for this instruction to be called in a function which does not
3859take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00003860function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003861
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003862<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00003863href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00003864argument.</p>
3865
Chris Lattner26ca62e2003-10-18 05:51:36 +00003866<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003867
3868<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3869
Misha Brukman76307852003-11-08 01:05:38 +00003870</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003871
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003872<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003873<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3874<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00003875
Misha Brukman76307852003-11-08 01:05:38 +00003876<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00003877
3878<p>LLVM supports the notion of an "intrinsic function". These functions have
Reid Spencer4eefaab2007-04-01 08:04:23 +00003879well known names and semantics and are required to follow certain restrictions.
3880Overall, these intrinsics represent an extension mechanism for the LLVM
Jeff Cohen222a8a42007-04-29 01:07:00 +00003881language that does not require changing all of the transformations in LLVM when
Gabor Greifa54634a2007-07-06 22:07:22 +00003882adding to the language (or the bitcode reader/writer, the parser, etc...).</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00003883
John Criswell88190562005-05-16 16:17:45 +00003884<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Jeff Cohen222a8a42007-04-29 01:07:00 +00003885prefix is reserved in LLVM for intrinsic names; thus, function names may not
3886begin with this prefix. Intrinsic functions must always be external functions:
3887you cannot define the body of intrinsic functions. Intrinsic functions may
3888only be used in call or invoke instructions: it is illegal to take the address
3889of an intrinsic function. Additionally, because intrinsic functions are part
3890of the LLVM language, it is required if any are added that they be documented
3891here.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00003892
Chandler Carruth7132e002007-08-04 01:51:18 +00003893<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents
3894a family of functions that perform the same operation but on different data
3895types. Because LLVM can represent over 8 million different integer types,
3896overloading is used commonly to allow an intrinsic function to operate on any
3897integer type. One or more of the argument types or the result type can be
3898overloaded to accept any integer type. Argument types may also be defined as
3899exactly matching a previous argument's type or the result type. This allows an
3900intrinsic function which accepts multiple arguments, but needs all of them to
3901be of the same type, to only be overloaded with respect to a single argument or
3902the result.</p>
Chris Lattnerfee11462004-02-12 17:01:32 +00003903
Chandler Carruth7132e002007-08-04 01:51:18 +00003904<p>Overloaded intrinsics will have the names of its overloaded argument types
3905encoded into its function name, each preceded by a period. Only those types
3906which are overloaded result in a name suffix. Arguments whose type is matched
3907against another type do not. For example, the <tt>llvm.ctpop</tt> function can
3908take an integer of any width and returns an integer of exactly the same integer
3909width. This leads to a family of functions such as
3910<tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>.
3911Only one type, the return type, is overloaded, and only one type suffix is
3912required. Because the argument's type is matched against the return type, it
3913does not require its own name suffix.</p>
Reid Spencer4eefaab2007-04-01 08:04:23 +00003914
3915<p>To learn how to add an intrinsic function, please see the
3916<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00003917</p>
3918
Misha Brukman76307852003-11-08 01:05:38 +00003919</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003920
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003921<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00003922<div class="doc_subsection">
3923 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3924</div>
3925
Misha Brukman76307852003-11-08 01:05:38 +00003926<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003927
Misha Brukman76307852003-11-08 01:05:38 +00003928<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00003929 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00003930intrinsic functions. These functions are related to the similarly
3931named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003932
Chris Lattner48b383b02003-11-25 01:02:51 +00003933<p>All of these functions operate on arguments that use a
3934target-specific value type "<tt>va_list</tt>". The LLVM assembly
3935language reference manual does not define what this type is, so all
Jeff Cohen222a8a42007-04-29 01:07:00 +00003936transformations should be prepared to handle these functions regardless of
3937the type used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003938
Chris Lattner30b868d2006-05-15 17:26:46 +00003939<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00003940instruction and the variable argument handling intrinsic functions are
3941used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003942
Bill Wendling3716c5d2007-05-29 09:04:49 +00003943<div class="doc_code">
Chris Lattnerfee11462004-02-12 17:01:32 +00003944<pre>
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003945define i32 @test(i32 %X, ...) {
Chris Lattnerfee11462004-02-12 17:01:32 +00003946 ; Initialize variable argument processing
Jeff Cohen222a8a42007-04-29 01:07:00 +00003947 %ap = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003948 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003949 call void @llvm.va_start(i8* %ap2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003950
3951 ; Read a single integer argument
Jeff Cohen222a8a42007-04-29 01:07:00 +00003952 %tmp = va_arg i8** %ap, i32
Chris Lattnerfee11462004-02-12 17:01:32 +00003953
3954 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Jeff Cohen222a8a42007-04-29 01:07:00 +00003955 %aq = alloca i8*
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003956 %aq2 = bitcast i8** %aq to i8*
Jeff Cohen222a8a42007-04-29 01:07:00 +00003957 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003958 call void @llvm.va_end(i8* %aq2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003959
3960 ; Stop processing of arguments.
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003961 call void @llvm.va_end(i8* %ap2)
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003962 ret i32 %tmp
Chris Lattnerfee11462004-02-12 17:01:32 +00003963}
Anton Korobeynikov640bbe02007-03-21 23:58:04 +00003964
3965declare void @llvm.va_start(i8*)
3966declare void @llvm.va_copy(i8*, i8*)
3967declare void @llvm.va_end(i8*)
Chris Lattnerfee11462004-02-12 17:01:32 +00003968</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003969</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003970
Bill Wendling3716c5d2007-05-29 09:04:49 +00003971</div>
3972
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003973<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003974<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00003975 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00003976</div>
3977
3978
Misha Brukman76307852003-11-08 01:05:38 +00003979<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003980<h5>Syntax:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003981<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003982<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003983<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3984<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3985href="#i_va_arg">va_arg</a></tt>.</p>
3986
3987<h5>Arguments:</h5>
3988
3989<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3990
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003991<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003992
3993<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3994macro available in C. In a target-dependent way, it initializes the
Jeff Cohen222a8a42007-04-29 01:07:00 +00003995<tt>va_list</tt> element to which the argument points, so that the next call to
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003996<tt>va_arg</tt> will produce the first variable argument passed to the function.
3997Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
Jeff Cohen222a8a42007-04-29 01:07:00 +00003998last argument of the function as the compiler can figure that out.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003999
Misha Brukman76307852003-11-08 01:05:38 +00004000</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004001
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004002<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004003<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004004 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004005</div>
4006
Misha Brukman76307852003-11-08 01:05:38 +00004007<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004008<h5>Syntax:</h5>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004009<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004010<h5>Overview:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004011
Jeff Cohen222a8a42007-04-29 01:07:00 +00004012<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Reid Spencer96a5f022007-04-04 02:42:35 +00004013which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00004014or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004015
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004016<h5>Arguments:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004017
Jeff Cohen222a8a42007-04-29 01:07:00 +00004018<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004019
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004020<h5>Semantics:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004021
Misha Brukman76307852003-11-08 01:05:38 +00004022<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Jeff Cohen222a8a42007-04-29 01:07:00 +00004023macro available in C. In a target-dependent way, it destroys the
4024<tt>va_list</tt> element to which the argument points. Calls to <a
4025href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy">
4026<tt>llvm.va_copy</tt></a> must be matched exactly with calls to
4027<tt>llvm.va_end</tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00004028
Misha Brukman76307852003-11-08 01:05:38 +00004029</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004030
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004031<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00004032<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004033 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner941515c2004-01-06 05:31:32 +00004034</div>
4035
Misha Brukman76307852003-11-08 01:05:38 +00004036<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004037
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004038<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004039
4040<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004041 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00004042</pre>
4043
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004044<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004045
Jeff Cohen222a8a42007-04-29 01:07:00 +00004046<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
4047from the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004048
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004049<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004050
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004051<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00004052The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00004053
Chris Lattner757528b0b2004-05-23 21:06:01 +00004054
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00004055<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004056
Jeff Cohen222a8a42007-04-29 01:07:00 +00004057<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
4058macro available in C. In a target-dependent way, it copies the source
4059<tt>va_list</tt> element into the destination <tt>va_list</tt> element. This
4060intrinsic is necessary because the <tt><a href="#int_va_start">
4061llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for
4062example, memory allocation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004063
Misha Brukman76307852003-11-08 01:05:38 +00004064</div>
Chris Lattner941515c2004-01-06 05:31:32 +00004065
Chris Lattnerfee11462004-02-12 17:01:32 +00004066<!-- ======================================================================= -->
4067<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00004068 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
4069</div>
4070
4071<div class="doc_text">
4072
4073<p>
4074LLVM support for <a href="GarbageCollection.html">Accurate Garbage
4075Collection</a> requires the implementation and generation of these intrinsics.
Reid Spencer96a5f022007-04-04 02:42:35 +00004076These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
Chris Lattner757528b0b2004-05-23 21:06:01 +00004077stack</a>, as well as garbage collector implementations that require <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004078href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
Chris Lattner757528b0b2004-05-23 21:06:01 +00004079Front-ends for type-safe garbage collected languages should generate these
4080intrinsics to make use of the LLVM garbage collectors. For more details, see <a
4081href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
4082</p>
Christopher Lamb55c6d4f2007-12-17 01:00:21 +00004083
4084<p>The garbage collection intrinsics only operate on objects in the generic
4085 address space (address space zero).</p>
4086
Chris Lattner757528b0b2004-05-23 21:06:01 +00004087</div>
4088
4089<!-- _______________________________________________________________________ -->
4090<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004091 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004092</div>
4093
4094<div class="doc_text">
4095
4096<h5>Syntax:</h5>
4097
4098<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004099 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00004100</pre>
4101
4102<h5>Overview:</h5>
4103
John Criswelldfe6a862004-12-10 15:51:16 +00004104<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00004105the code generator, and allows some metadata to be associated with it.</p>
4106
4107<h5>Arguments:</h5>
4108
4109<p>The first argument specifies the address of a stack object that contains the
4110root pointer. The second pointer (which must be either a constant or a global
4111value address) contains the meta-data to be associated with the root.</p>
4112
4113<h5>Semantics:</h5>
4114
4115<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
4116location. At compile-time, the code generator generates information to allow
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00004117the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
4118intrinsic may only be used in a function which <a href="#gc">specifies a GC
4119algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004120
4121</div>
4122
4123
4124<!-- _______________________________________________________________________ -->
4125<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004126 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004127</div>
4128
4129<div class="doc_text">
4130
4131<h5>Syntax:</h5>
4132
4133<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004134 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00004135</pre>
4136
4137<h5>Overview:</h5>
4138
4139<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
4140locations, allowing garbage collector implementations that require read
4141barriers.</p>
4142
4143<h5>Arguments:</h5>
4144
Chris Lattnerf9228072006-03-14 20:02:51 +00004145<p>The second argument is the address to read from, which should be an address
4146allocated from the garbage collector. The first object is a pointer to the
4147start of the referenced object, if needed by the language runtime (otherwise
4148null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004149
4150<h5>Semantics:</h5>
4151
4152<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
4153instruction, but may be replaced with substantially more complex code by the
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00004154garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
4155may only be used in a function which <a href="#gc">specifies a GC
4156algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004157
4158</div>
4159
4160
4161<!-- _______________________________________________________________________ -->
4162<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004163 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004164</div>
4165
4166<div class="doc_text">
4167
4168<h5>Syntax:</h5>
4169
4170<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004171 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00004172</pre>
4173
4174<h5>Overview:</h5>
4175
4176<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
4177locations, allowing garbage collector implementations that require write
4178barriers (such as generational or reference counting collectors).</p>
4179
4180<h5>Arguments:</h5>
4181
Chris Lattnerf9228072006-03-14 20:02:51 +00004182<p>The first argument is the reference to store, the second is the start of the
4183object to store it to, and the third is the address of the field of Obj to
4184store to. If the runtime does not require a pointer to the object, Obj may be
4185null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004186
4187<h5>Semantics:</h5>
4188
4189<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
4190instruction, but may be replaced with substantially more complex code by the
Gordon Henriksenfb56bde2007-12-25 02:31:26 +00004191garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
4192may only be used in a function which <a href="#gc">specifies a GC
4193algorithm</a>.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00004194
4195</div>
4196
4197
4198
4199<!-- ======================================================================= -->
4200<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00004201 <a name="int_codegen">Code Generator Intrinsics</a>
4202</div>
4203
4204<div class="doc_text">
4205<p>
4206These intrinsics are provided by LLVM to expose special features that may only
4207be implemented with code generator support.
4208</p>
4209
4210</div>
4211
4212<!-- _______________________________________________________________________ -->
4213<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004214 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004215</div>
4216
4217<div class="doc_text">
4218
4219<h5>Syntax:</h5>
4220<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004221 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004222</pre>
4223
4224<h5>Overview:</h5>
4225
4226<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00004227The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
4228target-specific value indicating the return address of the current function
4229or one of its callers.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004230</p>
4231
4232<h5>Arguments:</h5>
4233
4234<p>
4235The argument to this intrinsic indicates which function to return the address
4236for. Zero indicates the calling function, one indicates its caller, etc. The
4237argument is <b>required</b> to be a constant integer value.
4238</p>
4239
4240<h5>Semantics:</h5>
4241
4242<p>
4243The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
4244the return address of the specified call frame, or zero if it cannot be
4245identified. The value returned by this intrinsic is likely to be incorrect or 0
4246for arguments other than zero, so it should only be used for debugging purposes.
4247</p>
4248
4249<p>
4250Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00004251aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00004252source-language caller.
4253</p>
4254</div>
4255
4256
4257<!-- _______________________________________________________________________ -->
4258<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004259 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004260</div>
4261
4262<div class="doc_text">
4263
4264<h5>Syntax:</h5>
4265<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004266 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004267</pre>
4268
4269<h5>Overview:</h5>
4270
4271<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00004272The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
4273target-specific frame pointer value for the specified stack frame.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004274</p>
4275
4276<h5>Arguments:</h5>
4277
4278<p>
4279The argument to this intrinsic indicates which function to return the frame
4280pointer for. Zero indicates the calling function, one indicates its caller,
4281etc. The argument is <b>required</b> to be a constant integer value.
4282</p>
4283
4284<h5>Semantics:</h5>
4285
4286<p>
4287The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
4288the frame address of the specified call frame, or zero if it cannot be
4289identified. The value returned by this intrinsic is likely to be incorrect or 0
4290for arguments other than zero, so it should only be used for debugging purposes.
4291</p>
4292
4293<p>
4294Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00004295aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00004296source-language caller.
4297</p>
4298</div>
4299
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004300<!-- _______________________________________________________________________ -->
4301<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004302 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00004303</div>
4304
4305<div class="doc_text">
4306
4307<h5>Syntax:</h5>
4308<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004309 declare i8 *@llvm.stacksave()
Chris Lattner2f0f0012006-01-13 02:03:13 +00004310</pre>
4311
4312<h5>Overview:</h5>
4313
4314<p>
4315The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
Reid Spencer96a5f022007-04-04 02:42:35 +00004316the function stack, for use with <a href="#int_stackrestore">
Chris Lattner2f0f0012006-01-13 02:03:13 +00004317<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
4318features like scoped automatic variable sized arrays in C99.
4319</p>
4320
4321<h5>Semantics:</h5>
4322
4323<p>
4324This intrinsic returns a opaque pointer value that can be passed to <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004325href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
Chris Lattner2f0f0012006-01-13 02:03:13 +00004326<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
4327<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
4328state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
4329practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
4330that were allocated after the <tt>llvm.stacksave</tt> was executed.
4331</p>
4332
4333</div>
4334
4335<!-- _______________________________________________________________________ -->
4336<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004337 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner2f0f0012006-01-13 02:03:13 +00004338</div>
4339
4340<div class="doc_text">
4341
4342<h5>Syntax:</h5>
4343<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004344 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner2f0f0012006-01-13 02:03:13 +00004345</pre>
4346
4347<h5>Overview:</h5>
4348
4349<p>
4350The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
4351the function stack to the state it was in when the corresponding <a
Reid Spencer96a5f022007-04-04 02:42:35 +00004352href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
Chris Lattner2f0f0012006-01-13 02:03:13 +00004353useful for implementing language features like scoped automatic variable sized
4354arrays in C99.
4355</p>
4356
4357<h5>Semantics:</h5>
4358
4359<p>
Reid Spencer96a5f022007-04-04 02:42:35 +00004360See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
Chris Lattner2f0f0012006-01-13 02:03:13 +00004361</p>
4362
4363</div>
4364
4365
4366<!-- _______________________________________________________________________ -->
4367<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004368 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004369</div>
4370
4371<div class="doc_text">
4372
4373<h5>Syntax:</h5>
4374<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004375 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004376</pre>
4377
4378<h5>Overview:</h5>
4379
4380
4381<p>
4382The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00004383a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
4384no
4385effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00004386characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004387</p>
4388
4389<h5>Arguments:</h5>
4390
4391<p>
4392<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
4393determining if the fetch should be for a read (0) or write (1), and
4394<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00004395locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00004396<tt>locality</tt> arguments must be constant integers.
4397</p>
4398
4399<h5>Semantics:</h5>
4400
4401<p>
4402This intrinsic does not modify the behavior of the program. In particular,
4403prefetches cannot trap and do not produce a value. On targets that support this
4404intrinsic, the prefetch can provide hints to the processor cache for better
4405performance.
4406</p>
4407
4408</div>
4409
Andrew Lenharthb4427912005-03-28 20:05:49 +00004410<!-- _______________________________________________________________________ -->
4411<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004412 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharthb4427912005-03-28 20:05:49 +00004413</div>
4414
4415<div class="doc_text">
4416
4417<h5>Syntax:</h5>
4418<pre>
Chris Lattner12477732007-09-21 17:30:40 +00004419 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Andrew Lenharthb4427912005-03-28 20:05:49 +00004420</pre>
4421
4422<h5>Overview:</h5>
4423
4424
4425<p>
John Criswell88190562005-05-16 16:17:45 +00004426The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4427(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00004428code to simulators and other tools. The method is target specific, but it is
4429expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00004430The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnere64d41d2005-11-15 06:07:55 +00004431after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb40261e2006-03-24 07:16:10 +00004432optimizations. The intended use is to be inserted after optimizations to allow
John Criswell88190562005-05-16 16:17:45 +00004433correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00004434</p>
4435
4436<h5>Arguments:</h5>
4437
4438<p>
4439<tt>id</tt> is a numerical id identifying the marker.
4440</p>
4441
4442<h5>Semantics:</h5>
4443
4444<p>
4445This intrinsic does not modify the behavior of the program. Backends that do not
4446support this intrinisic may ignore it.
4447</p>
4448
4449</div>
4450
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004451<!-- _______________________________________________________________________ -->
4452<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004453 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004454</div>
4455
4456<div class="doc_text">
4457
4458<h5>Syntax:</h5>
4459<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004460 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004461</pre>
4462
4463<h5>Overview:</h5>
4464
4465
4466<p>
4467The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4468counter register (or similar low latency, high accuracy clocks) on those targets
4469that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4470As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4471should only be used for small timings.
4472</p>
4473
4474<h5>Semantics:</h5>
4475
4476<p>
4477When directly supported, reading the cycle counter should not modify any memory.
4478Implementations are allowed to either return a application specific value or a
4479system wide value. On backends without support, this is lowered to a constant 0.
4480</p>
4481
4482</div>
4483
Chris Lattner3649c3a2004-02-14 04:08:35 +00004484<!-- ======================================================================= -->
4485<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00004486 <a name="int_libc">Standard C Library Intrinsics</a>
4487</div>
4488
4489<div class="doc_text">
4490<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004491LLVM provides intrinsics for a few important standard C library functions.
4492These intrinsics allow source-language front-ends to pass information about the
4493alignment of the pointer arguments to the code generator, providing opportunity
4494for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00004495</p>
4496
4497</div>
4498
4499<!-- _______________________________________________________________________ -->
4500<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004501 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattnerfee11462004-02-12 17:01:32 +00004502</div>
4503
4504<div class="doc_text">
4505
4506<h5>Syntax:</h5>
4507<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004508 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004509 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004510 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004511 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00004512</pre>
4513
4514<h5>Overview:</h5>
4515
4516<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004517The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004518location to the destination location.
4519</p>
4520
4521<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004522Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4523intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00004524</p>
4525
4526<h5>Arguments:</h5>
4527
4528<p>
4529The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004530the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00004531specifying the number of bytes to copy, and the fourth argument is the alignment
4532of the source and destination locations.
4533</p>
4534
Chris Lattner4c67c482004-02-12 21:18:15 +00004535<p>
4536If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004537the caller guarantees that both the source and destination pointers are aligned
4538to that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004539</p>
4540
Chris Lattnerfee11462004-02-12 17:01:32 +00004541<h5>Semantics:</h5>
4542
4543<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004544The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004545location to the destination location, which are not allowed to overlap. It
4546copies "len" bytes of memory over. If the argument is known to be aligned to
4547some boundary, this can be specified as the fourth argument, otherwise it should
4548be set to 0 or 1.
4549</p>
4550</div>
4551
4552
Chris Lattnerf30152e2004-02-12 18:10:10 +00004553<!-- _______________________________________________________________________ -->
4554<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004555 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattnerf30152e2004-02-12 18:10:10 +00004556</div>
4557
4558<div class="doc_text">
4559
4560<h5>Syntax:</h5>
4561<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004562 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004563 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004564 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004565 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00004566</pre>
4567
4568<h5>Overview:</h5>
4569
4570<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004571The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4572location to the destination location. It is similar to the
Chris Lattnerec564022008-01-06 19:51:52 +00004573'<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004574</p>
4575
4576<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004577Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4578intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004579</p>
4580
4581<h5>Arguments:</h5>
4582
4583<p>
4584The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004585the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00004586specifying the number of bytes to copy, and the fourth argument is the alignment
4587of the source and destination locations.
4588</p>
4589
Chris Lattner4c67c482004-02-12 21:18:15 +00004590<p>
4591If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004592the caller guarantees that the source and destination pointers are aligned to
4593that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004594</p>
4595
Chris Lattnerf30152e2004-02-12 18:10:10 +00004596<h5>Semantics:</h5>
4597
4598<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004599The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00004600location to the destination location, which may overlap. It
4601copies "len" bytes of memory over. If the argument is known to be aligned to
4602some boundary, this can be specified as the fourth argument, otherwise it should
4603be set to 0 or 1.
4604</p>
4605</div>
4606
Chris Lattner941515c2004-01-06 05:31:32 +00004607
Chris Lattner3649c3a2004-02-14 04:08:35 +00004608<!-- _______________________________________________________________________ -->
4609<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004610 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004611</div>
4612
4613<div class="doc_text">
4614
4615<h5>Syntax:</h5>
4616<pre>
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004617 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004618 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004619 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004620 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004621</pre>
4622
4623<h5>Overview:</h5>
4624
4625<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004626The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00004627byte value.
4628</p>
4629
4630<p>
4631Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4632does not return a value, and takes an extra alignment argument.
4633</p>
4634
4635<h5>Arguments:</h5>
4636
4637<p>
4638The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00004639byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00004640argument specifying the number of bytes to fill, and the fourth argument is the
4641known alignment of destination location.
4642</p>
4643
4644<p>
4645If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004646the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004647</p>
4648
4649<h5>Semantics:</h5>
4650
4651<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004652The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4653the
Chris Lattner3649c3a2004-02-14 04:08:35 +00004654destination location. If the argument is known to be aligned to some boundary,
4655this can be specified as the fourth argument, otherwise it should be set to 0 or
46561.
4657</p>
4658</div>
4659
4660
Chris Lattner3b4f4372004-06-11 02:28:03 +00004661<!-- _______________________________________________________________________ -->
4662<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004663 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004664</div>
4665
4666<div class="doc_text">
4667
4668<h5>Syntax:</h5>
Dale Johannesendd89d272007-10-02 17:47:38 +00004669<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
Dan Gohmanb6324c12007-10-15 20:30:11 +00004670floating point or vector of floating point type. Not all targets support all
4671types however.
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004672<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00004673 declare float @llvm.sqrt.f32(float %Val)
4674 declare double @llvm.sqrt.f64(double %Val)
4675 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
4676 declare fp128 @llvm.sqrt.f128(fp128 %Val)
4677 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004678</pre>
4679
4680<h5>Overview:</h5>
4681
4682<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004683The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Dan Gohmanb6324c12007-10-15 20:30:11 +00004684returning the same value as the libm '<tt>sqrt</tt>' functions would. Unlike
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004685<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
Chris Lattner00d7cb92008-01-29 07:00:44 +00004686negative numbers other than -0.0 (which allows for better optimization, because
4687there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is
4688defined to return -0.0 like IEEE sqrt.
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004689</p>
4690
4691<h5>Arguments:</h5>
4692
4693<p>
4694The argument and return value are floating point numbers of the same type.
4695</p>
4696
4697<h5>Semantics:</h5>
4698
4699<p>
Dan Gohman33988db2007-07-16 14:37:41 +00004700This function returns the sqrt of the specified operand if it is a nonnegative
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004701floating point number.
4702</p>
4703</div>
4704
Chris Lattner33b73f92006-09-08 06:34:02 +00004705<!-- _______________________________________________________________________ -->
4706<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004707 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattner33b73f92006-09-08 06:34:02 +00004708</div>
4709
4710<div class="doc_text">
4711
4712<h5>Syntax:</h5>
Dale Johannesendd89d272007-10-02 17:47:38 +00004713<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
Dan Gohmanb6324c12007-10-15 20:30:11 +00004714floating point or vector of floating point type. Not all targets support all
4715types however.
Chris Lattner33b73f92006-09-08 06:34:02 +00004716<pre>
Dale Johannesendd89d272007-10-02 17:47:38 +00004717 declare float @llvm.powi.f32(float %Val, i32 %power)
4718 declare double @llvm.powi.f64(double %Val, i32 %power)
4719 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
4720 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
4721 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Chris Lattner33b73f92006-09-08 06:34:02 +00004722</pre>
4723
4724<h5>Overview:</h5>
4725
4726<p>
4727The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4728specified (positive or negative) power. The order of evaluation of
Dan Gohmanb6324c12007-10-15 20:30:11 +00004729multiplications is not defined. When a vector of floating point type is
4730used, the second argument remains a scalar integer value.
Chris Lattner33b73f92006-09-08 06:34:02 +00004731</p>
4732
4733<h5>Arguments:</h5>
4734
4735<p>
4736The second argument is an integer power, and the first is a value to raise to
4737that power.
4738</p>
4739
4740<h5>Semantics:</h5>
4741
4742<p>
4743This function returns the first value raised to the second power with an
4744unspecified sequence of rounding operations.</p>
4745</div>
4746
Dan Gohmanb6324c12007-10-15 20:30:11 +00004747<!-- _______________________________________________________________________ -->
4748<div class="doc_subsubsection">
4749 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
4750</div>
4751
4752<div class="doc_text">
4753
4754<h5>Syntax:</h5>
4755<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
4756floating point or vector of floating point type. Not all targets support all
4757types however.
4758<pre>
4759 declare float @llvm.sin.f32(float %Val)
4760 declare double @llvm.sin.f64(double %Val)
4761 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
4762 declare fp128 @llvm.sin.f128(fp128 %Val)
4763 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
4764</pre>
4765
4766<h5>Overview:</h5>
4767
4768<p>
4769The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.
4770</p>
4771
4772<h5>Arguments:</h5>
4773
4774<p>
4775The argument and return value are floating point numbers of the same type.
4776</p>
4777
4778<h5>Semantics:</h5>
4779
4780<p>
4781This function returns the sine of the specified operand, returning the
4782same values as the libm <tt>sin</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00004783conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00004784</div>
4785
4786<!-- _______________________________________________________________________ -->
4787<div class="doc_subsubsection">
4788 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
4789</div>
4790
4791<div class="doc_text">
4792
4793<h5>Syntax:</h5>
4794<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
4795floating point or vector of floating point type. Not all targets support all
4796types however.
4797<pre>
4798 declare float @llvm.cos.f32(float %Val)
4799 declare double @llvm.cos.f64(double %Val)
4800 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
4801 declare fp128 @llvm.cos.f128(fp128 %Val)
4802 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
4803</pre>
4804
4805<h5>Overview:</h5>
4806
4807<p>
4808The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.
4809</p>
4810
4811<h5>Arguments:</h5>
4812
4813<p>
4814The argument and return value are floating point numbers of the same type.
4815</p>
4816
4817<h5>Semantics:</h5>
4818
4819<p>
4820This function returns the cosine of the specified operand, returning the
4821same values as the libm <tt>cos</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00004822conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00004823</div>
4824
4825<!-- _______________________________________________________________________ -->
4826<div class="doc_subsubsection">
4827 <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
4828</div>
4829
4830<div class="doc_text">
4831
4832<h5>Syntax:</h5>
4833<p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
4834floating point or vector of floating point type. Not all targets support all
4835types however.
4836<pre>
4837 declare float @llvm.pow.f32(float %Val, float %Power)
4838 declare double @llvm.pow.f64(double %Val, double %Power)
4839 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
4840 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
4841 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
4842</pre>
4843
4844<h5>Overview:</h5>
4845
4846<p>
4847The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
4848specified (positive or negative) power.
4849</p>
4850
4851<h5>Arguments:</h5>
4852
4853<p>
4854The second argument is a floating point power, and the first is a value to
4855raise to that power.
4856</p>
4857
4858<h5>Semantics:</h5>
4859
4860<p>
4861This function returns the first value raised to the second power,
4862returning the
4863same values as the libm <tt>pow</tt> functions would, and handles error
Dan Gohmand0806a02007-10-17 18:05:13 +00004864conditions in the same way.</p>
Dan Gohmanb6324c12007-10-15 20:30:11 +00004865</div>
4866
Chris Lattner33b73f92006-09-08 06:34:02 +00004867
Andrew Lenharth1d463522005-05-03 18:01:48 +00004868<!-- ======================================================================= -->
4869<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004870 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004871</div>
4872
4873<div class="doc_text">
4874<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004875LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004876These allow efficient code generation for some algorithms.
4877</p>
4878
4879</div>
4880
4881<!-- _______________________________________________________________________ -->
4882<div class="doc_subsubsection">
Reid Spencer96a5f022007-04-04 02:42:35 +00004883 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004884</div>
4885
4886<div class="doc_text">
4887
4888<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004889<p>This is an overloaded intrinsic function. You can use bswap on any integer
Chandler Carruth7132e002007-08-04 01:51:18 +00004890type that is an even number of bytes (i.e. BitWidth % 16 == 0).
Nate Begeman0f223bb2006-01-13 23:26:38 +00004891<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00004892 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
4893 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
4894 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00004895</pre>
4896
4897<h5>Overview:</h5>
4898
4899<p>
Reid Spencerf361c4f2007-04-02 02:25:19 +00004900The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
Reid Spencer4eefaab2007-04-01 08:04:23 +00004901values with an even number of bytes (positive multiple of 16 bits). These are
4902useful for performing operations on data that is not in the target's native
4903byte order.
Nate Begeman0f223bb2006-01-13 23:26:38 +00004904</p>
4905
4906<h5>Semantics:</h5>
4907
4908<p>
Chandler Carruth7132e002007-08-04 01:51:18 +00004909The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004910and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
4911intrinsic returns an i32 value that has the four bytes of the input i32
4912swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Chandler Carruth7132e002007-08-04 01:51:18 +00004913i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>,
4914<tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to
Reid Spencer4eefaab2007-04-01 08:04:23 +00004915additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Nate Begeman0f223bb2006-01-13 23:26:38 +00004916</p>
4917
4918</div>
4919
4920<!-- _______________________________________________________________________ -->
4921<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004922 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004923</div>
4924
4925<div class="doc_text">
4926
4927<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004928<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
4929width. Not all targets support all bit widths however.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004930<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00004931 declare i8 @llvm.ctpop.i8 (i8 &lt;src&gt;)
4932 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004933 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00004934 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
4935 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004936</pre>
4937
4938<h5>Overview:</h5>
4939
4940<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004941The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4942value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004943</p>
4944
4945<h5>Arguments:</h5>
4946
4947<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004948The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004949integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004950</p>
4951
4952<h5>Semantics:</h5>
4953
4954<p>
4955The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4956</p>
4957</div>
4958
4959<!-- _______________________________________________________________________ -->
4960<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004961 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004962</div>
4963
4964<div class="doc_text">
4965
4966<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00004967<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
4968integer bit width. Not all targets support all bit widths however.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004969<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00004970 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
4971 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00004972 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00004973 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
4974 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004975</pre>
4976
4977<h5>Overview:</h5>
4978
4979<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004980The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4981leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004982</p>
4983
4984<h5>Arguments:</h5>
4985
4986<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004987The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004988integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004989</p>
4990
4991<h5>Semantics:</h5>
4992
4993<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004994The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4995in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004996of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004997</p>
4998</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00004999
5000
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005001
5002<!-- _______________________________________________________________________ -->
5003<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00005004 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005005</div>
5006
5007<div class="doc_text">
5008
5009<h5>Syntax:</h5>
Reid Spencer4eefaab2007-04-01 08:04:23 +00005010<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
5011integer bit width. Not all targets support all bit widths however.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005012<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005013 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5014 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovbe9c93c2007-03-22 00:02:17 +00005015 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carruth7132e002007-08-04 01:51:18 +00005016 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5017 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005018</pre>
5019
5020<h5>Overview:</h5>
5021
5022<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00005023The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5024trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005025</p>
5026
5027<h5>Arguments:</h5>
5028
5029<p>
5030The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00005031integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00005032</p>
5033
5034<h5>Semantics:</h5>
5035
5036<p>
5037The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
5038in a variable. If the src == 0 then the result is the size in bits of the type
5039of src. For example, <tt>llvm.cttz(2) = 1</tt>.
5040</p>
5041</div>
5042
Reid Spencer8a5799f2007-04-01 08:27:01 +00005043<!-- _______________________________________________________________________ -->
5044<div class="doc_subsubsection">
Reid Spencerea2945e2007-04-10 02:51:31 +00005045 <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a>
Reid Spencer8bc7d952007-04-01 19:00:37 +00005046</div>
5047
5048<div class="doc_text">
5049
5050<h5>Syntax:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00005051<p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt>
Reid Spencer8bc7d952007-04-01 19:00:37 +00005052on any integer bit width.
5053<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005054 declare i17 @llvm.part.select.i17 (i17 %val, i32 %loBit, i32 %hiBit)
5055 declare i29 @llvm.part.select.i29 (i29 %val, i32 %loBit, i32 %hiBit)
Reid Spencer8bc7d952007-04-01 19:00:37 +00005056</pre>
5057
5058<h5>Overview:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00005059<p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a
Reid Spencer8bc7d952007-04-01 19:00:37 +00005060range of bits from an integer value and returns them in the same bit width as
5061the original value.</p>
5062
5063<h5>Arguments:</h5>
5064<p>The first argument, <tt>%val</tt> and the result may be integer types of
5065any bit width but they must have the same bit width. The second and third
Reid Spencer96a5f022007-04-04 02:42:35 +00005066arguments must be <tt>i32</tt> type since they specify only a bit index.</p>
Reid Spencer8bc7d952007-04-01 19:00:37 +00005067
5068<h5>Semantics:</h5>
Reid Spencerea2945e2007-04-10 02:51:31 +00005069<p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes
Reid Spencer96a5f022007-04-04 02:42:35 +00005070of operation: forwards and reverse. If <tt>%loBit</tt> is greater than
5071<tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it
5072operates in forward mode.</p>
5073<p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt>
5074right by <tt>%loBit</tt> bits and then ANDing it with a mask with
Reid Spencer8bc7d952007-04-01 19:00:37 +00005075only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p>
5076<ol>
5077 <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified
5078 by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li>
5079 <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value
5080 to determine the number of bits to retain.</li>
5081 <li>A mask of the retained bits is created by shifting a -1 value.</li>
5082 <li>The mask is ANDed with <tt>%val</tt> to produce the result.
5083</ol>
Reid Spencer70845c02007-05-14 16:14:57 +00005084<p>In reverse mode, a similar computation is made except that the bits are
5085returned in the reverse order. So, for example, if <tt>X</tt> has the value
5086<tt>i16 0x0ACF (101011001111)</tt> and we apply
5087<tt>part.select(i16 X, 8, 3)</tt> to it, we get back the value
5088<tt>i16 0x0026 (000000100110)</tt>.</p>
Reid Spencer8bc7d952007-04-01 19:00:37 +00005089</div>
5090
Reid Spencer5bf54c82007-04-11 23:23:49 +00005091<div class="doc_subsubsection">
5092 <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a>
5093</div>
5094
5095<div class="doc_text">
5096
5097<h5>Syntax:</h5>
5098<p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt>
5099on any integer bit width.
5100<pre>
Chandler Carruth7132e002007-08-04 01:51:18 +00005101 declare i17 @llvm.part.set.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi)
5102 declare i29 @llvm.part.set.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi)
Reid Spencer5bf54c82007-04-11 23:23:49 +00005103</pre>
5104
5105<h5>Overview:</h5>
5106<p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range
5107of bits in an integer value with another integer value. It returns the integer
5108with the replaced bits.</p>
5109
5110<h5>Arguments:</h5>
5111<p>The first argument, <tt>%val</tt> and the result may be integer types of
5112any bit width but they must have the same bit width. <tt>%val</tt> is the value
5113whose bits will be replaced. The second argument, <tt>%repl</tt> may be an
5114integer of any bit width. The third and fourth arguments must be <tt>i32</tt>
5115type since they specify only a bit index.</p>
5116
5117<h5>Semantics:</h5>
5118<p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes
5119of operation: forwards and reverse. If <tt>%lo</tt> is greater than
5120<tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it
5121operates in forward mode.</p>
5122<p>For both modes, the <tt>%repl</tt> value is prepared for use by either
5123truncating it down to the size of the replacement area or zero extending it
5124up to that size.</p>
5125<p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive)
5126are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit
5127in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up
5128to the <tt>%hi</tt>th bit.
Reid Spencer146281c2007-05-14 16:50:20 +00005129<p>In reverse mode, a similar computation is made except that the bits are
5130reversed. That is, the <tt>0</tt>th bit in <tt>%repl</tt> replaces the
5131<tt>%hi</tt> bit in <tt>%val</tt> and etc. down to the <tt>%lo</tt>th bit.
Reid Spencer5bf54c82007-04-11 23:23:49 +00005132<h5>Examples:</h5>
5133<pre>
Reid Spencerc70afc32007-04-12 01:03:03 +00005134 llvm.part.set(0xFFFF, 0, 4, 7) -&gt; 0xFF0F
Reid Spencer146281c2007-05-14 16:50:20 +00005135 llvm.part.set(0xFFFF, 0, 7, 4) -&gt; 0xFF0F
5136 llvm.part.set(0xFFFF, 1, 7, 4) -&gt; 0xFF8F
5137 llvm.part.set(0xFFFF, F, 8, 3) -&gt; 0xFFE7
Reid Spencerc70afc32007-04-12 01:03:03 +00005138 llvm.part.set(0xFFFF, 0, 3, 8) -&gt; 0xFE07
Reid Spencer7972c472007-04-11 23:49:50 +00005139</pre>
Reid Spencer5bf54c82007-04-11 23:23:49 +00005140</div>
5141
Chris Lattner941515c2004-01-06 05:31:32 +00005142<!-- ======================================================================= -->
5143<div class="doc_subsection">
5144 <a name="int_debugger">Debugger Intrinsics</a>
5145</div>
5146
5147<div class="doc_text">
5148<p>
5149The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
5150are described in the <a
5151href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
5152Debugging</a> document.
5153</p>
5154</div>
5155
5156
Jim Laskey2211f492007-03-14 19:31:19 +00005157<!-- ======================================================================= -->
5158<div class="doc_subsection">
5159 <a name="int_eh">Exception Handling Intrinsics</a>
5160</div>
5161
5162<div class="doc_text">
5163<p> The LLVM exception handling intrinsics (which all start with
5164<tt>llvm.eh.</tt> prefix), are described in the <a
5165href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
5166Handling</a> document. </p>
5167</div>
5168
Tanya Lattnercb1b9602007-06-15 20:50:54 +00005169<!-- ======================================================================= -->
5170<div class="doc_subsection">
Duncan Sands86e01192007-09-11 14:10:23 +00005171 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands644f9172007-07-27 12:58:54 +00005172</div>
5173
5174<div class="doc_text">
5175<p>
Duncan Sands86e01192007-09-11 14:10:23 +00005176 This intrinsic makes it possible to excise one parameter, marked with
Duncan Sands644f9172007-07-27 12:58:54 +00005177 the <tt>nest</tt> attribute, from a function. The result is a callable
5178 function pointer lacking the nest parameter - the caller does not need
5179 to provide a value for it. Instead, the value to use is stored in
5180 advance in a "trampoline", a block of memory usually allocated
5181 on the stack, which also contains code to splice the nest value into the
5182 argument list. This is used to implement the GCC nested function address
5183 extension.
5184</p>
5185<p>
5186 For example, if the function is
5187 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
Bill Wendling252570f2007-09-22 09:23:55 +00005188 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as follows:</p>
Duncan Sands644f9172007-07-27 12:58:54 +00005189<pre>
Duncan Sands86e01192007-09-11 14:10:23 +00005190 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
5191 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
5192 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
5193 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands644f9172007-07-27 12:58:54 +00005194</pre>
Bill Wendling252570f2007-09-22 09:23:55 +00005195 <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
5196 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
Duncan Sands644f9172007-07-27 12:58:54 +00005197</div>
5198
5199<!-- _______________________________________________________________________ -->
5200<div class="doc_subsubsection">
5201 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
5202</div>
5203<div class="doc_text">
5204<h5>Syntax:</h5>
5205<pre>
Duncan Sands86e01192007-09-11 14:10:23 +00005206declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands644f9172007-07-27 12:58:54 +00005207</pre>
5208<h5>Overview:</h5>
5209<p>
Duncan Sands86e01192007-09-11 14:10:23 +00005210 This fills the memory pointed to by <tt>tramp</tt> with code
5211 and returns a function pointer suitable for executing it.
Duncan Sands644f9172007-07-27 12:58:54 +00005212</p>
5213<h5>Arguments:</h5>
5214<p>
5215 The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
5216 pointers. The <tt>tramp</tt> argument must point to a sufficiently large
5217 and sufficiently aligned block of memory; this memory is written to by the
Duncan Sandsf2bcd372007-08-22 23:39:54 +00005218 intrinsic. Note that the size and the alignment are target-specific - LLVM
5219 currently provides no portable way of determining them, so a front-end that
5220 generates this intrinsic needs to have some target-specific knowledge.
5221 The <tt>func</tt> argument must hold a function bitcast to an <tt>i8*</tt>.
Duncan Sands644f9172007-07-27 12:58:54 +00005222</p>
5223<h5>Semantics:</h5>
5224<p>
5225 The block of memory pointed to by <tt>tramp</tt> is filled with target
Duncan Sands86e01192007-09-11 14:10:23 +00005226 dependent code, turning it into a function. A pointer to this function is
5227 returned, but needs to be bitcast to an
Duncan Sands644f9172007-07-27 12:58:54 +00005228 <a href="#int_trampoline">appropriate function pointer type</a>
Duncan Sands86e01192007-09-11 14:10:23 +00005229 before being called. The new function's signature is the same as that of
5230 <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute
5231 removed. At most one such <tt>nest</tt> argument is allowed, and it must be
5232 of pointer type. Calling the new function is equivalent to calling
5233 <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the
5234 missing <tt>nest</tt> argument. If, after calling
5235 <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is
5236 modified, then the effect of any later call to the returned function pointer is
5237 undefined.
Duncan Sands644f9172007-07-27 12:58:54 +00005238</p>
5239</div>
5240
5241<!-- ======================================================================= -->
5242<div class="doc_subsection">
Andrew Lenharth9b254ee2008-02-16 01:24:58 +00005243 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
5244</div>
5245
5246<div class="doc_text">
5247<p>
5248 These intrinsic functions expand the "universal IR" of LLVM to represent
5249 hardware constructs for atomic operations and memory synchronization. This
5250 provides an interface to the hardware, not an interface to the programmer. It
5251 is aimed at a low enough level to allow any programming models or APIs which
5252 need atomic behaviors to map cleanly onto it. It is also modeled primarily on
5253 hardware behavior. Just as hardware provides a "universal IR" for source
5254 languages, it also provides a starting point for developing a "universal"
5255 atomic operation and synchronization IR.
5256</p>
5257<p>
5258 These do <em>not</em> form an API such as high-level threading libraries,
5259 software transaction memory systems, atomic primitives, and intrinsic
5260 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
5261 application libraries. The hardware interface provided by LLVM should allow
5262 a clean implementation of all of these APIs and parallel programming models.
5263 No one model or paradigm should be selected above others unless the hardware
5264 itself ubiquitously does so.
5265
5266</p>
5267</div>
5268
5269<!-- _______________________________________________________________________ -->
5270<div class="doc_subsubsection">
5271 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
5272</div>
5273<div class="doc_text">
5274<h5>Syntax:</h5>
5275<pre>
5276declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;,
5277i1 &lt;device&gt; )
5278
5279</pre>
5280<h5>Overview:</h5>
5281<p>
5282 The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
5283 specific pairs of memory access types.
5284</p>
5285<h5>Arguments:</h5>
5286<p>
5287 The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
5288 The first four arguments enables a specific barrier as listed below. The fith
5289 argument specifies that the barrier applies to io or device or uncached memory.
5290
5291</p>
5292 <ul>
5293 <li><tt>ll</tt>: load-load barrier</li>
5294 <li><tt>ls</tt>: load-store barrier</li>
5295 <li><tt>sl</tt>: store-load barrier</li>
5296 <li><tt>ss</tt>: store-store barrier</li>
5297 <li><tt>device</tt>: barrier applies to device and uncached memory also.
5298 </ul>
5299<h5>Semantics:</h5>
5300<p>
5301 This intrinsic causes the system to enforce some ordering constraints upon
5302 the loads and stores of the program. This barrier does not indicate
5303 <em>when</em> any events will occur, it only enforces an <em>order</em> in
5304 which they occur. For any of the specified pairs of load and store operations
5305 (f.ex. load-load, or store-load), all of the first operations preceding the
5306 barrier will complete before any of the second operations succeeding the
5307 barrier begin. Specifically the semantics for each pairing is as follows:
5308</p>
5309 <ul>
5310 <li><tt>ll</tt>: All loads before the barrier must complete before any load
5311 after the barrier begins.</li>
5312
5313 <li><tt>ls</tt>: All loads before the barrier must complete before any
5314 store after the barrier begins.</li>
5315 <li><tt>ss</tt>: All stores before the barrier must complete before any
5316 store after the barrier begins.</li>
5317 <li><tt>sl</tt>: All stores before the barrier must complete before any
5318 load after the barrier begins.</li>
5319 </ul>
5320<p>
5321 These semantics are applied with a logical "and" behavior when more than one
5322 is enabled in a single memory barrier intrinsic.
5323</p>
5324<p>
5325 Backends may implement stronger barriers than those requested when they do not
5326 support as fine grained a barrier as requested. Some architectures do not
5327 need all types of barriers and on such architectures, these become noops.
5328</p>
5329<h5>Example:</h5>
5330<pre>
5331%ptr = malloc i32
5332 store i32 4, %ptr
5333
5334%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
5335 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
5336 <i>; guarantee the above finishes</i>
5337 store i32 8, %ptr <i>; before this begins</i>
5338</pre>
5339</div>
5340
5341
5342<!-- ======================================================================= -->
5343<div class="doc_subsection">
Tanya Lattnercb1b9602007-06-15 20:50:54 +00005344 <a name="int_general">General Intrinsics</a>
5345</div>
5346
5347<div class="doc_text">
5348<p> This class of intrinsics is designed to be generic and has
5349no specific purpose. </p>
5350</div>
5351
5352<!-- _______________________________________________________________________ -->
5353<div class="doc_subsubsection">
5354 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
5355</div>
5356
5357<div class="doc_text">
5358
5359<h5>Syntax:</h5>
5360<pre>
Tanya Lattnerbed1d4d2007-06-18 23:42:37 +00005361 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 +00005362</pre>
5363
5364<h5>Overview:</h5>
5365
5366<p>
5367The '<tt>llvm.var.annotation</tt>' intrinsic
5368</p>
5369
5370<h5>Arguments:</h5>
5371
5372<p>
Tanya Lattnerbed1d4d2007-06-18 23:42:37 +00005373The first argument is a pointer to a value, the second is a pointer to a
5374global string, the third is a pointer to a global string which is the source
5375file name, and the last argument is the line number.
Tanya Lattnercb1b9602007-06-15 20:50:54 +00005376</p>
5377
5378<h5>Semantics:</h5>
5379
5380<p>
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00005381This intrinsic allows annotation of local variables with arbitrary strings.
Tanya Lattnercb1b9602007-06-15 20:50:54 +00005382This can be useful for special purpose optimizations that want to look for these
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00005383annotations. These have no other defined use, they are ignored by code
5384generation and optimization.
5385</p>
Tanya Lattnercb1b9602007-06-15 20:50:54 +00005386</div>
5387
Tanya Lattner293c0372007-09-21 22:59:12 +00005388<!-- _______________________________________________________________________ -->
5389<div class="doc_subsubsection">
Tanya Lattner0186a652007-09-21 23:57:59 +00005390 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattner293c0372007-09-21 22:59:12 +00005391</div>
5392
5393<div class="doc_text">
5394
5395<h5>Syntax:</h5>
Tanya Lattner23dbd572007-09-21 23:56:27 +00005396<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
5397any integer bit width.
5398</p>
Tanya Lattner293c0372007-09-21 22:59:12 +00005399<pre>
Tanya Lattnercf3e26f2007-09-22 00:03:01 +00005400 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5401 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5402 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5403 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5404 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 +00005405</pre>
5406
5407<h5>Overview:</h5>
Tanya Lattner23dbd572007-09-21 23:56:27 +00005408
5409<p>
5410The '<tt>llvm.annotation</tt>' intrinsic.
Tanya Lattner293c0372007-09-21 22:59:12 +00005411</p>
5412
5413<h5>Arguments:</h5>
5414
5415<p>
5416The first argument is an integer value (result of some expression),
5417the second is a pointer to a global string, the third is a pointer to a global
5418string which is the source file name, and the last argument is the line number.
Tanya Lattner23dbd572007-09-21 23:56:27 +00005419It returns the value of the first argument.
Tanya Lattner293c0372007-09-21 22:59:12 +00005420</p>
5421
5422<h5>Semantics:</h5>
5423
5424<p>
5425This intrinsic allows annotations to be put on arbitrary expressions
5426with arbitrary strings. This can be useful for special purpose optimizations
5427that want to look for these annotations. These have no other defined use, they
5428are ignored by code generation and optimization.
5429</div>
Jim Laskey2211f492007-03-14 19:31:19 +00005430
Anton Korobeynikov06cbb652008-01-15 22:31:34 +00005431<!-- _______________________________________________________________________ -->
5432<div class="doc_subsubsection">
5433 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
5434</div>
5435
5436<div class="doc_text">
5437
5438<h5>Syntax:</h5>
5439<pre>
5440 declare void @llvm.trap()
5441</pre>
5442
5443<h5>Overview:</h5>
5444
5445<p>
5446The '<tt>llvm.trap</tt>' intrinsic
5447</p>
5448
5449<h5>Arguments:</h5>
5450
5451<p>
5452None
5453</p>
5454
5455<h5>Semantics:</h5>
5456
5457<p>
5458This intrinsics is lowered to the target dependent trap instruction. If the
5459target does not have a trap instruction, this intrinsic will be lowered to the
5460call of the abort() function.
5461</p>
5462</div>
5463
Chris Lattner2f7c9632001-06-06 20:29:01 +00005464<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00005465<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00005466<address>
5467 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
5468 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
5469 <a href="http://validator.w3.org/check/referer"><img
Chris Lattnerb8f816e2008-01-04 04:33:49 +00005470 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
Misha Brukmanc501f552004-03-01 17:47:27 +00005471
5472 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00005473 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00005474 Last modified: $Date$
5475</address>
Chris Lattnerb8f816e2008-01-04 04:33:49 +00005476
Misha Brukman76307852003-11-08 01:05:38 +00005477</body>
5478</html>