blob: 79d6f8820c433b3cb4da88ec9d03395a4d7f9ecc [file] [log] [blame]
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman9d0919f2003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencer3921c742004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman9d0919f2003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattnerd7923912004-05-23 21:06:01 +000012
Misha Brukman9d0919f2003-11-08 01:05:38 +000013<body>
Chris Lattnerd7923912004-05-23 21:06:01 +000014
Chris Lattner261efe92003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner00950542001-06-06 20:29:01 +000016<ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnere5d947b2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
Anton Korobeynikovc6c98af2007-04-29 18:02:48 +000027 <li><a href="#aliasstructure">Aliases</a>
Reid Spencerca86e162006-12-31 07:07:53 +000028 <li><a href="#paramattrs">Parameter Attributes</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000029 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Reid Spencerde151942007-02-19 23:54:10 +000030 <li><a href="#datalayout">Data Layout</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000031 </ol>
32 </li>
Chris Lattner00950542001-06-06 20:29:01 +000033 <li><a href="#typesystem">Type System</a>
34 <ol>
Robert Bocchino7b81c752006-02-17 21:18:08 +000035 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner261efe92003-11-25 01:02:51 +000036 <ol>
Misha Brukman9d0919f2003-11-08 01:05:38 +000037 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000038 </ol>
39 </li>
Chris Lattner00950542001-06-06 20:29:01 +000040 <li><a href="#t_derived">Derived Types</a>
41 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000042 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000043 <li><a href="#t_function">Function Type</a></li>
44 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000045 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth75e10682006-12-08 17:13:00 +000046 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer485bad12007-02-15 03:07:05 +000047 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000048 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000049 </ol>
50 </li>
51 </ol>
52 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000053 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000054 <ol>
55 <li><a href="#simpleconstants">Simple Constants</a>
56 <li><a href="#aggregateconstants">Aggregate Constants</a>
57 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
58 <li><a href="#undefvalues">Undefined Values</a>
59 <li><a href="#constantexprs">Constant Expressions</a>
60 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000061 </li>
Chris Lattnere87d6532006-01-25 23:47:57 +000062 <li><a href="#othervalues">Other Values</a>
63 <ol>
64 <li><a href="#inlineasm">Inline Assembler Expressions</a>
65 </ol>
66 </li>
Chris Lattner00950542001-06-06 20:29:01 +000067 <li><a href="#instref">Instruction Reference</a>
68 <ol>
69 <li><a href="#terminators">Terminator Instructions</a>
70 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000071 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
72 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000073 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
74 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000075 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000076 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000077 </ol>
78 </li>
Chris Lattner00950542001-06-06 20:29:01 +000079 <li><a href="#binaryops">Binary Operations</a>
80 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000081 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
82 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
83 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer1628cec2006-10-26 06:15:43 +000084 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
85 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
86 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer0a783f72006-11-02 01:53:59 +000087 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
88 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
89 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000090 </ol>
91 </li>
Chris Lattner00950542001-06-06 20:29:01 +000092 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
93 <ol>
Reid Spencer8e11bf82007-02-02 13:57:07 +000094 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
95 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
96 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000097 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000098 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000099 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000100 </ol>
101 </li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000102 <li><a href="#vectorops">Vector Operations</a>
103 <ol>
104 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
105 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
106 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000107 </ol>
108 </li>
Chris Lattner884a9702006-08-15 00:45:58 +0000109 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner00950542001-06-06 20:29:01 +0000110 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000111 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
112 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
113 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +0000114 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
115 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
116 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000117 </ol>
118 </li>
Reid Spencer2fd21e62006-11-08 01:18:52 +0000119 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000120 <ol>
121 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
122 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
123 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
124 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
125 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencerd4448792006-11-09 23:03:26 +0000126 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
127 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
128 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
129 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencer72679252006-11-11 21:00:47 +0000130 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
131 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5c0ef472006-11-11 23:08:07 +0000132 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000133 </ol>
Chris Lattner00950542001-06-06 20:29:01 +0000134 <li><a href="#otherops">Other Operations</a>
135 <ol>
Reid Spencerf3a70a62006-11-18 21:50:54 +0000136 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
137 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000138 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000139 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000140 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattnerfb6977d2006-01-13 23:26:01 +0000141 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000142 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000143 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000144 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000145 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000146 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000147 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000148 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
149 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000150 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
151 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
152 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000153 </ol>
154 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000155 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
156 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000157 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
158 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
159 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000160 </ol>
161 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000162 <li><a href="#int_codegen">Code Generator Intrinsics</a>
163 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000164 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
165 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
166 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
167 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
168 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
169 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
170 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000171 </ol>
172 </li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000173 <li><a href="#int_libc">Standard C Library Intrinsics</a>
174 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000175 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
176 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
177 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
178 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
179 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000180 </ol>
181 </li>
Nate Begeman7e36c472006-01-13 23:26:38 +0000182 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000183 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000184 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattner8a886be2006-01-16 22:34:14 +0000185 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
186 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
187 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Reid Spencerf86037f2007-04-11 23:23:49 +0000188 <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li>
189 <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000190 </ol>
191 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000192 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskeydd4ef1b2007-03-14 19:31:19 +0000193 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Chandler Carruth2eb93b32007-07-20 19:34:37 +0000194 <li><a href="#int_atomics">Atomic Operations and Synchronization Intrinsics</a>
195 <ol>
196 <li><a href="#int_lcs">'<tt>llvm.atomic.lcs.*</tt>' Intrinsic</a></li>
197 <li><a href="#int_ls">'<tt>llvm.atomic.ls.*</tt>' Intrinsic</a></li>
198 <li><a href="#int_las">'<tt>llvm.atomic.las.*</tt>' Intrinsic</a></li>
199 <li><a href="#int_lss">'<tt>llvm.atomic.lss.*</tt>' Intrinsic</a></li>
200 <li><a href="#int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a></li>
201 </ol>
202 </li>
Duncan Sands36397f52007-07-27 12:58:54 +0000203 <li><a href="#int_trampoline">Trampoline Intrinsics</a>
204 <ol>
205 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
206 <li><a href="#int_at">'<tt>llvm.adjust.trampoline</tt>' Intrinsic</a></li>
207 </ol>
208 </li>
Reid Spencer20677642007-07-20 19:59:11 +0000209 <li><a href="#int_general">General intrinsics</a>
Tanya Lattner6d806e92007-06-15 20:50:54 +0000210 <ol>
Reid Spencer20677642007-07-20 19:59:11 +0000211 <li><a href="#int_var_annotation">
212 <tt>llvm.var.annotation</tt>' Intrinsic</a></li>
213 </ol>
Tanya Lattner6d806e92007-06-15 20:50:54 +0000214 </li>
Chris Lattner261efe92003-11-25 01:02:51 +0000215 </ol>
216 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000217</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000218
219<div class="doc_author">
220 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
221 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000222</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000223
Chris Lattner00950542001-06-06 20:29:01 +0000224<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000225<div class="doc_section"> <a name="abstract">Abstract </a></div>
226<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000227
Misha Brukman9d0919f2003-11-08 01:05:38 +0000228<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000229<p>This document is a reference manual for the LLVM assembly language.
230LLVM is an SSA based representation that provides type safety,
231low-level operations, flexibility, and the capability of representing
232'all' high-level languages cleanly. It is the common code
233representation used throughout all phases of the LLVM compilation
234strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000235</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000236
Chris Lattner00950542001-06-06 20:29:01 +0000237<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000238<div class="doc_section"> <a name="introduction">Introduction</a> </div>
239<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000240
Misha Brukman9d0919f2003-11-08 01:05:38 +0000241<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000242
Chris Lattner261efe92003-11-25 01:02:51 +0000243<p>The LLVM code representation is designed to be used in three
Gabor Greif04367bf2007-07-06 22:07:22 +0000244different forms: as an in-memory compiler IR, as an on-disk bitcode
Chris Lattner261efe92003-11-25 01:02:51 +0000245representation (suitable for fast loading by a Just-In-Time compiler),
246and as a human readable assembly language representation. This allows
247LLVM to provide a powerful intermediate representation for efficient
248compiler transformations and analysis, while providing a natural means
249to debug and visualize the transformations. The three different forms
250of LLVM are all equivalent. This document describes the human readable
251representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000252
John Criswellc1f786c2005-05-13 22:25:59 +0000253<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000254while being expressive, typed, and extensible at the same time. It
255aims to be a "universal IR" of sorts, by being at a low enough level
256that high-level ideas may be cleanly mapped to it (similar to how
257microprocessors are "universal IR's", allowing many source languages to
258be mapped to them). By providing type information, LLVM can be used as
259the target of optimizations: for example, through pointer analysis, it
260can be proven that a C automatic variable is never accessed outside of
261the current function... allowing it to be promoted to a simple SSA
262value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000263
Misha Brukman9d0919f2003-11-08 01:05:38 +0000264</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000265
Chris Lattner00950542001-06-06 20:29:01 +0000266<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000267<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000268
Misha Brukman9d0919f2003-11-08 01:05:38 +0000269<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000270
Chris Lattner261efe92003-11-25 01:02:51 +0000271<p>It is important to note that this document describes 'well formed'
272LLVM assembly language. There is a difference between what the parser
273accepts and what is considered 'well formed'. For example, the
274following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000275
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000276<div class="doc_code">
Chris Lattnerd7923912004-05-23 21:06:01 +0000277<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000278%x = <a href="#i_add">add</a> i32 1, %x
Chris Lattnerd7923912004-05-23 21:06:01 +0000279</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000280</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000281
Chris Lattner261efe92003-11-25 01:02:51 +0000282<p>...because the definition of <tt>%x</tt> does not dominate all of
283its uses. The LLVM infrastructure provides a verification pass that may
284be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000285automatically run by the parser after parsing input assembly and by
Gabor Greif04367bf2007-07-06 22:07:22 +0000286the optimizer before it outputs bitcode. The violations pointed out
Chris Lattner261efe92003-11-25 01:02:51 +0000287by the verifier pass indicate bugs in transformation passes or input to
288the parser.</p>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000289</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000290
Reid Spencer20677642007-07-20 19:59:11 +0000291<!-- Describe the typesetting conventions here. -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000292
Chris Lattner00950542001-06-06 20:29:01 +0000293<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000294<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000295<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000296
Misha Brukman9d0919f2003-11-08 01:05:38 +0000297<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000298
Chris Lattner261efe92003-11-25 01:02:51 +0000299<p>LLVM uses three different forms of identifiers, for different
300purposes:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000301
Chris Lattner00950542001-06-06 20:29:01 +0000302<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000303 <li>Named values are represented as a string of characters with a '%' prefix.
304 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
305 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
306 Identifiers which require other characters in their names can be surrounded
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000307 with quotes. In this way, anything except a <tt>&quot;</tt> character can be used
Chris Lattnere5d947b2004-12-09 16:36:40 +0000308 in a name.</li>
309
310 <li>Unnamed values are represented as an unsigned numeric value with a '%'
311 prefix. For example, %12, %2, %44.</li>
312
Reid Spencercc16dc32004-12-09 18:02:53 +0000313 <li>Constants, which are described in a <a href="#constants">section about
314 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000315</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000316
317<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
318don't need to worry about name clashes with reserved words, and the set of
319reserved words may be expanded in the future without penalty. Additionally,
320unnamed identifiers allow a compiler to quickly come up with a temporary
321variable without having to avoid symbol table conflicts.</p>
322
Chris Lattner261efe92003-11-25 01:02:51 +0000323<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5c0ef472006-11-11 23:08:07 +0000324languages. There are keywords for different opcodes
325('<tt><a href="#i_add">add</a></tt>',
326 '<tt><a href="#i_bitcast">bitcast</a></tt>',
327 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerca86e162006-12-31 07:07:53 +0000328href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnere5d947b2004-12-09 16:36:40 +0000329and others. These reserved words cannot conflict with variable names, because
330none of them start with a '%' character.</p>
331
332<p>Here is an example of LLVM code to multiply the integer variable
333'<tt>%X</tt>' by 8:</p>
334
Misha Brukman9d0919f2003-11-08 01:05:38 +0000335<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000336
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000337<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000338<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000339%result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnere5d947b2004-12-09 16:36:40 +0000340</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000341</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000342
Misha Brukman9d0919f2003-11-08 01:05:38 +0000343<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000344
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000345<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000346<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000347%result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnere5d947b2004-12-09 16:36:40 +0000348</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000349</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000350
Misha Brukman9d0919f2003-11-08 01:05:38 +0000351<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000352
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000353<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000354<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000355<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
356<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
357%result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnere5d947b2004-12-09 16:36:40 +0000358</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000359</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000360
Chris Lattner261efe92003-11-25 01:02:51 +0000361<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
362important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000363
Chris Lattner00950542001-06-06 20:29:01 +0000364<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000365
366 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
367 line.</li>
368
369 <li>Unnamed temporaries are created when the result of a computation is not
370 assigned to a named value.</li>
371
Misha Brukman9d0919f2003-11-08 01:05:38 +0000372 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000373
Misha Brukman9d0919f2003-11-08 01:05:38 +0000374</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000375
John Criswelle4c57cc2005-05-12 16:52:32 +0000376<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000377demonstrating instructions, we will follow an instruction with a comment that
378defines the type and name of value produced. Comments are shown in italic
379text.</p>
380
Misha Brukman9d0919f2003-11-08 01:05:38 +0000381</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000382
383<!-- *********************************************************************** -->
384<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
385<!-- *********************************************************************** -->
386
387<!-- ======================================================================= -->
388<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
389</div>
390
391<div class="doc_text">
392
393<p>LLVM programs are composed of "Module"s, each of which is a
394translation unit of the input programs. Each module consists of
395functions, global variables, and symbol table entries. Modules may be
396combined together with the LLVM linker, which merges function (and
397global variable) definitions, resolves forward declarations, and merges
398symbol table entries. Here is an example of the "hello world" module:</p>
399
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000400<div class="doc_code">
Chris Lattnerfa730212004-12-09 16:11:40 +0000401<pre><i>; Declare the string constant as a global constant...</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000402<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
403 href="#globalvars">constant</a> <a href="#t_array">[13 x i8]</a> c"hello world\0A\00" <i>; [13 x i8]*</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000404
405<i>; External declaration of the puts function</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000406<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000407
408<i>; Definition of main function</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000409define i32 @main() { <i>; i32()* </i>
Reid Spencerca86e162006-12-31 07:07:53 +0000410 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000411 %cast210 = <a
Chris Lattner6c0955b2007-06-12 17:01:15 +0000412 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000413
414 <i>; Call puts function to write out the string to stdout...</i>
415 <a
Chris Lattnera89e5f12007-06-12 17:00:26 +0000416 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000417 <a
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000418 href="#i_ret">ret</a> i32 0<br>}<br>
419</pre>
420</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000421
422<p>This example is made up of a <a href="#globalvars">global variable</a>
423named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
424function, and a <a href="#functionstructure">function definition</a>
425for "<tt>main</tt>".</p>
426
Chris Lattnere5d947b2004-12-09 16:36:40 +0000427<p>In general, a module is made up of a list of global values,
428where both functions and global variables are global values. Global values are
429represented by a pointer to a memory location (in this case, a pointer to an
430array of char, and a pointer to a function), and have one of the following <a
431href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000432
Chris Lattnere5d947b2004-12-09 16:36:40 +0000433</div>
434
435<!-- ======================================================================= -->
436<div class="doc_subsection">
437 <a name="linkage">Linkage Types</a>
438</div>
439
440<div class="doc_text">
441
442<p>
443All Global Variables and Functions have one of the following types of linkage:
444</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000445
446<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000447
Chris Lattnerfa730212004-12-09 16:11:40 +0000448 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000449
450 <dd>Global values with internal linkage are only directly accessible by
451 objects in the current module. In particular, linking code into a module with
452 an internal global value may cause the internal to be renamed as necessary to
453 avoid collisions. Because the symbol is internal to the module, all
454 references can be updated. This corresponds to the notion of the
Chris Lattner4887bd82007-01-14 06:51:48 +0000455 '<tt>static</tt>' keyword in C.
Chris Lattnerfa730212004-12-09 16:11:40 +0000456 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000457
Chris Lattnerfa730212004-12-09 16:11:40 +0000458 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000459
Chris Lattner4887bd82007-01-14 06:51:48 +0000460 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
461 the same name when linkage occurs. This is typically used to implement
462 inline functions, templates, or other code which must be generated in each
463 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
464 allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000465 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000466
Chris Lattnerfa730212004-12-09 16:11:40 +0000467 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000468
469 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
470 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattner4887bd82007-01-14 06:51:48 +0000471 used for globals that may be emitted in multiple translation units, but that
472 are not guaranteed to be emitted into every translation unit that uses them.
473 One example of this are common globals in C, such as "<tt>int X;</tt>" at
474 global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000475 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000476
Chris Lattnerfa730212004-12-09 16:11:40 +0000477 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000478
479 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
480 pointer to array type. When two global variables with appending linkage are
481 linked together, the two global arrays are appended together. This is the
482 LLVM, typesafe, equivalent of having the system linker append together
483 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000484 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000485
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000486 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
487 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
488 until linked, if not linked, the symbol becomes null instead of being an
489 undefined reference.
490 </dd>
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000491
Chris Lattnerfa730212004-12-09 16:11:40 +0000492 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000493
494 <dd>If none of the above identifiers are used, the global is externally
495 visible, meaning that it participates in linkage and can be used to resolve
496 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000497 </dd>
Reid Spencerc8910842007-04-11 23:49:50 +0000498</dl>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000499
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000500 <p>
501 The next two types of linkage are targeted for Microsoft Windows platform
502 only. They are designed to support importing (exporting) symbols from (to)
503 DLLs.
504 </p>
505
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000506 <dl>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000507 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
508
509 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
510 or variable via a global pointer to a pointer that is set up by the DLL
511 exporting the symbol. On Microsoft Windows targets, the pointer name is
512 formed by combining <code>_imp__</code> and the function or variable name.
513 </dd>
514
515 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
516
517 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
518 pointer to a pointer in a DLL, so that it can be referenced with the
519 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
520 name is formed by combining <code>_imp__</code> and the function or variable
521 name.
522 </dd>
523
Chris Lattnerfa730212004-12-09 16:11:40 +0000524</dl>
525
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000526<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattnerfa730212004-12-09 16:11:40 +0000527variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
528variable and was linked with this one, one of the two would be renamed,
529preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
530external (i.e., lacking any linkage declarations), they are accessible
Reid Spencerac8d2762007-01-05 00:59:10 +0000531outside of the current module.</p>
532<p>It is illegal for a function <i>declaration</i>
533to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000534or <tt>extern_weak</tt>.</p>
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000535<p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt>
536linkages.
Chris Lattnerfa730212004-12-09 16:11:40 +0000537</div>
538
539<!-- ======================================================================= -->
540<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000541 <a name="callingconv">Calling Conventions</a>
542</div>
543
544<div class="doc_text">
545
546<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
547and <a href="#i_invoke">invokes</a> can all have an optional calling convention
548specified for the call. The calling convention of any pair of dynamic
549caller/callee must match, or the behavior of the program is undefined. The
550following calling conventions are supported by LLVM, and more may be added in
551the future:</p>
552
553<dl>
554 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
555
556 <dd>This calling convention (the default if no other calling convention is
557 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000558 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencerc28d2bc2006-12-31 21:30:18 +0000559 prototype and implemented declaration of the function (as does normal C).
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000560 </dd>
561
562 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
563
564 <dd>This calling convention attempts to make calls as fast as possible
565 (e.g. by passing things in registers). This calling convention allows the
566 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000567 without having to conform to an externally specified ABI. Implementations of
568 this convention should allow arbitrary tail call optimization to be supported.
569 This calling convention does not support varargs and requires the prototype of
570 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000571 </dd>
572
573 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
574
575 <dd>This calling convention attempts to make code in the caller as efficient
576 as possible under the assumption that the call is not commonly executed. As
577 such, these calls often preserve all registers so that the call does not break
578 any live ranges in the caller side. This calling convention does not support
579 varargs and requires the prototype of all callees to exactly match the
580 prototype of the function definition.
581 </dd>
582
Chris Lattnercfe6b372005-05-07 01:46:40 +0000583 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000584
585 <dd>Any calling convention may be specified by number, allowing
586 target-specific calling conventions to be used. Target specific calling
587 conventions start at 64.
588 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000589</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000590
591<p>More calling conventions can be added/defined on an as-needed basis, to
592support pascal conventions or any other well-known target-independent
593convention.</p>
594
595</div>
596
597<!-- ======================================================================= -->
598<div class="doc_subsection">
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000599 <a name="visibility">Visibility Styles</a>
600</div>
601
602<div class="doc_text">
603
604<p>
605All Global Variables and Functions have one of the following visibility styles:
606</p>
607
608<dl>
609 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
610
611 <dd>On ELF, default visibility means that the declaration is visible to other
612 modules and, in shared libraries, means that the declared entity may be
613 overridden. On Darwin, default visibility means that the declaration is
614 visible to other modules. Default visibility corresponds to "external
615 linkage" in the language.
616 </dd>
617
618 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
619
620 <dd>Two declarations of an object with hidden visibility refer to the same
621 object if they are in the same shared object. Usually, hidden visibility
622 indicates that the symbol will not be placed into the dynamic symbol table,
623 so no other module (executable or shared library) can reference it
624 directly.
625 </dd>
626
Anton Korobeynikov6f9896f2007-04-29 18:35:00 +0000627 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
628
629 <dd>On ELF, protected visibility indicates that the symbol will be placed in
630 the dynamic symbol table, but that references within the defining module will
631 bind to the local symbol. That is, the symbol cannot be overridden by another
632 module.
633 </dd>
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000634</dl>
635
636</div>
637
638<!-- ======================================================================= -->
639<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000640 <a name="globalvars">Global Variables</a>
641</div>
642
643<div class="doc_text">
644
Chris Lattner3689a342005-02-12 19:30:21 +0000645<p>Global variables define regions of memory allocated at compilation time
Chris Lattner88f6c462005-11-12 00:45:07 +0000646instead of run-time. Global variables may optionally be initialized, may have
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000647an explicit section to be placed in, and may have an optional explicit alignment
648specified. A variable may be defined as "thread_local", which means that it
649will not be shared by threads (each thread will have a separated copy of the
650variable). A variable may be defined as a global "constant," which indicates
651that the contents of the variable will <b>never</b> be modified (enabling better
Chris Lattner3689a342005-02-12 19:30:21 +0000652optimization, allowing the global data to be placed in the read-only section of
653an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000654cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000655
656<p>
657LLVM explicitly allows <em>declarations</em> of global variables to be marked
658constant, even if the final definition of the global is not. This capability
659can be used to enable slightly better optimization of the program, but requires
660the language definition to guarantee that optimizations based on the
661'constantness' are valid for the translation units that do not include the
662definition.
663</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000664
665<p>As SSA values, global variables define pointer values that are in
666scope (i.e. they dominate) all basic blocks in the program. Global
667variables always define a pointer to their "content" type because they
668describe a region of memory, and all memory objects in LLVM are
669accessed through pointers.</p>
670
Chris Lattner88f6c462005-11-12 00:45:07 +0000671<p>LLVM allows an explicit section to be specified for globals. If the target
672supports it, it will emit globals to the section specified.</p>
673
Chris Lattner2cbdc452005-11-06 08:02:57 +0000674<p>An explicit alignment may be specified for a global. If not present, or if
675the alignment is set to zero, the alignment of the global is set by the target
676to whatever it feels convenient. If an explicit alignment is specified, the
677global is forced to have at least that much alignment. All alignments must be
678a power of 2.</p>
679
Chris Lattner68027ea2007-01-14 00:27:09 +0000680<p>For example, the following defines a global with an initializer, section,
681 and alignment:</p>
682
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000683<div class="doc_code">
Chris Lattner68027ea2007-01-14 00:27:09 +0000684<pre>
Chris Lattner3e63a9d2007-07-13 20:01:46 +0000685@G = constant float 1.0, section "foo", align 4
Chris Lattner68027ea2007-01-14 00:27:09 +0000686</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000687</div>
Chris Lattner68027ea2007-01-14 00:27:09 +0000688
Chris Lattnerfa730212004-12-09 16:11:40 +0000689</div>
690
691
692<!-- ======================================================================= -->
693<div class="doc_subsection">
694 <a name="functionstructure">Functions</a>
695</div>
696
697<div class="doc_text">
698
Reid Spencerca86e162006-12-31 07:07:53 +0000699<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
700an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000701<a href="#visibility">visibility style</a>, an optional
Reid Spencerca86e162006-12-31 07:07:53 +0000702<a href="#callingconv">calling convention</a>, a return type, an optional
703<a href="#paramattrs">parameter attribute</a> for the return type, a function
704name, a (possibly empty) argument list (each with optional
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000705<a href="#paramattrs">parameter attributes</a>), an optional section, an
706optional alignment, an opening curly brace, a list of basic blocks, and a
707closing curly brace.
708
709LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
710optional <a href="#linkage">linkage type</a>, an optional
711<a href="#visibility">visibility style</a>, an optional
712<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerca86e162006-12-31 07:07:53 +0000713<a href="#paramattrs">parameter attribute</a> for the return type, a function
714name, a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000715
716<p>A function definition contains a list of basic blocks, forming the CFG for
717the function. Each basic block may optionally start with a label (giving the
718basic block a symbol table entry), contains a list of instructions, and ends
719with a <a href="#terminators">terminator</a> instruction (such as a branch or
720function return).</p>
721
Chris Lattner4a3c9012007-06-08 16:52:14 +0000722<p>The first basic block in a function is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000723executed on entrance to the function, and it is not allowed to have predecessor
724basic blocks (i.e. there can not be any branches to the entry block of a
725function). Because the block can have no predecessors, it also cannot have any
726<a href="#i_phi">PHI nodes</a>.</p>
727
Chris Lattner88f6c462005-11-12 00:45:07 +0000728<p>LLVM allows an explicit section to be specified for functions. If the target
729supports it, it will emit functions to the section specified.</p>
730
Chris Lattner2cbdc452005-11-06 08:02:57 +0000731<p>An explicit alignment may be specified for a function. If not present, or if
732the alignment is set to zero, the alignment of the function is set by the target
733to whatever it feels convenient. If an explicit alignment is specified, the
734function is forced to have at least that much alignment. All alignments must be
735a power of 2.</p>
736
Chris Lattnerfa730212004-12-09 16:11:40 +0000737</div>
738
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000739
740<!-- ======================================================================= -->
741<div class="doc_subsection">
742 <a name="aliasstructure">Aliases</a>
743</div>
744<div class="doc_text">
745 <p>Aliases act as "second name" for the aliasee value (which can be either
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000746 function or global variable or bitcast of global value). Aliases may have an
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000747 optional <a href="#linkage">linkage type</a>, and an
748 optional <a href="#visibility">visibility style</a>.</p>
749
750 <h5>Syntax:</h5>
751
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000752<div class="doc_code">
Bill Wendlingaac388b2007-05-29 09:42:13 +0000753<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000754@&lt;Name&gt; = [Linkage] [Visibility] alias &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Bill Wendlingaac388b2007-05-29 09:42:13 +0000755</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000756</div>
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000757
758</div>
759
760
761
Chris Lattner4e9aba72006-01-23 23:23:47 +0000762<!-- ======================================================================= -->
Reid Spencerca86e162006-12-31 07:07:53 +0000763<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
764<div class="doc_text">
765 <p>The return type and each parameter of a function type may have a set of
766 <i>parameter attributes</i> associated with them. Parameter attributes are
767 used to communicate additional information about the result or parameters of
768 a function. Parameter attributes are considered to be part of the function
769 type so two functions types that differ only by the parameter attributes
770 are different function types.</p>
771
Reid Spencer950e9f82007-01-15 18:27:39 +0000772 <p>Parameter attributes are simple keywords that follow the type specified. If
773 multiple parameter attributes are needed, they are space separated. For
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000774 example:</p>
775
776<div class="doc_code">
777<pre>
Reid Spencer9445e9a2007-07-19 23:13:04 +0000778%someFunc = i16 (i8 signext %someParam) zeroext
779%someFunc = i16 (i8 zeroext %someParam) zeroext
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000780</pre>
781</div>
782
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000783 <p>Note that the two function types above are unique because the parameter has
Reid Spencer9445e9a2007-07-19 23:13:04 +0000784 a different attribute (<tt>signext</tt> in the first one, <tt>zeroext</tt> in
785 the second). Also note that the attribute for the function result
786 (<tt>zeroext</tt>) comes immediately after the argument list.</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000787
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000788 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000789 <dl>
Reid Spencer9445e9a2007-07-19 23:13:04 +0000790 <dt><tt>zeroext</tt></dt>
Reid Spencerca86e162006-12-31 07:07:53 +0000791 <dd>This indicates that the parameter should be zero extended just before
792 a call to this function.</dd>
Reid Spencer9445e9a2007-07-19 23:13:04 +0000793 <dt><tt>signext</tt></dt>
Reid Spencerca86e162006-12-31 07:07:53 +0000794 <dd>This indicates that the parameter should be sign extended just before
795 a call to this function.</dd>
Anton Korobeynikov34d6dea2007-01-28 14:30:45 +0000796 <dt><tt>inreg</tt></dt>
797 <dd>This indicates that the parameter should be placed in register (if
Anton Korobeynikov66a8c8c2007-01-28 15:27:21 +0000798 possible) during assembling function call. Support for this attribute is
799 target-specific</dd>
Anton Korobeynikov34d6dea2007-01-28 14:30:45 +0000800 <dt><tt>sret</tt></dt>
Anton Korobeynikov66a8c8c2007-01-28 15:27:21 +0000801 <dd>This indicates that the parameter specifies the address of a structure
Reid Spencer67606122007-03-22 02:02:11 +0000802 that is the return value of the function in the source program.</dd>
Zhou Shengfebca342007-06-05 05:28:26 +0000803 <dt><tt>noalias</tt></dt>
804 <dd>This indicates that the parameter not alias any other object or any
805 other "noalias" objects during the function call.
Reid Spencer2dc52012007-03-22 02:18:56 +0000806 <dt><tt>noreturn</tt></dt>
807 <dd>This function attribute indicates that the function never returns. This
808 indicates to LLVM that every call to this function should be treated as if
809 an <tt>unreachable</tt> instruction immediately followed the call.</dd>
Reid Spencer67606122007-03-22 02:02:11 +0000810 <dt><tt>nounwind</tt></dt>
811 <dd>This function attribute indicates that the function type does not use
812 the unwind instruction and does not allow stack unwinding to propagate
813 through it.</dd>
Duncan Sands50f19f52007-07-27 19:57:41 +0000814 <dt><tt>nest</tt></dt>
815 <dd>This indicates that the parameter can be excised using the
816 <a href="#int_trampoline">trampoline intrinsics</a>.</dd>
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000817 </dl>
Reid Spencerca86e162006-12-31 07:07:53 +0000818
Reid Spencerca86e162006-12-31 07:07:53 +0000819</div>
820
821<!-- ======================================================================= -->
Chris Lattner4e9aba72006-01-23 23:23:47 +0000822<div class="doc_subsection">
Chris Lattner1eeeb0c2006-04-08 04:40:53 +0000823 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner4e9aba72006-01-23 23:23:47 +0000824</div>
825
826<div class="doc_text">
827<p>
828Modules may contain "module-level inline asm" blocks, which corresponds to the
829GCC "file scope inline asm" blocks. These blocks are internally concatenated by
830LLVM and treated as a single unit, but may be separated in the .ll file if
831desired. The syntax is very simple:
832</p>
833
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000834<div class="doc_code">
835<pre>
836module asm "inline asm code goes here"
837module asm "more can go here"
838</pre>
839</div>
Chris Lattner4e9aba72006-01-23 23:23:47 +0000840
841<p>The strings can contain any character by escaping non-printable characters.
842 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
843 for the number.
844</p>
845
846<p>
847 The inline asm code is simply printed to the machine code .s file when
848 assembly code is generated.
849</p>
850</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000851
Reid Spencerde151942007-02-19 23:54:10 +0000852<!-- ======================================================================= -->
853<div class="doc_subsection">
854 <a name="datalayout">Data Layout</a>
855</div>
856
857<div class="doc_text">
858<p>A module may specify a target specific data layout string that specifies how
Reid Spencerc8910842007-04-11 23:49:50 +0000859data is to be laid out in memory. The syntax for the data layout is simply:</p>
860<pre> target datalayout = "<i>layout specification</i>"</pre>
861<p>The <i>layout specification</i> consists of a list of specifications
862separated by the minus sign character ('-'). Each specification starts with a
863letter and may include other information after the letter to define some
864aspect of the data layout. The specifications accepted are as follows: </p>
Reid Spencerde151942007-02-19 23:54:10 +0000865<dl>
866 <dt><tt>E</tt></dt>
867 <dd>Specifies that the target lays out data in big-endian form. That is, the
868 bits with the most significance have the lowest address location.</dd>
869 <dt><tt>e</tt></dt>
870 <dd>Specifies that hte target lays out data in little-endian form. That is,
871 the bits with the least significance have the lowest address location.</dd>
872 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
873 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
874 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
875 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
876 too.</dd>
877 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
878 <dd>This specifies the alignment for an integer type of a given bit
879 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
880 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
881 <dd>This specifies the alignment for a vector type of a given bit
882 <i>size</i>.</dd>
883 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
884 <dd>This specifies the alignment for a floating point type of a given bit
885 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
886 (double).</dd>
887 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
888 <dd>This specifies the alignment for an aggregate type of a given bit
889 <i>size</i>.</dd>
890</dl>
891<p>When constructing the data layout for a given target, LLVM starts with a
892default set of specifications which are then (possibly) overriden by the
893specifications in the <tt>datalayout</tt> keyword. The default specifications
894are given in this list:</p>
895<ul>
896 <li><tt>E</tt> - big endian</li>
897 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
898 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
899 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
900 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
901 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
902 <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred
903 alignment of 64-bits</li>
904 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
905 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
906 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
907 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
908 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
909</ul>
910<p>When llvm is determining the alignment for a given type, it uses the
911following rules:
912<ol>
913 <li>If the type sought is an exact match for one of the specifications, that
914 specification is used.</li>
915 <li>If no match is found, and the type sought is an integer type, then the
916 smallest integer type that is larger than the bitwidth of the sought type is
917 used. If none of the specifications are larger than the bitwidth then the the
918 largest integer type is used. For example, given the default specifications
919 above, the i7 type will use the alignment of i8 (next largest) while both
920 i65 and i256 will use the alignment of i64 (largest specified).</li>
921 <li>If no match is found, and the type sought is a vector type, then the
922 largest vector type that is smaller than the sought vector type will be used
923 as a fall back. This happens because <128 x double> can be implemented in
924 terms of 64 <2 x double>, for example.</li>
925</ol>
926</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000927
Chris Lattner00950542001-06-06 20:29:01 +0000928<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000929<div class="doc_section"> <a name="typesystem">Type System</a> </div>
930<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000931
Misha Brukman9d0919f2003-11-08 01:05:38 +0000932<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000933
Misha Brukman9d0919f2003-11-08 01:05:38 +0000934<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +0000935intermediate representation. Being typed enables a number of
936optimizations to be performed on the IR directly, without having to do
937extra analyses on the side before the transformation. A strong type
938system makes it easier to read the generated code and enables novel
939analyses and transformations that are not feasible to perform on normal
940three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000941
942</div>
943
Chris Lattner00950542001-06-06 20:29:01 +0000944<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +0000945<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000946<div class="doc_text">
John Criswell4457dc92004-04-09 16:48:45 +0000947<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattnerd4f6b172005-03-07 22:13:59 +0000948system. The current set of primitive types is as follows:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000949
Reid Spencerd3f876c2004-11-01 08:19:36 +0000950<table class="layout">
951 <tr class="layout">
952 <td class="left">
953 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000954 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000955 <tr><th>Type</th><th>Description</th></tr>
Duncan Sands8036ca42007-03-30 12:22:09 +0000956 <tr><td><tt><a name="t_void">void</a></tt></td><td>No value</td></tr>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000957 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000958 </tbody>
959 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000960 </td>
961 <td class="right">
962 <table>
Chris Lattner261efe92003-11-25 01:02:51 +0000963 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000964 <tr><th>Type</th><th>Description</th></tr>
Reid Spencer2b916312007-05-16 18:44:01 +0000965 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerca86e162006-12-31 07:07:53 +0000966 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000967 </tbody>
968 </table>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000969 </td>
970 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000971</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000972</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000973
Chris Lattner00950542001-06-06 20:29:01 +0000974<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000975<div class="doc_subsubsection"> <a name="t_classifications">Type
976Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000977<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000978<p>These different primitive types fall into a few useful
979classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +0000980
981<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +0000982 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +0000983 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000984 <tr>
Chris Lattner261efe92003-11-25 01:02:51 +0000985 <td><a name="t_integer">integer</a></td>
Reid Spencer2b916312007-05-16 18:44:01 +0000986 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +0000987 </tr>
988 <tr>
989 <td><a name="t_floating">floating point</a></td>
990 <td><tt>float, double</tt></td>
991 </tr>
992 <tr>
993 <td><a name="t_firstclass">first class</a></td>
Reid Spencer2b916312007-05-16 18:44:01 +0000994 <td><tt>i1, ..., float, double, <br/>
Reid Spencer485bad12007-02-15 03:07:05 +0000995 <a href="#t_pointer">pointer</a>,<a href="#t_vector">vector</a></tt>
Reid Spencerca86e162006-12-31 07:07:53 +0000996 </td>
Chris Lattner261efe92003-11-25 01:02:51 +0000997 </tr>
998 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000999</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001000
Chris Lattner261efe92003-11-25 01:02:51 +00001001<p>The <a href="#t_firstclass">first class</a> types are perhaps the
1002most important. Values of these types are the only ones which can be
1003produced by instructions, passed as arguments, or used as operands to
1004instructions. This means that all structures and arrays must be
1005manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001006</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001007
Chris Lattner00950542001-06-06 20:29:01 +00001008<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001009<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001010
Misha Brukman9d0919f2003-11-08 01:05:38 +00001011<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001012
Chris Lattner261efe92003-11-25 01:02:51 +00001013<p>The real power in LLVM comes from the derived types in the system.
1014This is what allows a programmer to represent arrays, functions,
1015pointers, and other useful types. Note that these derived types may be
1016recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001017
Misha Brukman9d0919f2003-11-08 01:05:38 +00001018</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001019
Chris Lattner00950542001-06-06 20:29:01 +00001020<!-- _______________________________________________________________________ -->
Reid Spencer2b916312007-05-16 18:44:01 +00001021<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1022
1023<div class="doc_text">
1024
1025<h5>Overview:</h5>
1026<p>The integer type is a very simple derived type that simply specifies an
1027arbitrary bit width for the integer type desired. Any bit width from 1 bit to
10282^23-1 (about 8 million) can be specified.</p>
1029
1030<h5>Syntax:</h5>
1031
1032<pre>
1033 iN
1034</pre>
1035
1036<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1037value.</p>
1038
1039<h5>Examples:</h5>
1040<table class="layout">
1041 <tr class="layout">
1042 <td class="left">
1043 <tt>i1</tt><br/>
1044 <tt>i4</tt><br/>
1045 <tt>i8</tt><br/>
1046 <tt>i16</tt><br/>
1047 <tt>i32</tt><br/>
1048 <tt>i42</tt><br/>
1049 <tt>i64</tt><br/>
1050 <tt>i1942652</tt><br/>
1051 </td>
1052 <td class="left">
1053 A boolean integer of 1 bit<br/>
1054 A nibble sized integer of 4 bits.<br/>
1055 A byte sized integer of 8 bits.<br/>
1056 A half word sized integer of 16 bits.<br/>
1057 A word sized integer of 32 bits.<br/>
1058 An integer whose bit width is the answer. <br/>
1059 A double word sized integer of 64 bits.<br/>
1060 A really big integer of over 1 million bits.<br/>
1061 </td>
1062 </tr>
1063</table>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001064</div>
Reid Spencer2b916312007-05-16 18:44:01 +00001065
1066<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001067<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001068
Misha Brukman9d0919f2003-11-08 01:05:38 +00001069<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001070
Chris Lattner00950542001-06-06 20:29:01 +00001071<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001072
Misha Brukman9d0919f2003-11-08 01:05:38 +00001073<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +00001074sequentially in memory. The array type requires a size (number of
1075elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001076
Chris Lattner7faa8832002-04-14 06:13:44 +00001077<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001078
1079<pre>
1080 [&lt;# elements&gt; x &lt;elementtype&gt;]
1081</pre>
1082
John Criswelle4c57cc2005-05-12 16:52:32 +00001083<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +00001084be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001085
Chris Lattner7faa8832002-04-14 06:13:44 +00001086<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001087<table class="layout">
1088 <tr class="layout">
1089 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001090 <tt>[40 x i32 ]</tt><br/>
1091 <tt>[41 x i32 ]</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +00001092 <tt>[40 x i8]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001093 </td>
1094 <td class="left">
Reid Spencera5173382007-01-04 16:43:23 +00001095 Array of 40 32-bit integer values.<br/>
1096 Array of 41 32-bit integer values.<br/>
1097 Array of 40 8-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001098 </td>
1099 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001100</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001101<p>Here are some examples of multidimensional arrays:</p>
1102<table class="layout">
1103 <tr class="layout">
1104 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001105 <tt>[3 x [4 x i32]]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001106 <tt>[12 x [10 x float]]</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +00001107 <tt>[2 x [3 x [4 x i16]]]</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001108 </td>
1109 <td class="left">
Reid Spencera5173382007-01-04 16:43:23 +00001110 3x4 array of 32-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001111 12x10 array of single precision floating point values.<br/>
Reid Spencera5173382007-01-04 16:43:23 +00001112 2x3x4 array of 16-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001113 </td>
1114 </tr>
1115</table>
Chris Lattnere67a9512005-06-24 17:22:57 +00001116
John Criswell0ec250c2005-10-24 16:17:18 +00001117<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1118length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +00001119LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1120As a special case, however, zero length arrays are recognized to be variable
1121length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerca86e162006-12-31 07:07:53 +00001122type "{ i32, [0 x float]}", for example.</p>
Chris Lattnere67a9512005-06-24 17:22:57 +00001123
Misha Brukman9d0919f2003-11-08 01:05:38 +00001124</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001125
Chris Lattner00950542001-06-06 20:29:01 +00001126<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001127<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001128<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001129<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001130<p>The function type can be thought of as a function signature. It
1131consists of a return type and a list of formal parameter types.
John Criswell009900b2003-11-25 21:45:46 +00001132Function types are usually used to build virtual function tables
Chris Lattner261efe92003-11-25 01:02:51 +00001133(which are structures of pointers to functions), for indirect function
1134calls, and when defining a function.</p>
John Criswell009900b2003-11-25 21:45:46 +00001135<p>
1136The return type of a function type cannot be an aggregate type.
1137</p>
Chris Lattner00950542001-06-06 20:29:01 +00001138<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001139<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell0ec250c2005-10-24 16:17:18 +00001140<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +00001141specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +00001142which indicates that the function takes a variable number of arguments.
1143Variable argument functions can access their arguments with the <a
Chris Lattner261efe92003-11-25 01:02:51 +00001144 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001145<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001146<table class="layout">
1147 <tr class="layout">
Reid Spencer92f82302006-12-31 07:18:34 +00001148 <td class="left"><tt>i32 (i32)</tt></td>
1149 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001150 </td>
Reid Spencer92f82302006-12-31 07:18:34 +00001151 </tr><tr class="layout">
Reid Spencer9445e9a2007-07-19 23:13:04 +00001152 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencerf17a0b72006-12-31 07:20:23 +00001153 </tt></td>
Reid Spencer92f82302006-12-31 07:18:34 +00001154 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1155 an <tt>i16</tt> that should be sign extended and a
Reid Spencerca86e162006-12-31 07:07:53 +00001156 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer92f82302006-12-31 07:18:34 +00001157 <tt>float</tt>.
1158 </td>
1159 </tr><tr class="layout">
1160 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1161 <td class="left">A vararg function that takes at least one
Reid Spencera5173382007-01-04 16:43:23 +00001162 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer92f82302006-12-31 07:18:34 +00001163 which returns an integer. This is the signature for <tt>printf</tt> in
1164 LLVM.
Reid Spencerd3f876c2004-11-01 08:19:36 +00001165 </td>
1166 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001167</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001168
Misha Brukman9d0919f2003-11-08 01:05:38 +00001169</div>
Chris Lattner00950542001-06-06 20:29:01 +00001170<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001171<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001172<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001173<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001174<p>The structure type is used to represent a collection of data members
1175together in memory. The packing of the field types is defined to match
1176the ABI of the underlying processor. The elements of a structure may
1177be any type that has a size.</p>
1178<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1179and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1180field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1181instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001182<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001183<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001184<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001185<table class="layout">
1186 <tr class="layout">
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001187 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1188 <td class="left">A triple of three <tt>i32</tt> values</td>
1189 </tr><tr class="layout">
1190 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1191 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1192 second element is a <a href="#t_pointer">pointer</a> to a
1193 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1194 an <tt>i32</tt>.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001195 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001196</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001197</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001198
Chris Lattner00950542001-06-06 20:29:01 +00001199<!-- _______________________________________________________________________ -->
Andrew Lenharth75e10682006-12-08 17:13:00 +00001200<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1201</div>
1202<div class="doc_text">
1203<h5>Overview:</h5>
1204<p>The packed structure type is used to represent a collection of data members
1205together in memory. There is no padding between fields. Further, the alignment
1206of a packed structure is 1 byte. The elements of a packed structure may
1207be any type that has a size.</p>
1208<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1209and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1210field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1211instruction.</p>
1212<h5>Syntax:</h5>
1213<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1214<h5>Examples:</h5>
1215<table class="layout">
1216 <tr class="layout">
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001217 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1218 <td class="left">A triple of three <tt>i32</tt> values</td>
1219 </tr><tr class="layout">
1220 <td class="left"><tt>&lt;&nbsp;{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}&nbsp;&gt;</tt></td>
1221 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1222 second element is a <a href="#t_pointer">pointer</a> to a
1223 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1224 an <tt>i32</tt>.</td>
Andrew Lenharth75e10682006-12-08 17:13:00 +00001225 </tr>
1226</table>
1227</div>
1228
1229<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001230<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001231<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001232<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001233<p>As in many languages, the pointer type represents a pointer or
1234reference to another object, which must live in memory.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001235<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001236<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001237<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001238<table class="layout">
1239 <tr class="layout">
1240 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001241 <tt>[4x i32]*</tt><br/>
1242 <tt>i32 (i32 *) *</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001243 </td>
1244 <td class="left">
1245 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
Reid Spencerca86e162006-12-31 07:07:53 +00001246 four <tt>i32</tt> values<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001247 A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerca86e162006-12-31 07:07:53 +00001248 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
1249 <tt>i32</tt>.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001250 </td>
1251 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001252</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001253</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001254
Chris Lattnera58561b2004-08-12 19:12:28 +00001255<!-- _______________________________________________________________________ -->
Reid Spencer485bad12007-02-15 03:07:05 +00001256<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001257<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +00001258
Chris Lattnera58561b2004-08-12 19:12:28 +00001259<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001260
Reid Spencer485bad12007-02-15 03:07:05 +00001261<p>A vector type is a simple derived type that represents a vector
1262of elements. Vector types are used when multiple primitive data
Chris Lattnera58561b2004-08-12 19:12:28 +00001263are operated in parallel using a single instruction (SIMD).
Reid Spencer485bad12007-02-15 03:07:05 +00001264A vector type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +00001265elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer485bad12007-02-15 03:07:05 +00001266of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnera58561b2004-08-12 19:12:28 +00001267considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001268
Chris Lattnera58561b2004-08-12 19:12:28 +00001269<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001270
1271<pre>
1272 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1273</pre>
1274
John Criswellc1f786c2005-05-13 22:25:59 +00001275<p>The number of elements is a constant integer value; elementtype may
Chris Lattner3b19d652007-01-15 01:54:13 +00001276be any integer or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001277
Chris Lattnera58561b2004-08-12 19:12:28 +00001278<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001279
Reid Spencerd3f876c2004-11-01 08:19:36 +00001280<table class="layout">
1281 <tr class="layout">
1282 <td class="left">
Reid Spencerca86e162006-12-31 07:07:53 +00001283 <tt>&lt;4 x i32&gt;</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001284 <tt>&lt;8 x float&gt;</tt><br/>
Reid Spencera5173382007-01-04 16:43:23 +00001285 <tt>&lt;2 x i64&gt;</tt><br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001286 </td>
1287 <td class="left">
Reid Spencer485bad12007-02-15 03:07:05 +00001288 Vector of 4 32-bit integer values.<br/>
1289 Vector of 8 floating-point values.<br/>
1290 Vector of 2 64-bit integer values.<br/>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001291 </td>
1292 </tr>
1293</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001294</div>
1295
Chris Lattner69c11bb2005-04-25 17:34:15 +00001296<!-- _______________________________________________________________________ -->
1297<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1298<div class="doc_text">
1299
1300<h5>Overview:</h5>
1301
1302<p>Opaque types are used to represent unknown types in the system. This
1303corresponds (for example) to the C notion of a foward declared structure type.
1304In LLVM, opaque types can eventually be resolved to any type (not just a
1305structure type).</p>
1306
1307<h5>Syntax:</h5>
1308
1309<pre>
1310 opaque
1311</pre>
1312
1313<h5>Examples:</h5>
1314
1315<table class="layout">
1316 <tr class="layout">
1317 <td class="left">
1318 <tt>opaque</tt>
1319 </td>
1320 <td class="left">
1321 An opaque type.<br/>
1322 </td>
1323 </tr>
1324</table>
1325</div>
1326
1327
Chris Lattnerc3f59762004-12-09 17:30:23 +00001328<!-- *********************************************************************** -->
1329<div class="doc_section"> <a name="constants">Constants</a> </div>
1330<!-- *********************************************************************** -->
1331
1332<div class="doc_text">
1333
1334<p>LLVM has several different basic types of constants. This section describes
1335them all and their syntax.</p>
1336
1337</div>
1338
1339<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +00001340<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001341
1342<div class="doc_text">
1343
1344<dl>
1345 <dt><b>Boolean constants</b></dt>
1346
1347 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencerc78f3372007-01-12 03:35:51 +00001348 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattnerc3f59762004-12-09 17:30:23 +00001349 </dd>
1350
1351 <dt><b>Integer constants</b></dt>
1352
Reid Spencercc16dc32004-12-09 18:02:53 +00001353 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencera5173382007-01-04 16:43:23 +00001354 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattnerc3f59762004-12-09 17:30:23 +00001355 integer types.
1356 </dd>
1357
1358 <dt><b>Floating point constants</b></dt>
1359
1360 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1361 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnerc3f59762004-12-09 17:30:23 +00001362 notation (see below). Floating point constants must have a <a
1363 href="#t_floating">floating point</a> type. </dd>
1364
1365 <dt><b>Null pointer constants</b></dt>
1366
John Criswell9e2485c2004-12-10 15:51:16 +00001367 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +00001368 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1369
1370</dl>
1371
John Criswell9e2485c2004-12-10 15:51:16 +00001372<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +00001373of floating point constants. For example, the form '<tt>double
13740x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
13754.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +00001376(and the only time that they are generated by the disassembler) is when a
1377floating point constant must be emitted but it cannot be represented as a
1378decimal floating point number. For example, NaN's, infinities, and other
1379special values are represented in their IEEE hexadecimal format so that
1380assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001381
1382</div>
1383
1384<!-- ======================================================================= -->
1385<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1386</div>
1387
1388<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001389<p>Aggregate constants arise from aggregation of simple constants
1390and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001391
1392<dl>
1393 <dt><b>Structure constants</b></dt>
1394
1395 <dd>Structure constants are represented with notation similar to structure
1396 type definitions (a comma separated list of elements, surrounded by braces
Reid Spencerca86e162006-12-31 07:07:53 +00001397 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* %G }</tt>",
Chris Lattner3e63a9d2007-07-13 20:01:46 +00001398 where "<tt>%G</tt>" is declared as "<tt>@G = external global i32</tt>". Structure constants
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001399 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +00001400 types of elements must match those specified by the type.
1401 </dd>
1402
1403 <dt><b>Array constants</b></dt>
1404
1405 <dd>Array constants are represented with notation similar to array type
1406 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerca86e162006-12-31 07:07:53 +00001407 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +00001408 constants must have <a href="#t_array">array type</a>, and the number and
1409 types of elements must match those specified by the type.
1410 </dd>
1411
Reid Spencer485bad12007-02-15 03:07:05 +00001412 <dt><b>Vector constants</b></dt>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001413
Reid Spencer485bad12007-02-15 03:07:05 +00001414 <dd>Vector constants are represented with notation similar to vector type
Chris Lattnerc3f59762004-12-09 17:30:23 +00001415 definitions (a comma separated list of elements, surrounded by
Reid Spencerca86e162006-12-31 07:07:53 +00001416 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001417 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
Reid Spencer485bad12007-02-15 03:07:05 +00001418 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattnerc3f59762004-12-09 17:30:23 +00001419 match those specified by the type.
1420 </dd>
1421
1422 <dt><b>Zero initialization</b></dt>
1423
1424 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1425 value to zero of <em>any</em> type, including scalar and aggregate types.
1426 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001427 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001428 initializers.
1429 </dd>
1430</dl>
1431
1432</div>
1433
1434<!-- ======================================================================= -->
1435<div class="doc_subsection">
1436 <a name="globalconstants">Global Variable and Function Addresses</a>
1437</div>
1438
1439<div class="doc_text">
1440
1441<p>The addresses of <a href="#globalvars">global variables</a> and <a
1442href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001443constants. These constants are explicitly referenced when the <a
1444href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001445href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1446file:</p>
1447
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001448<div class="doc_code">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001449<pre>
Chris Lattnera18a4242007-06-06 18:28:13 +00001450@X = global i32 17
1451@Y = global i32 42
1452@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
Chris Lattnerc3f59762004-12-09 17:30:23 +00001453</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001454</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001455
1456</div>
1457
1458<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001459<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001460<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001461 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001462 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001463 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001464
Reid Spencer2dc45b82004-12-09 18:13:12 +00001465 <p>Undefined values indicate to the compiler that the program is well defined
1466 no matter what value is used, giving the compiler more freedom to optimize.
1467 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001468</div>
1469
1470<!-- ======================================================================= -->
1471<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1472</div>
1473
1474<div class="doc_text">
1475
1476<p>Constant expressions are used to allow expressions involving other constants
1477to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001478href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001479that does not have side effects (e.g. load and call are not supported). The
1480following is the syntax for constant expressions:</p>
1481
1482<dl>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001483 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1484 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattner3b19d652007-01-15 01:54:13 +00001485 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001486
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001487 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1488 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattner3b19d652007-01-15 01:54:13 +00001489 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001490
1491 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1492 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattner3b19d652007-01-15 01:54:13 +00001493 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001494
1495 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1496 <dd>Truncate a floating point constant to another floating point type. The
1497 size of CST must be larger than the size of TYPE. Both types must be
1498 floating point.</dd>
1499
1500 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1501 <dd>Floating point extend a constant to another type. The size of CST must be
1502 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1503
Reid Spencer1539a1c2007-07-31 14:40:14 +00001504 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001505 <dd>Convert a floating point constant to the corresponding unsigned integer
1506 constant. TYPE must be an integer type. CST must be floating point. If the
1507 value won't fit in the integer type, the results are undefined.</dd>
1508
Reid Spencerd4448792006-11-09 23:03:26 +00001509 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001510 <dd>Convert a floating point constant to the corresponding signed integer
1511 constant. TYPE must be an integer type. CST must be floating point. If the
1512 value won't fit in the integer type, the results are undefined.</dd>
1513
Reid Spencerd4448792006-11-09 23:03:26 +00001514 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001515 <dd>Convert an unsigned integer constant to the corresponding floating point
1516 constant. TYPE must be floating point. CST must be of integer type. If the
Jeff Cohencb757312007-04-22 14:56:37 +00001517 value won't fit in the floating point type, the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001518
Reid Spencerd4448792006-11-09 23:03:26 +00001519 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001520 <dd>Convert a signed integer constant to the corresponding floating point
1521 constant. TYPE must be floating point. CST must be of integer type. If the
Jeff Cohencb757312007-04-22 14:56:37 +00001522 value won't fit in the floating point type, the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001523
Reid Spencer5c0ef472006-11-11 23:08:07 +00001524 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1525 <dd>Convert a pointer typed constant to the corresponding integer constant
1526 TYPE must be an integer type. CST must be of pointer type. The CST value is
1527 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1528
1529 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1530 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1531 pointer type. CST must be of integer type. The CST value is zero extended,
1532 truncated, or unchanged to make it fit in a pointer size. This one is
1533 <i>really</i> dangerous!</dd>
1534
1535 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001536 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1537 identical (same number of bits). The conversion is done as if the CST value
1538 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5c0ef472006-11-11 23:08:07 +00001539 with this operator, just the type. This can be used for conversion of
Reid Spencer485bad12007-02-15 03:07:05 +00001540 vector types to any other type, as long as they have the same bit width. For
Reid Spencer5c0ef472006-11-11 23:08:07 +00001541 pointers it is only valid to cast to another pointer type.
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001542 </dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001543
1544 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1545
1546 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1547 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1548 instruction, the index list may have zero or more indexes, which are required
1549 to make sense for the type of "CSTPTR".</dd>
1550
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001551 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1552
1553 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer01c42592006-12-04 19:23:19 +00001554 constants.</dd>
1555
1556 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1557 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1558
1559 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1560 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001561
1562 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1563
1564 <dd>Perform the <a href="#i_extractelement">extractelement
1565 operation</a> on constants.
1566
Robert Bocchino05ccd702006-01-15 20:48:27 +00001567 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1568
1569 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer01c42592006-12-04 19:23:19 +00001570 operation</a> on constants.</dd>
Robert Bocchino05ccd702006-01-15 20:48:27 +00001571
Chris Lattnerc1989542006-04-08 00:13:41 +00001572
1573 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1574
1575 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer01c42592006-12-04 19:23:19 +00001576 operation</a> on constants.</dd>
Chris Lattnerc1989542006-04-08 00:13:41 +00001577
Chris Lattnerc3f59762004-12-09 17:30:23 +00001578 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1579
Reid Spencer2dc45b82004-12-09 18:13:12 +00001580 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1581 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001582 binary</a> operations. The constraints on operands are the same as those for
1583 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001584 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001585</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001586</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001587
Chris Lattner00950542001-06-06 20:29:01 +00001588<!-- *********************************************************************** -->
Chris Lattnere87d6532006-01-25 23:47:57 +00001589<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1590<!-- *********************************************************************** -->
1591
1592<!-- ======================================================================= -->
1593<div class="doc_subsection">
1594<a name="inlineasm">Inline Assembler Expressions</a>
1595</div>
1596
1597<div class="doc_text">
1598
1599<p>
1600LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1601Module-Level Inline Assembly</a>) through the use of a special value. This
1602value represents the inline assembler as a string (containing the instructions
1603to emit), a list of operand constraints (stored as a string), and a flag that
1604indicates whether or not the inline asm expression has side effects. An example
1605inline assembler expression is:
1606</p>
1607
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001608<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001609<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001610i32 (i32) asm "bswap $0", "=r,r"
Chris Lattnere87d6532006-01-25 23:47:57 +00001611</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001612</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001613
1614<p>
1615Inline assembler expressions may <b>only</b> be used as the callee operand of
1616a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1617</p>
1618
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001619<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001620<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001621%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattnere87d6532006-01-25 23:47:57 +00001622</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001623</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001624
1625<p>
1626Inline asms with side effects not visible in the constraint list must be marked
1627as having side effects. This is done through the use of the
1628'<tt>sideeffect</tt>' keyword, like so:
1629</p>
1630
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001631<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001632<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001633call void asm sideeffect "eieio", ""()
Chris Lattnere87d6532006-01-25 23:47:57 +00001634</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001635</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001636
1637<p>TODO: The format of the asm and constraints string still need to be
1638documented here. Constraints on what can be done (e.g. duplication, moving, etc
1639need to be documented).
1640</p>
1641
1642</div>
1643
1644<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001645<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1646<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001647
Misha Brukman9d0919f2003-11-08 01:05:38 +00001648<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001649
Chris Lattner261efe92003-11-25 01:02:51 +00001650<p>The LLVM instruction set consists of several different
1651classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001652instructions</a>, <a href="#binaryops">binary instructions</a>,
1653<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001654 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1655instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001656
Misha Brukman9d0919f2003-11-08 01:05:38 +00001657</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001658
Chris Lattner00950542001-06-06 20:29:01 +00001659<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001660<div class="doc_subsection"> <a name="terminators">Terminator
1661Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001662
Misha Brukman9d0919f2003-11-08 01:05:38 +00001663<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001664
Chris Lattner261efe92003-11-25 01:02:51 +00001665<p>As mentioned <a href="#functionstructure">previously</a>, every
1666basic block in a program ends with a "Terminator" instruction, which
1667indicates which block should be executed after the current block is
1668finished. These terminator instructions typically yield a '<tt>void</tt>'
1669value: they produce control flow, not values (the one exception being
1670the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001671<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001672 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1673instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001674the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1675 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1676 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001677
Misha Brukman9d0919f2003-11-08 01:05:38 +00001678</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001679
Chris Lattner00950542001-06-06 20:29:01 +00001680<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001681<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1682Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001683<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001684<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001685<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001686 ret void <i>; Return from void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001687</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001688<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001689<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001690value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001691<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner261efe92003-11-25 01:02:51 +00001692returns a value and then causes control flow, and one that just causes
1693control flow to occur.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001694<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001695<p>The '<tt>ret</tt>' instruction may return any '<a
1696 href="#t_firstclass">first class</a>' type. Notice that a function is
1697not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1698instruction inside of the function that returns a value that does not
1699match the return type of the function.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001700<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001701<p>When the '<tt>ret</tt>' instruction is executed, control flow
1702returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001703 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001704the instruction after the call. If the caller was an "<a
1705 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001706at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001707returns a value, that value shall set the call or invoke instruction's
1708return value.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001709<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001710<pre> ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001711 ret void <i>; Return from a void function</i>
Chris Lattner00950542001-06-06 20:29:01 +00001712</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001713</div>
Chris Lattner00950542001-06-06 20:29:01 +00001714<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001715<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001716<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001717<h5>Syntax:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001718<pre> br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner00950542001-06-06 20:29:01 +00001719</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001720<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001721<p>The '<tt>br</tt>' instruction is used to cause control flow to
1722transfer to a different basic block in the current function. There are
1723two forms of this instruction, corresponding to a conditional branch
1724and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001725<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001726<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencerc78f3372007-01-12 03:35:51 +00001727single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Reid Spencerde151942007-02-19 23:54:10 +00001728unconditional form of the '<tt>br</tt>' instruction takes a single
1729'<tt>label</tt>' value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001730<h5>Semantics:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001731<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001732argument is evaluated. If the value is <tt>true</tt>, control flows
1733to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1734control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001735<h5>Example:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001736<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq, i32 %a, %b<br> br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Reid Spencerca86e162006-12-31 07:07:53 +00001737 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001738</div>
Chris Lattner00950542001-06-06 20:29:01 +00001739<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001740<div class="doc_subsubsection">
1741 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1742</div>
1743
Misha Brukman9d0919f2003-11-08 01:05:38 +00001744<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001745<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001746
1747<pre>
1748 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1749</pre>
1750
Chris Lattner00950542001-06-06 20:29:01 +00001751<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001752
1753<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1754several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001755instruction, allowing a branch to occur to one of many possible
1756destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001757
1758
Chris Lattner00950542001-06-06 20:29:01 +00001759<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001760
1761<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1762comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1763an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1764table is not allowed to contain duplicate constant entries.</p>
1765
Chris Lattner00950542001-06-06 20:29:01 +00001766<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001767
Chris Lattner261efe92003-11-25 01:02:51 +00001768<p>The <tt>switch</tt> instruction specifies a table of values and
1769destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001770table is searched for the given value. If the value is found, control flow is
1771transfered to the corresponding destination; otherwise, control flow is
1772transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001773
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001774<h5>Implementation:</h5>
1775
1776<p>Depending on properties of the target machine and the particular
1777<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001778ways. For example, it could be generated as a series of chained conditional
1779branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001780
1781<h5>Example:</h5>
1782
1783<pre>
1784 <i>; Emulate a conditional br instruction</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00001785 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerca86e162006-12-31 07:07:53 +00001786 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001787
1788 <i>; Emulate an unconditional br instruction</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001789 switch i32 0, label %dest [ ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001790
1791 <i>; Implement a jump table:</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001792 switch i32 %val, label %otherwise [ i32 0, label %onzero
1793 i32 1, label %onone
1794 i32 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001795</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001796</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001797
Chris Lattner00950542001-06-06 20:29:01 +00001798<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001799<div class="doc_subsubsection">
1800 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1801</div>
1802
Misha Brukman9d0919f2003-11-08 01:05:38 +00001803<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001804
Chris Lattner00950542001-06-06 20:29:01 +00001805<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001806
1807<pre>
1808 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
Chris Lattner76b8a332006-05-14 18:23:06 +00001809 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001810</pre>
1811
Chris Lattner6536cfe2002-05-06 22:08:29 +00001812<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001813
1814<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1815function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001816'<tt>normal</tt>' label or the
1817'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001818"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1819"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001820href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1821continued at the dynamically nearest "exception" label.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001822
Chris Lattner00950542001-06-06 20:29:01 +00001823<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001824
Misha Brukman9d0919f2003-11-08 01:05:38 +00001825<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001826
Chris Lattner00950542001-06-06 20:29:01 +00001827<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001828 <li>
Duncan Sands8036ca42007-03-30 12:22:09 +00001829 The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001830 convention</a> the call should use. If none is specified, the call defaults
1831 to using C calling conventions.
1832 </li>
1833 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1834 function value being invoked. In most cases, this is a direct function
1835 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1836 an arbitrary pointer to function value.
1837 </li>
1838
1839 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1840 function to be invoked. </li>
1841
1842 <li>'<tt>function args</tt>': argument list whose types match the function
1843 signature argument types. If the function signature indicates the function
1844 accepts a variable number of arguments, the extra arguments can be
1845 specified. </li>
1846
1847 <li>'<tt>normal label</tt>': the label reached when the called function
1848 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1849
1850 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1851 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1852
Chris Lattner00950542001-06-06 20:29:01 +00001853</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001854
Chris Lattner00950542001-06-06 20:29:01 +00001855<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001856
Misha Brukman9d0919f2003-11-08 01:05:38 +00001857<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001858href="#i_call">call</a></tt>' instruction in most regards. The primary
1859difference is that it establishes an association with a label, which is used by
1860the runtime library to unwind the stack.</p>
1861
1862<p>This instruction is used in languages with destructors to ensure that proper
1863cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1864exception. Additionally, this is important for implementation of
1865'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1866
Chris Lattner00950542001-06-06 20:29:01 +00001867<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001868<pre>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001869 %retval = invoke i32 %Test(i32 15) to label %Continue
1870 unwind label %TestCleanup <i>; {i32}:retval set</i>
1871 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Test(i32 15) to label %Continue
1872 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00001873</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001874</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001875
1876
Chris Lattner27f71f22003-09-03 00:41:47 +00001877<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00001878
Chris Lattner261efe92003-11-25 01:02:51 +00001879<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1880Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00001881
Misha Brukman9d0919f2003-11-08 01:05:38 +00001882<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00001883
Chris Lattner27f71f22003-09-03 00:41:47 +00001884<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001885<pre>
1886 unwind
1887</pre>
1888
Chris Lattner27f71f22003-09-03 00:41:47 +00001889<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001890
1891<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1892at the first callee in the dynamic call stack which used an <a
1893href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1894primarily used to implement exception handling.</p>
1895
Chris Lattner27f71f22003-09-03 00:41:47 +00001896<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00001897
1898<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1899immediately halt. The dynamic call stack is then searched for the first <a
1900href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1901execution continues at the "exceptional" destination block specified by the
1902<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1903dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001904</div>
Chris Lattner35eca582004-10-16 18:04:13 +00001905
1906<!-- _______________________________________________________________________ -->
1907
1908<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1909Instruction</a> </div>
1910
1911<div class="doc_text">
1912
1913<h5>Syntax:</h5>
1914<pre>
1915 unreachable
1916</pre>
1917
1918<h5>Overview:</h5>
1919
1920<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1921instruction is used to inform the optimizer that a particular portion of the
1922code is not reachable. This can be used to indicate that the code after a
1923no-return function cannot be reached, and other facts.</p>
1924
1925<h5>Semantics:</h5>
1926
1927<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1928</div>
1929
1930
1931
Chris Lattner00950542001-06-06 20:29:01 +00001932<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001933<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001934<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00001935<p>Binary operators are used to do most of the computation in a
1936program. They require two operands, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00001937produce a single value. The operands might represent
Reid Spencer485bad12007-02-15 03:07:05 +00001938multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattnera58561b2004-08-12 19:12:28 +00001939The result value of a binary operator is not
Chris Lattner261efe92003-11-25 01:02:51 +00001940necessarily the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001941<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001942</div>
Chris Lattner00950542001-06-06 20:29:01 +00001943<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001944<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1945Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001946<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001947<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001948<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001949</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001950<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001951<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001952<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001953<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00001954 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
Reid Spencer485bad12007-02-15 03:07:05 +00001955 This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00001956Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001957<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001958<p>The value produced is the integer or floating point sum of the two
1959operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001960<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00001961<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001962</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001963</div>
Chris Lattner00950542001-06-06 20:29:01 +00001964<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001965<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1966Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001967<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001968<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001969<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001970</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001971<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001972<p>The '<tt>sub</tt>' instruction returns the difference of its two
1973operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00001974<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1975instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001976<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001977<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00001978 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00001979values.
Reid Spencer485bad12007-02-15 03:07:05 +00001980This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00001981Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001982<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001983<p>The value produced is the integer or floating point difference of
1984the two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001985<h5>Example:</h5>
Bill Wendlingaac388b2007-05-29 09:42:13 +00001986<pre>
1987 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001988 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner00950542001-06-06 20:29:01 +00001989</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001990</div>
Chris Lattner00950542001-06-06 20:29:01 +00001991<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001992<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1993Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001994<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001995<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001996<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00001997</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001998<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001999<p>The '<tt>mul</tt>' instruction returns the product of its two
2000operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002001<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002002<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00002003 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00002004values.
Reid Spencer485bad12007-02-15 03:07:05 +00002005This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00002006Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002007<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002008<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00002009two operands.</p>
Reid Spencera5173382007-01-04 16:43:23 +00002010<p>Because the operands are the same width, the result of an integer
2011multiplication is the same whether the operands should be deemed unsigned or
2012signed.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002013<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002014<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00002015</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002016</div>
Chris Lattner00950542001-06-06 20:29:01 +00002017<!-- _______________________________________________________________________ -->
Reid Spencer1628cec2006-10-26 06:15:43 +00002018<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2019</a></div>
2020<div class="doc_text">
2021<h5>Syntax:</h5>
2022<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2023</pre>
2024<h5>Overview:</h5>
2025<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
2026operands.</p>
2027<h5>Arguments:</h5>
2028<p>The two arguments to the '<tt>udiv</tt>' instruction must be
2029<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer485bad12007-02-15 03:07:05 +00002030types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer1628cec2006-10-26 06:15:43 +00002031of the values in which case the elements must be integers.</p>
2032<h5>Semantics:</h5>
2033<p>The value produced is the unsigned integer quotient of the two operands. This
2034instruction always performs an unsigned division operation, regardless of
2035whether the arguments are unsigned or not.</p>
2036<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002037<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00002038</pre>
2039</div>
2040<!-- _______________________________________________________________________ -->
2041<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2042</a> </div>
2043<div class="doc_text">
2044<h5>Syntax:</h5>
2045<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2046</pre>
2047<h5>Overview:</h5>
2048<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
2049operands.</p>
2050<h5>Arguments:</h5>
2051<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
2052<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer485bad12007-02-15 03:07:05 +00002053types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer1628cec2006-10-26 06:15:43 +00002054of the values in which case the elements must be integers.</p>
2055<h5>Semantics:</h5>
2056<p>The value produced is the signed integer quotient of the two operands. This
2057instruction always performs a signed division operation, regardless of whether
2058the arguments are signed or not.</p>
2059<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002060<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00002061</pre>
2062</div>
2063<!-- _______________________________________________________________________ -->
2064<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002065Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002066<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002067<h5>Syntax:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002068<pre> &lt;result&gt; = fdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002069</pre>
2070<h5>Overview:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002071<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner261efe92003-11-25 01:02:51 +00002072operands.</p>
2073<h5>Arguments:</h5>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002074<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Reid Spencer1628cec2006-10-26 06:15:43 +00002075<a href="#t_floating">floating point</a> values. Both arguments must have
Reid Spencer485bad12007-02-15 03:07:05 +00002076identical types. This instruction can also take <a href="#t_vector">vector</a>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002077versions of floating point values.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002078<h5>Semantics:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002079<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002080<h5>Example:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002081<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002082</pre>
2083</div>
2084<!-- _______________________________________________________________________ -->
Reid Spencer0a783f72006-11-02 01:53:59 +00002085<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2086</div>
2087<div class="doc_text">
2088<h5>Syntax:</h5>
2089<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2090</pre>
2091<h5>Overview:</h5>
2092<p>The '<tt>urem</tt>' instruction returns the remainder from the
2093unsigned division of its two arguments.</p>
2094<h5>Arguments:</h5>
2095<p>The two arguments to the '<tt>urem</tt>' instruction must be
2096<a href="#t_integer">integer</a> values. Both arguments must have identical
2097types.</p>
2098<h5>Semantics:</h5>
2099<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
2100This instruction always performs an unsigned division to get the remainder,
2101regardless of whether the arguments are unsigned or not.</p>
2102<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002103<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00002104</pre>
2105
2106</div>
2107<!-- _______________________________________________________________________ -->
2108<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002109Instruction</a> </div>
2110<div class="doc_text">
2111<h5>Syntax:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002112<pre> &lt;result&gt; = srem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002113</pre>
2114<h5>Overview:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002115<p>The '<tt>srem</tt>' instruction returns the remainder from the
2116signed division of its two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002117<h5>Arguments:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002118<p>The two arguments to the '<tt>srem</tt>' instruction must be
2119<a href="#t_integer">integer</a> values. Both arguments must have identical
2120types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002121<h5>Semantics:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002122<p>This instruction returns the <i>remainder</i> of a division (where the result
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002123has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i>
2124operator (where the result has the same sign as the divisor, <tt>var2</tt>) of
2125a value. For more information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00002126 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002127Math Forum</a>. For a table of how this is implemented in various languages,
Reid Spencer64f5c6c2007-03-24 22:40:44 +00002128please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002129Wikipedia: modulo operation</a>.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002130<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002131<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00002132</pre>
2133
2134</div>
2135<!-- _______________________________________________________________________ -->
2136<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
2137Instruction</a> </div>
2138<div class="doc_text">
2139<h5>Syntax:</h5>
2140<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2141</pre>
2142<h5>Overview:</h5>
2143<p>The '<tt>frem</tt>' instruction returns the remainder from the
2144division of its two operands.</p>
2145<h5>Arguments:</h5>
2146<p>The two arguments to the '<tt>frem</tt>' instruction must be
2147<a href="#t_floating">floating point</a> values. Both arguments must have
2148identical types.</p>
2149<h5>Semantics:</h5>
2150<p>This instruction returns the <i>remainder</i> of a division.</p>
2151<h5>Example:</h5>
2152<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002153</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002154</div>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002155
Reid Spencer8e11bf82007-02-02 13:57:07 +00002156<!-- ======================================================================= -->
2157<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2158Operations</a> </div>
2159<div class="doc_text">
2160<p>Bitwise binary operators are used to do various forms of
2161bit-twiddling in a program. They are generally very efficient
2162instructions and can commonly be strength reduced from other
2163instructions. They require two operands, execute an operation on them,
2164and produce a single value. The resulting value of the bitwise binary
2165operators is always the same type as its first operand.</p>
2166</div>
2167
Reid Spencer569f2fa2007-01-31 21:39:12 +00002168<!-- _______________________________________________________________________ -->
2169<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2170Instruction</a> </div>
2171<div class="doc_text">
2172<h5>Syntax:</h5>
2173<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2174</pre>
2175<h5>Overview:</h5>
2176<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2177the left a specified number of bits.</p>
2178<h5>Arguments:</h5>
2179<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
2180 href="#t_integer">integer</a> type.</p>
2181<h5>Semantics:</h5>
2182<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
2183<h5>Example:</h5><pre>
2184 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2185 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2186 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
2187</pre>
2188</div>
2189<!-- _______________________________________________________________________ -->
2190<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2191Instruction</a> </div>
2192<div class="doc_text">
2193<h5>Syntax:</h5>
2194<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2195</pre>
2196
2197<h5>Overview:</h5>
2198<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002199operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002200
2201<h5>Arguments:</h5>
2202<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
2203<a href="#t_integer">integer</a> type.</p>
2204
2205<h5>Semantics:</h5>
2206<p>This instruction always performs a logical shift right operation. The most
2207significant bits of the result will be filled with zero bits after the
2208shift.</p>
2209
2210<h5>Example:</h5>
2211<pre>
2212 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
2213 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
2214 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
2215 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
2216</pre>
2217</div>
2218
Reid Spencer8e11bf82007-02-02 13:57:07 +00002219<!-- _______________________________________________________________________ -->
Reid Spencer569f2fa2007-01-31 21:39:12 +00002220<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2221Instruction</a> </div>
2222<div class="doc_text">
2223
2224<h5>Syntax:</h5>
2225<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2226</pre>
2227
2228<h5>Overview:</h5>
2229<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002230operand shifted to the right a specified number of bits with sign extension.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002231
2232<h5>Arguments:</h5>
2233<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
2234<a href="#t_integer">integer</a> type.</p>
2235
2236<h5>Semantics:</h5>
2237<p>This instruction always performs an arithmetic shift right operation,
2238The most significant bits of the result will be filled with the sign bit
2239of <tt>var1</tt>.</p>
2240
2241<h5>Example:</h5>
2242<pre>
2243 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
2244 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
2245 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
2246 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
2247</pre>
2248</div>
2249
Chris Lattner00950542001-06-06 20:29:01 +00002250<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002251<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
2252Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002253<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002254<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002255<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002256</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002257<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002258<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
2259its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002260<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002261<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002262 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002263identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002264<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002265<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002266<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002267<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00002268<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00002269 <tbody>
2270 <tr>
2271 <td>In0</td>
2272 <td>In1</td>
2273 <td>Out</td>
2274 </tr>
2275 <tr>
2276 <td>0</td>
2277 <td>0</td>
2278 <td>0</td>
2279 </tr>
2280 <tr>
2281 <td>0</td>
2282 <td>1</td>
2283 <td>0</td>
2284 </tr>
2285 <tr>
2286 <td>1</td>
2287 <td>0</td>
2288 <td>0</td>
2289 </tr>
2290 <tr>
2291 <td>1</td>
2292 <td>1</td>
2293 <td>1</td>
2294 </tr>
2295 </tbody>
2296</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002297</div>
Chris Lattner00950542001-06-06 20:29:01 +00002298<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002299<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
2300 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
2301 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner00950542001-06-06 20:29:01 +00002302</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002303</div>
Chris Lattner00950542001-06-06 20:29:01 +00002304<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002305<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002306<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002307<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002308<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002309</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00002310<h5>Overview:</h5>
2311<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2312or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002313<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002314<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002315 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002316identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002317<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002318<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002319<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002320<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002321<table border="1" cellspacing="0" cellpadding="4">
2322 <tbody>
2323 <tr>
2324 <td>In0</td>
2325 <td>In1</td>
2326 <td>Out</td>
2327 </tr>
2328 <tr>
2329 <td>0</td>
2330 <td>0</td>
2331 <td>0</td>
2332 </tr>
2333 <tr>
2334 <td>0</td>
2335 <td>1</td>
2336 <td>1</td>
2337 </tr>
2338 <tr>
2339 <td>1</td>
2340 <td>0</td>
2341 <td>1</td>
2342 </tr>
2343 <tr>
2344 <td>1</td>
2345 <td>1</td>
2346 <td>1</td>
2347 </tr>
2348 </tbody>
2349</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002350</div>
Chris Lattner00950542001-06-06 20:29:01 +00002351<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002352<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2353 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2354 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner00950542001-06-06 20:29:01 +00002355</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002356</div>
Chris Lattner00950542001-06-06 20:29:01 +00002357<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002358<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2359Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002360<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002361<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002362<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002363</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002364<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002365<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2366or of its two operands. The <tt>xor</tt> is used to implement the
2367"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002368<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002369<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002370 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002371identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002372<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002373<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002374<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002375<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002376<table border="1" cellspacing="0" cellpadding="4">
2377 <tbody>
2378 <tr>
2379 <td>In0</td>
2380 <td>In1</td>
2381 <td>Out</td>
2382 </tr>
2383 <tr>
2384 <td>0</td>
2385 <td>0</td>
2386 <td>0</td>
2387 </tr>
2388 <tr>
2389 <td>0</td>
2390 <td>1</td>
2391 <td>1</td>
2392 </tr>
2393 <tr>
2394 <td>1</td>
2395 <td>0</td>
2396 <td>1</td>
2397 </tr>
2398 <tr>
2399 <td>1</td>
2400 <td>1</td>
2401 <td>0</td>
2402 </tr>
2403 </tbody>
2404</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002405</div>
Chris Lattner261efe92003-11-25 01:02:51 +00002406<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00002407<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002408<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2409 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2410 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2411 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00002412</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002413</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002414
Chris Lattner00950542001-06-06 20:29:01 +00002415<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002416<div class="doc_subsection">
Chris Lattner3df241e2006-04-08 23:07:04 +00002417 <a name="vectorops">Vector Operations</a>
2418</div>
2419
2420<div class="doc_text">
2421
2422<p>LLVM supports several instructions to represent vector operations in a
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002423target-independent manner. These instructions cover the element-access and
Chris Lattner3df241e2006-04-08 23:07:04 +00002424vector-specific operations needed to process vectors effectively. While LLVM
2425does directly support these vector operations, many sophisticated algorithms
2426will want to use target-specific intrinsics to take full advantage of a specific
2427target.</p>
2428
2429</div>
2430
2431<!-- _______________________________________________________________________ -->
2432<div class="doc_subsubsection">
2433 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2434</div>
2435
2436<div class="doc_text">
2437
2438<h5>Syntax:</h5>
2439
2440<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002441 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002442</pre>
2443
2444<h5>Overview:</h5>
2445
2446<p>
2447The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer485bad12007-02-15 03:07:05 +00002448element from a vector at a specified index.
Chris Lattner3df241e2006-04-08 23:07:04 +00002449</p>
2450
2451
2452<h5>Arguments:</h5>
2453
2454<p>
2455The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer485bad12007-02-15 03:07:05 +00002456value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattner3df241e2006-04-08 23:07:04 +00002457an index indicating the position from which to extract the element.
2458The index may be a variable.</p>
2459
2460<h5>Semantics:</h5>
2461
2462<p>
2463The result is a scalar of the same type as the element type of
2464<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2465<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2466results are undefined.
2467</p>
2468
2469<h5>Example:</h5>
2470
2471<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002472 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002473</pre>
2474</div>
2475
2476
2477<!-- _______________________________________________________________________ -->
2478<div class="doc_subsubsection">
2479 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2480</div>
2481
2482<div class="doc_text">
2483
2484<h5>Syntax:</h5>
2485
2486<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002487 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, i32 &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002488</pre>
2489
2490<h5>Overview:</h5>
2491
2492<p>
2493The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer485bad12007-02-15 03:07:05 +00002494element into a vector at a specified index.
Chris Lattner3df241e2006-04-08 23:07:04 +00002495</p>
2496
2497
2498<h5>Arguments:</h5>
2499
2500<p>
2501The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer485bad12007-02-15 03:07:05 +00002502value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattner3df241e2006-04-08 23:07:04 +00002503scalar value whose type must equal the element type of the first
2504operand. The third operand is an index indicating the position at
2505which to insert the value. The index may be a variable.</p>
2506
2507<h5>Semantics:</h5>
2508
2509<p>
Reid Spencer485bad12007-02-15 03:07:05 +00002510The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattner3df241e2006-04-08 23:07:04 +00002511element values are those of <tt>val</tt> except at position
2512<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2513exceeds the length of <tt>val</tt>, the results are undefined.
2514</p>
2515
2516<h5>Example:</h5>
2517
2518<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002519 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002520</pre>
2521</div>
2522
2523<!-- _______________________________________________________________________ -->
2524<div class="doc_subsubsection">
2525 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2526</div>
2527
2528<div class="doc_text">
2529
2530<h5>Syntax:</h5>
2531
2532<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002533 &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;n x i32&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002534</pre>
2535
2536<h5>Overview:</h5>
2537
2538<p>
2539The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2540from two input vectors, returning a vector of the same type.
2541</p>
2542
2543<h5>Arguments:</h5>
2544
2545<p>
2546The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2547with types that match each other and types that match the result of the
2548instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerca86e162006-12-31 07:07:53 +00002549of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattner3df241e2006-04-08 23:07:04 +00002550</p>
2551
2552<p>
2553The shuffle mask operand is required to be a constant vector with either
2554constant integer or undef values.
2555</p>
2556
2557<h5>Semantics:</h5>
2558
2559<p>
2560The elements of the two input vectors are numbered from left to right across
2561both of the vectors. The shuffle mask operand specifies, for each element of
2562the result vector, which element of the two input registers the result element
2563gets. The element selector may be undef (meaning "don't care") and the second
2564operand may be undef if performing a shuffle from only one vector.
2565</p>
2566
2567<h5>Example:</h5>
2568
2569<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002570 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002571 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002572 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2573 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
Chris Lattner3df241e2006-04-08 23:07:04 +00002574</pre>
2575</div>
2576
Tanya Lattner09474292006-04-14 19:24:33 +00002577
Chris Lattner3df241e2006-04-08 23:07:04 +00002578<!-- ======================================================================= -->
2579<div class="doc_subsection">
Chris Lattner884a9702006-08-15 00:45:58 +00002580 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002581</div>
2582
Misha Brukman9d0919f2003-11-08 01:05:38 +00002583<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002584
Chris Lattner261efe92003-11-25 01:02:51 +00002585<p>A key design point of an SSA-based representation is how it
2586represents memory. In LLVM, no memory locations are in SSA form, which
2587makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00002588allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002589
Misha Brukman9d0919f2003-11-08 01:05:38 +00002590</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002591
Chris Lattner00950542001-06-06 20:29:01 +00002592<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002593<div class="doc_subsubsection">
2594 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2595</div>
2596
Misha Brukman9d0919f2003-11-08 01:05:38 +00002597<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002598
Chris Lattner00950542001-06-06 20:29:01 +00002599<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002600
2601<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002602 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002603</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002604
Chris Lattner00950542001-06-06 20:29:01 +00002605<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002606
Chris Lattner261efe92003-11-25 01:02:51 +00002607<p>The '<tt>malloc</tt>' instruction allocates memory from the system
2608heap and returns a pointer to it.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002609
Chris Lattner00950542001-06-06 20:29:01 +00002610<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002611
2612<p>The '<tt>malloc</tt>' instruction allocates
2613<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00002614bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002615appropriate type to the program. If "NumElements" is specified, it is the
2616number of elements allocated. If an alignment is specified, the value result
2617of the allocation is guaranteed to be aligned to at least that boundary. If
2618not specified, or if zero, the target can choose to align the allocation on any
2619convenient boundary.</p>
2620
Misha Brukman9d0919f2003-11-08 01:05:38 +00002621<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002622
Chris Lattner00950542001-06-06 20:29:01 +00002623<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002624
Chris Lattner261efe92003-11-25 01:02:51 +00002625<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2626a pointer is returned.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002627
Chris Lattner2cbdc452005-11-06 08:02:57 +00002628<h5>Example:</h5>
2629
2630<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002631 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002632
Bill Wendlingaac388b2007-05-29 09:42:13 +00002633 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2634 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2635 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2636 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2637 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00002638</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002639</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002640
Chris Lattner00950542001-06-06 20:29:01 +00002641<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002642<div class="doc_subsubsection">
2643 <a name="i_free">'<tt>free</tt>' Instruction</a>
2644</div>
2645
Misha Brukman9d0919f2003-11-08 01:05:38 +00002646<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002647
Chris Lattner00950542001-06-06 20:29:01 +00002648<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002649
2650<pre>
2651 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00002652</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002653
Chris Lattner00950542001-06-06 20:29:01 +00002654<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002655
Chris Lattner261efe92003-11-25 01:02:51 +00002656<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00002657memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002658
Chris Lattner00950542001-06-06 20:29:01 +00002659<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002660
Chris Lattner261efe92003-11-25 01:02:51 +00002661<p>'<tt>value</tt>' shall be a pointer value that points to a value
2662that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2663instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002664
Chris Lattner00950542001-06-06 20:29:01 +00002665<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002666
John Criswell9e2485c2004-12-10 15:51:16 +00002667<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner261efe92003-11-25 01:02:51 +00002668after this instruction executes.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002669
Chris Lattner00950542001-06-06 20:29:01 +00002670<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002671
2672<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002673 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2674 free [4 x i8]* %array
Chris Lattner00950542001-06-06 20:29:01 +00002675</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002676</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002677
Chris Lattner00950542001-06-06 20:29:01 +00002678<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002679<div class="doc_subsubsection">
2680 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2681</div>
2682
Misha Brukman9d0919f2003-11-08 01:05:38 +00002683<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002684
Chris Lattner00950542001-06-06 20:29:01 +00002685<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002686
2687<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002688 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner00950542001-06-06 20:29:01 +00002689</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002690
Chris Lattner00950542001-06-06 20:29:01 +00002691<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002692
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002693<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
2694currently executing function, to be automatically released when this function
Chris Lattner261efe92003-11-25 01:02:51 +00002695returns to its caller.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002696
Chris Lattner00950542001-06-06 20:29:01 +00002697<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002698
John Criswell9e2485c2004-12-10 15:51:16 +00002699<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002700bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002701appropriate type to the program. If "NumElements" is specified, it is the
2702number of elements allocated. If an alignment is specified, the value result
2703of the allocation is guaranteed to be aligned to at least that boundary. If
2704not specified, or if zero, the target can choose to align the allocation on any
2705convenient boundary.</p>
2706
Misha Brukman9d0919f2003-11-08 01:05:38 +00002707<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002708
Chris Lattner00950542001-06-06 20:29:01 +00002709<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002710
John Criswellc1f786c2005-05-13 22:25:59 +00002711<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00002712memory is automatically released when the function returns. The '<tt>alloca</tt>'
2713instruction is commonly used to represent automatic variables that must
2714have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00002715 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002716instructions), the memory is reclaimed.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002717
Chris Lattner00950542001-06-06 20:29:01 +00002718<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002719
2720<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002721 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002722 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2723 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002724 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00002725</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002726</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002727
Chris Lattner00950542001-06-06 20:29:01 +00002728<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002729<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2730Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002731<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002732<h5>Syntax:</h5>
Christopher Lamb2330e4d2007-04-21 08:16:25 +00002733<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 Lattner2b7d3202002-05-06 03:03:22 +00002734<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002735<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002736<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002737<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00002738address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00002739 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00002740marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00002741the number or order of execution of this <tt>load</tt> with other
2742volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2743instructions. </p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002744<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002745<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002746<h5>Examples:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002747<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002748 <a
Reid Spencerca86e162006-12-31 07:07:53 +00002749 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2750 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002751</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002752</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002753<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002754<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2755Instruction</a> </div>
Reid Spencer035ab572006-11-09 21:18:01 +00002756<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002757<h5>Syntax:</h5>
Christopher Lamb2330e4d2007-04-21 08:16:25 +00002758<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
2759 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002760</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002761<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002762<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002763<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002764<p>There are two arguments to the '<tt>store</tt>' instruction: a value
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002765to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002766operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00002767operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00002768optimizer is not allowed to modify the number or order of execution of
2769this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2770 href="#i_store">store</a></tt> instructions.</p>
2771<h5>Semantics:</h5>
2772<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2773at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002774<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002775<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002776 <a
Reid Spencerca86e162006-12-31 07:07:53 +00002777 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2778 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002779</pre>
Reid Spencer47ce1792006-11-09 21:15:49 +00002780</div>
2781
Chris Lattner2b7d3202002-05-06 03:03:22 +00002782<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002783<div class="doc_subsubsection">
2784 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2785</div>
2786
Misha Brukman9d0919f2003-11-08 01:05:38 +00002787<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00002788<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002789<pre>
2790 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2791</pre>
2792
Chris Lattner7faa8832002-04-14 06:13:44 +00002793<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002794
2795<p>
2796The '<tt>getelementptr</tt>' instruction is used to get the address of a
2797subelement of an aggregate data structure.</p>
2798
Chris Lattner7faa8832002-04-14 06:13:44 +00002799<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002800
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002801<p>This instruction takes a list of integer operands that indicate what
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002802elements of the aggregate object to index to. The actual types of the arguments
2803provided depend on the type of the first pointer argument. The
2804'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00002805levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerca86e162006-12-31 07:07:53 +00002806structure, only <tt>i32</tt> integer constants are allowed. When indexing
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002807into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2808be sign extended to 64-bit values.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002809
Chris Lattner261efe92003-11-25 01:02:51 +00002810<p>For example, let's consider a C code fragment and how it gets
2811compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002812
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002813<div class="doc_code">
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002814<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002815struct RT {
2816 char A;
Chris Lattnercabc8462007-05-29 15:43:56 +00002817 int B[10][20];
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002818 char C;
2819};
2820struct ST {
Chris Lattnercabc8462007-05-29 15:43:56 +00002821 int X;
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002822 double Y;
2823 struct RT Z;
2824};
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002825
Chris Lattnercabc8462007-05-29 15:43:56 +00002826int *foo(struct ST *s) {
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002827 return &amp;s[1].Z.B[5][13];
2828}
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002829</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002830</div>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002831
Misha Brukman9d0919f2003-11-08 01:05:38 +00002832<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002833
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002834<div class="doc_code">
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002835<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002836%RT = type { i8 , [10 x [20 x i32]], i8 }
2837%ST = type { i32, double, %RT }
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002838
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002839define i32* %foo(%ST* %s) {
2840entry:
2841 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
2842 ret i32* %reg
2843}
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002844</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002845</div>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002846
Chris Lattner7faa8832002-04-14 06:13:44 +00002847<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002848
2849<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00002850on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencer85f5b5b2006-12-04 21:29:24 +00002851and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencer42ddd842006-12-03 16:53:48 +00002852<a href="#t_integer">integer</a> type but the value will always be sign extended
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002853to 64-bits. <a href="#t_struct">Structure</a> types require <tt>i32</tt>
Reid Spencer42ddd842006-12-03 16:53:48 +00002854<b>constants</b>.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002855
Misha Brukman9d0919f2003-11-08 01:05:38 +00002856<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerca86e162006-12-31 07:07:53 +00002857type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002858}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerca86e162006-12-31 07:07:53 +00002859the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
2860i8 }</tt>' type, another structure. The third index indexes into the second
2861element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002862array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerca86e162006-12-31 07:07:53 +00002863'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
2864to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002865
Chris Lattner261efe92003-11-25 01:02:51 +00002866<p>Note that it is perfectly legal to index partially through a
2867structure, returning a pointer to an inner element. Because of this,
2868the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002869
2870<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002871 define i32* %foo(%ST* %s) {
2872 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002873 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
2874 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002875 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
2876 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
2877 ret i32* %t5
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002878 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00002879</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00002880
2881<p>Note that it is undefined to access an array out of bounds: array and
2882pointer indexes must always be within the defined bounds of the array type.
2883The one exception for this rules is zero length arrays. These arrays are
2884defined to be accessible as variable length arrays, which requires access
2885beyond the zero'th element.</p>
2886
Chris Lattner884a9702006-08-15 00:45:58 +00002887<p>The getelementptr instruction is often confusing. For some more insight
2888into how it works, see <a href="GetElementPtr.html">the getelementptr
2889FAQ</a>.</p>
2890
Chris Lattner7faa8832002-04-14 06:13:44 +00002891<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00002892
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002893<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002894 <i>; yields [12 x i8]*:aptr</i>
2895 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002896</pre>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00002897</div>
Reid Spencer47ce1792006-11-09 21:15:49 +00002898
Chris Lattner00950542001-06-06 20:29:01 +00002899<!-- ======================================================================= -->
Reid Spencer2fd21e62006-11-08 01:18:52 +00002900<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002901</div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002902<div class="doc_text">
Reid Spencer2fd21e62006-11-08 01:18:52 +00002903<p>The instructions in this category are the conversion instructions (casting)
2904which all take a single operand and a type. They perform various bit conversions
2905on the operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002906</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00002907
Chris Lattner6536cfe2002-05-06 22:08:29 +00002908<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00002909<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002910 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
2911</div>
2912<div class="doc_text">
2913
2914<h5>Syntax:</h5>
2915<pre>
2916 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2917</pre>
2918
2919<h5>Overview:</h5>
2920<p>
2921The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
2922</p>
2923
2924<h5>Arguments:</h5>
2925<p>
2926The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
2927be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattner3b19d652007-01-15 01:54:13 +00002928and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencerd4448792006-11-09 23:03:26 +00002929type. The bit size of <tt>value</tt> must be larger than the bit size of
2930<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002931
2932<h5>Semantics:</h5>
2933<p>
2934The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencerd4448792006-11-09 23:03:26 +00002935and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
2936larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
2937It will always truncate bits.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002938
2939<h5>Example:</h5>
2940<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002941 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00002942 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
2943 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002944</pre>
2945</div>
2946
2947<!-- _______________________________________________________________________ -->
2948<div class="doc_subsubsection">
2949 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
2950</div>
2951<div class="doc_text">
2952
2953<h5>Syntax:</h5>
2954<pre>
2955 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2956</pre>
2957
2958<h5>Overview:</h5>
2959<p>The '<tt>zext</tt>' instruction zero extends its operand to type
2960<tt>ty2</tt>.</p>
2961
2962
2963<h5>Arguments:</h5>
2964<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattner3b19d652007-01-15 01:54:13 +00002965<a href="#t_integer">integer</a> type, and a type to cast it to, which must
2966also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencerd4448792006-11-09 23:03:26 +00002967<tt>value</tt> must be smaller than the bit size of the destination type,
2968<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002969
2970<h5>Semantics:</h5>
2971<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Chris Lattnerd1d25172007-05-24 19:13:27 +00002972bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002973
Reid Spencerb5929522007-01-12 15:46:11 +00002974<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002975
2976<h5>Example:</h5>
2977<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002978 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00002979 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00002980</pre>
2981</div>
2982
2983<!-- _______________________________________________________________________ -->
2984<div class="doc_subsubsection">
2985 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
2986</div>
2987<div class="doc_text">
2988
2989<h5>Syntax:</h5>
2990<pre>
2991 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2992</pre>
2993
2994<h5>Overview:</h5>
2995<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
2996
2997<h5>Arguments:</h5>
2998<p>
2999The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattner3b19d652007-01-15 01:54:13 +00003000<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3001also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencerd4448792006-11-09 23:03:26 +00003002<tt>value</tt> must be smaller than the bit size of the destination type,
3003<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003004
3005<h5>Semantics:</h5>
3006<p>
3007The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
3008bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
Chris Lattnerd1d25172007-05-24 19:13:27 +00003009the type <tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003010
Reid Spencerc78f3372007-01-12 03:35:51 +00003011<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003012
3013<h5>Example:</h5>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003014<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003015 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00003016 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003017</pre>
3018</div>
3019
3020<!-- _______________________________________________________________________ -->
3021<div class="doc_subsubsection">
Reid Spencer3fa91b02006-11-09 21:48:10 +00003022 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
3023</div>
3024
3025<div class="doc_text">
3026
3027<h5>Syntax:</h5>
3028
3029<pre>
3030 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3031</pre>
3032
3033<h5>Overview:</h5>
3034<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
3035<tt>ty2</tt>.</p>
3036
3037
3038<h5>Arguments:</h5>
3039<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
3040 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
3041cast it to. The size of <tt>value</tt> must be larger than the size of
3042<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
3043<i>no-op cast</i>.</p>
3044
3045<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003046<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
3047<a href="#t_floating">floating point</a> type to a smaller
3048<a href="#t_floating">floating point</a> type. If the value cannot fit within
3049the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer3fa91b02006-11-09 21:48:10 +00003050
3051<h5>Example:</h5>
3052<pre>
3053 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
3054 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
3055</pre>
3056</div>
3057
3058<!-- _______________________________________________________________________ -->
3059<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003060 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
3061</div>
3062<div class="doc_text">
3063
3064<h5>Syntax:</h5>
3065<pre>
3066 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3067</pre>
3068
3069<h5>Overview:</h5>
3070<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
3071floating point value.</p>
3072
3073<h5>Arguments:</h5>
3074<p>The '<tt>fpext</tt>' instruction takes a
3075<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencerd4448792006-11-09 23:03:26 +00003076and a <a href="#t_floating">floating point</a> type to cast it to. The source
3077type must be smaller than the destination type.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003078
3079<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003080<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Duncan Sands8036ca42007-03-30 12:22:09 +00003081<a href="#t_floating">floating point</a> type to a larger
3082<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
Reid Spencerd4448792006-11-09 23:03:26 +00003083used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5c0ef472006-11-11 23:08:07 +00003084<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003085
3086<h5>Example:</h5>
3087<pre>
3088 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
3089 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
3090</pre>
3091</div>
3092
3093<!-- _______________________________________________________________________ -->
3094<div class="doc_subsubsection">
Reid Spencer24d6da52007-01-21 00:29:26 +00003095 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003096</div>
3097<div class="doc_text">
3098
3099<h5>Syntax:</h5>
3100<pre>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003101 &lt;result&gt; = fptoui &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003102</pre>
3103
3104<h5>Overview:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003105<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003106unsigned integer equivalent of type <tt>ty2</tt>.
3107</p>
3108
3109<h5>Arguments:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003110<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003111<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattner3b19d652007-01-15 01:54:13 +00003112must be an <a href="#t_integer">integer</a> type.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003113
3114<h5>Semantics:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003115<p> The '<tt>fptoui</tt>' instruction converts its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003116<a href="#t_floating">floating point</a> operand into the nearest (rounding
3117towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
3118the results are undefined.</p>
3119
Reid Spencerc78f3372007-01-12 03:35:51 +00003120<p>When converting to i1, the conversion is done as a comparison against
3121zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
3122If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003123
3124<h5>Example:</h5>
3125<pre>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003126 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
3127 %Y = fptoui float 1.0E+300 to i1 <i>; yields i1:true</i>
3128 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003129</pre>
3130</div>
3131
3132<!-- _______________________________________________________________________ -->
3133<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003134 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003135</div>
3136<div class="doc_text">
3137
3138<h5>Syntax:</h5>
3139<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003140 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003141</pre>
3142
3143<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003144<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003145<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnercc37aae2004-03-12 05:50:16 +00003146</p>
3147
3148
Chris Lattner6536cfe2002-05-06 22:08:29 +00003149<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003150<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003151<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattner3b19d652007-01-15 01:54:13 +00003152must also be an <a href="#t_integer">integer</a> type.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003153
Chris Lattner6536cfe2002-05-06 22:08:29 +00003154<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003155<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003156<a href="#t_floating">floating point</a> operand into the nearest (rounding
3157towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
3158the results are undefined.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003159
Reid Spencerc78f3372007-01-12 03:35:51 +00003160<p>When converting to i1, the conversion is done as a comparison against
3161zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
3162If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003163
Chris Lattner33ba0d92001-07-09 00:26:23 +00003164<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003165<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003166 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
3167 %Y = fptosi float 1.0E-247 to i1 <i>; yields i1:true</i>
Reid Spencerca86e162006-12-31 07:07:53 +00003168 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003169</pre>
3170</div>
3171
3172<!-- _______________________________________________________________________ -->
3173<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003174 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003175</div>
3176<div class="doc_text">
3177
3178<h5>Syntax:</h5>
3179<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003180 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003181</pre>
3182
3183<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003184<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003185integer and converts that value to the <tt>ty2</tt> type.</p>
3186
3187
3188<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003189<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattner3b19d652007-01-15 01:54:13 +00003190<a href="#t_integer">integer</a> value, and a type to cast it to, which must
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003191be a <a href="#t_floating">floating point</a> type.</p>
3192
3193<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003194<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003195integer quantity and converts it to the corresponding floating point value. If
Jeff Cohencb757312007-04-22 14:56:37 +00003196the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003197
3198
3199<h5>Example:</h5>
3200<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003201 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003202 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003203</pre>
3204</div>
3205
3206<!-- _______________________________________________________________________ -->
3207<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003208 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003209</div>
3210<div class="doc_text">
3211
3212<h5>Syntax:</h5>
3213<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003214 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003215</pre>
3216
3217<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003218<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003219integer and converts that value to the <tt>ty2</tt> type.</p>
3220
3221<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003222<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattner3b19d652007-01-15 01:54:13 +00003223<a href="#t_integer">integer</a> value, and a type to cast it to, which must be
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003224a <a href="#t_floating">floating point</a> type.</p>
3225
3226<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003227<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003228integer quantity and converts it to the corresponding floating point value. If
Jeff Cohencb757312007-04-22 14:56:37 +00003229the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003230
3231<h5>Example:</h5>
3232<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003233 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003234 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003235</pre>
3236</div>
3237
3238<!-- _______________________________________________________________________ -->
3239<div class="doc_subsubsection">
Reid Spencer72679252006-11-11 21:00:47 +00003240 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3241</div>
3242<div class="doc_text">
3243
3244<h5>Syntax:</h5>
3245<pre>
3246 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3247</pre>
3248
3249<h5>Overview:</h5>
3250<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3251the integer type <tt>ty2</tt>.</p>
3252
3253<h5>Arguments:</h5>
3254<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
Duncan Sands8036ca42007-03-30 12:22:09 +00003255must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Reid Spencer72679252006-11-11 21:00:47 +00003256<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3257
3258<h5>Semantics:</h5>
3259<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3260<tt>ty2</tt> by interpreting the pointer value as an integer and either
3261truncating or zero extending that value to the size of the integer type. If
3262<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3263<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
Jeff Cohenb627eab2007-04-29 01:07:00 +00003264are the same size, then nothing is done (<i>no-op cast</i>) other than a type
3265change.</p>
Reid Spencer72679252006-11-11 21:00:47 +00003266
3267<h5>Example:</h5>
3268<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003269 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
3270 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
Reid Spencer72679252006-11-11 21:00:47 +00003271</pre>
3272</div>
3273
3274<!-- _______________________________________________________________________ -->
3275<div class="doc_subsubsection">
3276 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3277</div>
3278<div class="doc_text">
3279
3280<h5>Syntax:</h5>
3281<pre>
3282 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3283</pre>
3284
3285<h5>Overview:</h5>
3286<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3287a pointer type, <tt>ty2</tt>.</p>
3288
3289<h5>Arguments:</h5>
Duncan Sands8036ca42007-03-30 12:22:09 +00003290<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Reid Spencer72679252006-11-11 21:00:47 +00003291value to cast, and a type to cast it to, which must be a
Anton Korobeynikov7f705592007-01-12 19:20:47 +00003292<a href="#t_pointer">pointer</a> type.
Reid Spencer72679252006-11-11 21:00:47 +00003293
3294<h5>Semantics:</h5>
3295<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3296<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3297the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3298size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3299the size of a pointer then a zero extension is done. If they are the same size,
3300nothing is done (<i>no-op cast</i>).</p>
3301
3302<h5>Example:</h5>
3303<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003304 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
3305 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
3306 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
Reid Spencer72679252006-11-11 21:00:47 +00003307</pre>
3308</div>
3309
3310<!-- _______________________________________________________________________ -->
3311<div class="doc_subsubsection">
Reid Spencer5c0ef472006-11-11 23:08:07 +00003312 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003313</div>
3314<div class="doc_text">
3315
3316<h5>Syntax:</h5>
3317<pre>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003318 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003319</pre>
3320
3321<h5>Overview:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003322<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003323<tt>ty2</tt> without changing any bits.</p>
3324
3325<h5>Arguments:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003326<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003327a first class value, and a type to cast it to, which must also be a <a
3328 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencer19b569f2007-01-09 20:08:58 +00003329and the destination type, <tt>ty2</tt>, must be identical. If the source
3330type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003331
3332<h5>Semantics:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003333<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer72679252006-11-11 21:00:47 +00003334<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3335this conversion. The conversion is done as if the <tt>value</tt> had been
3336stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3337converted to other pointer types with this instruction. To convert pointers to
3338other types, use the <a href="#i_inttoptr">inttoptr</a> or
3339<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003340
3341<h5>Example:</h5>
3342<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003343 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
Reid Spencerca86e162006-12-31 07:07:53 +00003344 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3345 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00003346</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003347</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003348
Reid Spencer2fd21e62006-11-08 01:18:52 +00003349<!-- ======================================================================= -->
3350<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3351<div class="doc_text">
3352<p>The instructions in this category are the "miscellaneous"
3353instructions, which defy better classification.</p>
3354</div>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003355
3356<!-- _______________________________________________________________________ -->
3357<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3358</div>
3359<div class="doc_text">
3360<h5>Syntax:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003361<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {i1}:result</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003362</pre>
3363<h5>Overview:</h5>
3364<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3365of its two integer operands.</p>
3366<h5>Arguments:</h5>
3367<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Jeff Cohenb627eab2007-04-29 01:07:00 +00003368the condition code indicating the kind of comparison to perform. It is not
3369a value, just a keyword. The possible condition code are:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003370<ol>
3371 <li><tt>eq</tt>: equal</li>
3372 <li><tt>ne</tt>: not equal </li>
3373 <li><tt>ugt</tt>: unsigned greater than</li>
3374 <li><tt>uge</tt>: unsigned greater or equal</li>
3375 <li><tt>ult</tt>: unsigned less than</li>
3376 <li><tt>ule</tt>: unsigned less or equal</li>
3377 <li><tt>sgt</tt>: signed greater than</li>
3378 <li><tt>sge</tt>: signed greater or equal</li>
3379 <li><tt>slt</tt>: signed less than</li>
3380 <li><tt>sle</tt>: signed less or equal</li>
3381</ol>
Chris Lattner3b19d652007-01-15 01:54:13 +00003382<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Reid Spencer350f8aa2007-01-04 05:19:58 +00003383<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003384<h5>Semantics:</h5>
3385<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3386the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencerc78f3372007-01-12 03:35:51 +00003387yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003388<ol>
3389 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3390 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3391 </li>
3392 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3393 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3394 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3395 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3396 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3397 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3398 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3399 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3400 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3401 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3402 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3403 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3404 <li><tt>sge</tt>: interprets the operands as signed values and yields
3405 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3406 <li><tt>slt</tt>: interprets the operands as signed values and yields
3407 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3408 <li><tt>sle</tt>: interprets the operands as signed values and yields
3409 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003410</ol>
3411<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Jeff Cohenb627eab2007-04-29 01:07:00 +00003412values are compared as if they were integers.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003413
3414<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003415<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3416 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3417 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3418 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3419 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3420 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003421</pre>
3422</div>
3423
3424<!-- _______________________________________________________________________ -->
3425<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3426</div>
3427<div class="doc_text">
3428<h5>Syntax:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003429<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {i1}:result</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003430</pre>
3431<h5>Overview:</h5>
3432<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3433of its floating point operands.</p>
3434<h5>Arguments:</h5>
3435<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Jeff Cohenb627eab2007-04-29 01:07:00 +00003436the condition code indicating the kind of comparison to perform. It is not
3437a value, just a keyword. The possible condition code are:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003438<ol>
Reid Spencerb7f26282006-11-19 03:00:14 +00003439 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003440 <li><tt>oeq</tt>: ordered and equal</li>
3441 <li><tt>ogt</tt>: ordered and greater than </li>
3442 <li><tt>oge</tt>: ordered and greater than or equal</li>
3443 <li><tt>olt</tt>: ordered and less than </li>
3444 <li><tt>ole</tt>: ordered and less than or equal</li>
3445 <li><tt>one</tt>: ordered and not equal</li>
3446 <li><tt>ord</tt>: ordered (no nans)</li>
3447 <li><tt>ueq</tt>: unordered or equal</li>
3448 <li><tt>ugt</tt>: unordered or greater than </li>
3449 <li><tt>uge</tt>: unordered or greater than or equal</li>
3450 <li><tt>ult</tt>: unordered or less than </li>
3451 <li><tt>ule</tt>: unordered or less than or equal</li>
3452 <li><tt>une</tt>: unordered or not equal</li>
3453 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003454 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003455</ol>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003456<p><i>Ordered</i> means that neither operand is a QNAN while
Reid Spencer93a49852006-12-06 07:08:07 +00003457<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer350f8aa2007-01-04 05:19:58 +00003458<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3459<a href="#t_floating">floating point</a> typed. They must have identical
3460types.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003461<h5>Semantics:</h5>
3462<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3463the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencerc78f3372007-01-12 03:35:51 +00003464yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003465<ol>
3466 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003467 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003468 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003469 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003470 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003471 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003472 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003473 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003474 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003475 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003476 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003477 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003478 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003479 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3480 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003481 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003482 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003483 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003484 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003485 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003486 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003487 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003488 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003489 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003490 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003491 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003492 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003493 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3494</ol>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003495
3496<h5>Example:</h5>
3497<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3498 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3499 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3500 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3501</pre>
3502</div>
3503
Reid Spencer2fd21e62006-11-08 01:18:52 +00003504<!-- _______________________________________________________________________ -->
3505<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3506Instruction</a> </div>
3507<div class="doc_text">
3508<h5>Syntax:</h5>
3509<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3510<h5>Overview:</h5>
3511<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3512the SSA graph representing the function.</p>
3513<h5>Arguments:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003514<p>The type of the incoming values is specified with the first type
Reid Spencer2fd21e62006-11-08 01:18:52 +00003515field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3516as arguments, with one pair for each predecessor basic block of the
3517current block. Only values of <a href="#t_firstclass">first class</a>
3518type may be used as the value arguments to the PHI node. Only labels
3519may be used as the label arguments.</p>
3520<p>There must be no non-phi instructions between the start of a basic
3521block and the PHI instructions: i.e. PHI instructions must be first in
3522a basic block.</p>
3523<h5>Semantics:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003524<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
3525specified by the pair corresponding to the predecessor basic block that executed
3526just prior to the current block.</p>
Reid Spencer2fd21e62006-11-08 01:18:52 +00003527<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003528<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add i32 %indvar, 1<br> br label %Loop<br></pre>
Reid Spencer2fd21e62006-11-08 01:18:52 +00003529</div>
3530
Chris Lattnercc37aae2004-03-12 05:50:16 +00003531<!-- _______________________________________________________________________ -->
3532<div class="doc_subsubsection">
3533 <a name="i_select">'<tt>select</tt>' Instruction</a>
3534</div>
3535
3536<div class="doc_text">
3537
3538<h5>Syntax:</h5>
3539
3540<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003541 &lt;result&gt; = select i1 &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003542</pre>
3543
3544<h5>Overview:</h5>
3545
3546<p>
3547The '<tt>select</tt>' instruction is used to choose one value based on a
3548condition, without branching.
3549</p>
3550
3551
3552<h5>Arguments:</h5>
3553
3554<p>
3555The '<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.
3556</p>
3557
3558<h5>Semantics:</h5>
3559
3560<p>
3561If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00003562value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00003563</p>
3564
3565<h5>Example:</h5>
3566
3567<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003568 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003569</pre>
3570</div>
3571
Robert Bocchino05ccd702006-01-15 20:48:27 +00003572
3573<!-- _______________________________________________________________________ -->
3574<div class="doc_subsubsection">
Chris Lattner2bff5242005-05-06 05:47:36 +00003575 <a name="i_call">'<tt>call</tt>' Instruction</a>
3576</div>
3577
Misha Brukman9d0919f2003-11-08 01:05:38 +00003578<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00003579
Chris Lattner00950542001-06-06 20:29:01 +00003580<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003581<pre>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003582 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00003583</pre>
3584
Chris Lattner00950542001-06-06 20:29:01 +00003585<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003586
Misha Brukman9d0919f2003-11-08 01:05:38 +00003587<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003588
Chris Lattner00950542001-06-06 20:29:01 +00003589<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003590
Misha Brukman9d0919f2003-11-08 01:05:38 +00003591<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003592
Chris Lattner6536cfe2002-05-06 22:08:29 +00003593<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00003594 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003595 <p>The optional "tail" marker indicates whether the callee function accesses
3596 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00003597 function call is eligible for tail call optimization. Note that calls may
3598 be marked "tail" even if they do not occur before a <a
3599 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00003600 </li>
3601 <li>
Duncan Sands8036ca42007-03-30 12:22:09 +00003602 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003603 convention</a> the call should use. If none is specified, the call defaults
3604 to using C calling conventions.
3605 </li>
3606 <li>
Chris Lattner2bff5242005-05-06 05:47:36 +00003607 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
3608 being invoked. The argument types must match the types implied by this
John Criswellfc6b8952005-05-16 16:17:45 +00003609 signature. This type can be omitted if the function is not varargs and
3610 if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003611 </li>
3612 <li>
3613 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3614 be invoked. In most cases, this is a direct function invocation, but
3615 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00003616 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003617 </li>
3618 <li>
3619 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00003620 function signature argument types. All arguments must be of
3621 <a href="#t_firstclass">first class</a> type. If the function signature
3622 indicates the function accepts a variable number of arguments, the extra
3623 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003624 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00003625</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00003626
Chris Lattner00950542001-06-06 20:29:01 +00003627<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003628
Chris Lattner261efe92003-11-25 01:02:51 +00003629<p>The '<tt>call</tt>' instruction is used to cause control flow to
3630transfer to a specified function, with its incoming arguments bound to
3631the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3632instruction in the called function, control flow continues with the
3633instruction after the function call, and the return value of the
3634function is bound to the result argument. This is a simpler case of
3635the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003636
Chris Lattner00950542001-06-06 20:29:01 +00003637<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003638
3639<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003640 %retval = call i32 %test(i32 %argc)
Jeff Cohenb627eab2007-04-29 01:07:00 +00003641 call i32(i8 *, ...) *%printf(i8 * %msg, i32 12, i8 42);
Reid Spencerca86e162006-12-31 07:07:53 +00003642 %X = tail call i32 %foo()
3643 %Y = tail call <a href="#callingconv">fastcc</a> i32 %foo()
Chris Lattner2bff5242005-05-06 05:47:36 +00003644</pre>
3645
Misha Brukman9d0919f2003-11-08 01:05:38 +00003646</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003647
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003648<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00003649<div class="doc_subsubsection">
Chris Lattnerfb6977d2006-01-13 23:26:01 +00003650 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003651</div>
3652
Misha Brukman9d0919f2003-11-08 01:05:38 +00003653<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00003654
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003655<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003656
3657<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003658 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00003659</pre>
3660
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003661<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003662
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003663<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00003664the "variable argument" area of a function call. It is used to implement the
3665<tt>va_arg</tt> macro in C.</p>
3666
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003667<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003668
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003669<p>This instruction takes a <tt>va_list*</tt> value and the type of
3670the argument. It returns a value of the specified argument type and
Jeff Cohenb627eab2007-04-29 01:07:00 +00003671increments the <tt>va_list</tt> to point to the next argument. The
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003672actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003673
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003674<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003675
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003676<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3677type from the specified <tt>va_list</tt> and causes the
3678<tt>va_list</tt> to point to the next argument. For more information,
3679see the variable argument handling <a href="#int_varargs">Intrinsic
3680Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003681
3682<p>It is legal for this instruction to be called in a function which does not
3683take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003684function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003685
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003686<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00003687href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00003688argument.</p>
3689
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003690<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003691
3692<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3693
Misha Brukman9d0919f2003-11-08 01:05:38 +00003694</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003695
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003696<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00003697<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3698<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003699
Misha Brukman9d0919f2003-11-08 01:05:38 +00003700<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003701
3702<p>LLVM supports the notion of an "intrinsic function". These functions have
Reid Spencer409e28f2007-04-01 08:04:23 +00003703well known names and semantics and are required to follow certain restrictions.
3704Overall, these intrinsics represent an extension mechanism for the LLVM
Jeff Cohenb627eab2007-04-29 01:07:00 +00003705language that does not require changing all of the transformations in LLVM when
Gabor Greif04367bf2007-07-06 22:07:22 +00003706adding to the language (or the bitcode reader/writer, the parser, etc...).</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00003707
John Criswellfc6b8952005-05-16 16:17:45 +00003708<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Jeff Cohenb627eab2007-04-29 01:07:00 +00003709prefix is reserved in LLVM for intrinsic names; thus, function names may not
3710begin with this prefix. Intrinsic functions must always be external functions:
3711you cannot define the body of intrinsic functions. Intrinsic functions may
3712only be used in call or invoke instructions: it is illegal to take the address
3713of an intrinsic function. Additionally, because intrinsic functions are part
3714of the LLVM language, it is required if any are added that they be documented
3715here.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00003716
Jeff Cohenb627eab2007-04-29 01:07:00 +00003717<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents
Reid Spencer409e28f2007-04-01 08:04:23 +00003718a family of functions that perform the same operation but on different data
3719types. This is most frequent with the integer types. Since LLVM can represent
3720over 8 million different integer types, there is a way to declare an intrinsic
Jeff Cohenb627eab2007-04-29 01:07:00 +00003721that can be overloaded based on its arguments. Such an intrinsic will have the
3722names of its argument types encoded into its function name, each
Reid Spencer409e28f2007-04-01 08:04:23 +00003723preceded by a period. For example, the <tt>llvm.ctpop</tt> function can take an
3724integer of any width. This leads to a family of functions such as
3725<tt>i32 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i32 @llvm.ctpop.i29(i29 %val)</tt>.
3726</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00003727
Reid Spencer409e28f2007-04-01 08:04:23 +00003728
3729<p>To learn how to add an intrinsic function, please see the
3730<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00003731</p>
3732
Misha Brukman9d0919f2003-11-08 01:05:38 +00003733</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003734
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003735<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003736<div class="doc_subsection">
3737 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3738</div>
3739
Misha Brukman9d0919f2003-11-08 01:05:38 +00003740<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00003741
Misha Brukman9d0919f2003-11-08 01:05:38 +00003742<p>Variable argument support is defined in LLVM with the <a
Chris Lattnerfb6977d2006-01-13 23:26:01 +00003743 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner261efe92003-11-25 01:02:51 +00003744intrinsic functions. These functions are related to the similarly
3745named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003746
Chris Lattner261efe92003-11-25 01:02:51 +00003747<p>All of these functions operate on arguments that use a
3748target-specific value type "<tt>va_list</tt>". The LLVM assembly
3749language reference manual does not define what this type is, so all
Jeff Cohenb627eab2007-04-29 01:07:00 +00003750transformations should be prepared to handle these functions regardless of
3751the type used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003752
Chris Lattner374ab302006-05-15 17:26:46 +00003753<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00003754instruction and the variable argument handling intrinsic functions are
3755used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003756
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003757<div class="doc_code">
Chris Lattner33aec9e2004-02-12 17:01:32 +00003758<pre>
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00003759define i32 @test(i32 %X, ...) {
Chris Lattner33aec9e2004-02-12 17:01:32 +00003760 ; Initialize variable argument processing
Jeff Cohenb627eab2007-04-29 01:07:00 +00003761 %ap = alloca i8*
Chris Lattnerb75137d2007-01-08 07:55:15 +00003762 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00003763 call void @llvm.va_start(i8* %ap2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003764
3765 ; Read a single integer argument
Jeff Cohenb627eab2007-04-29 01:07:00 +00003766 %tmp = va_arg i8** %ap, i32
Chris Lattner33aec9e2004-02-12 17:01:32 +00003767
3768 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Jeff Cohenb627eab2007-04-29 01:07:00 +00003769 %aq = alloca i8*
Chris Lattnerb75137d2007-01-08 07:55:15 +00003770 %aq2 = bitcast i8** %aq to i8*
Jeff Cohenb627eab2007-04-29 01:07:00 +00003771 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00003772 call void @llvm.va_end(i8* %aq2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003773
3774 ; Stop processing of arguments.
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00003775 call void @llvm.va_end(i8* %ap2)
Reid Spencerca86e162006-12-31 07:07:53 +00003776 ret i32 %tmp
Chris Lattner33aec9e2004-02-12 17:01:32 +00003777}
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00003778
3779declare void @llvm.va_start(i8*)
3780declare void @llvm.va_copy(i8*, i8*)
3781declare void @llvm.va_end(i8*)
Chris Lattner33aec9e2004-02-12 17:01:32 +00003782</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003783</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003784
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003785</div>
3786
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003787<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003788<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003789 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00003790</div>
3791
3792
Misha Brukman9d0919f2003-11-08 01:05:38 +00003793<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003794<h5>Syntax:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003795<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003796<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003797<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3798<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3799href="#i_va_arg">va_arg</a></tt>.</p>
3800
3801<h5>Arguments:</h5>
3802
3803<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3804
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003805<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003806
3807<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3808macro available in C. In a target-dependent way, it initializes the
Jeff Cohenb627eab2007-04-29 01:07:00 +00003809<tt>va_list</tt> element to which the argument points, so that the next call to
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003810<tt>va_arg</tt> will produce the first variable argument passed to the function.
3811Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
Jeff Cohenb627eab2007-04-29 01:07:00 +00003812last argument of the function as the compiler can figure that out.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003813
Misha Brukman9d0919f2003-11-08 01:05:38 +00003814</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003815
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003816<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003817<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003818 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00003819</div>
3820
Misha Brukman9d0919f2003-11-08 01:05:38 +00003821<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003822<h5>Syntax:</h5>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00003823<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003824<h5>Overview:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003825
Jeff Cohenb627eab2007-04-29 01:07:00 +00003826<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Reid Spencera3e435f2007-04-04 02:42:35 +00003827which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
Chris Lattner261efe92003-11-25 01:02:51 +00003828or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003829
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003830<h5>Arguments:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003831
Jeff Cohenb627eab2007-04-29 01:07:00 +00003832<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003833
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003834<h5>Semantics:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003835
Misha Brukman9d0919f2003-11-08 01:05:38 +00003836<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003837macro available in C. In a target-dependent way, it destroys the
3838<tt>va_list</tt> element to which the argument points. Calls to <a
3839href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy">
3840<tt>llvm.va_copy</tt></a> must be matched exactly with calls to
3841<tt>llvm.va_end</tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00003842
Misha Brukman9d0919f2003-11-08 01:05:38 +00003843</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003844
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003845<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00003846<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003847 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00003848</div>
3849
Misha Brukman9d0919f2003-11-08 01:05:38 +00003850<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00003851
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003852<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003853
3854<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00003855 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00003856</pre>
3857
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003858<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003859
Jeff Cohenb627eab2007-04-29 01:07:00 +00003860<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
3861from the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003862
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003863<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003864
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003865<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00003866The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003867
Chris Lattnerd7923912004-05-23 21:06:01 +00003868
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003869<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00003870
Jeff Cohenb627eab2007-04-29 01:07:00 +00003871<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
3872macro available in C. In a target-dependent way, it copies the source
3873<tt>va_list</tt> element into the destination <tt>va_list</tt> element. This
3874intrinsic is necessary because the <tt><a href="#int_va_start">
3875llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for
3876example, memory allocation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003877
Misha Brukman9d0919f2003-11-08 01:05:38 +00003878</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00003879
Chris Lattner33aec9e2004-02-12 17:01:32 +00003880<!-- ======================================================================= -->
3881<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00003882 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
3883</div>
3884
3885<div class="doc_text">
3886
3887<p>
3888LLVM support for <a href="GarbageCollection.html">Accurate Garbage
3889Collection</a> requires the implementation and generation of these intrinsics.
Reid Spencera3e435f2007-04-04 02:42:35 +00003890These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
Chris Lattnerd7923912004-05-23 21:06:01 +00003891stack</a>, as well as garbage collector implementations that require <a
Reid Spencera3e435f2007-04-04 02:42:35 +00003892href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
Chris Lattnerd7923912004-05-23 21:06:01 +00003893Front-ends for type-safe garbage collected languages should generate these
3894intrinsics to make use of the LLVM garbage collectors. For more details, see <a
3895href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
3896</p>
3897</div>
3898
3899<!-- _______________________________________________________________________ -->
3900<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003901 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00003902</div>
3903
3904<div class="doc_text">
3905
3906<h5>Syntax:</h5>
3907
3908<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00003909 declare void @llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00003910</pre>
3911
3912<h5>Overview:</h5>
3913
John Criswell9e2485c2004-12-10 15:51:16 +00003914<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00003915the code generator, and allows some metadata to be associated with it.</p>
3916
3917<h5>Arguments:</h5>
3918
3919<p>The first argument specifies the address of a stack object that contains the
3920root pointer. The second pointer (which must be either a constant or a global
3921value address) contains the meta-data to be associated with the root.</p>
3922
3923<h5>Semantics:</h5>
3924
3925<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
3926location. At compile-time, the code generator generates information to allow
3927the runtime to find the pointer at GC safe points.
3928</p>
3929
3930</div>
3931
3932
3933<!-- _______________________________________________________________________ -->
3934<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003935 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00003936</div>
3937
3938<div class="doc_text">
3939
3940<h5>Syntax:</h5>
3941
3942<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00003943 declare i8 * @llvm.gcread(i8 * %ObjPtr, i8 ** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00003944</pre>
3945
3946<h5>Overview:</h5>
3947
3948<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3949locations, allowing garbage collector implementations that require read
3950barriers.</p>
3951
3952<h5>Arguments:</h5>
3953
Chris Lattner80626e92006-03-14 20:02:51 +00003954<p>The second argument is the address to read from, which should be an address
3955allocated from the garbage collector. The first object is a pointer to the
3956start of the referenced object, if needed by the language runtime (otherwise
3957null).</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003958
3959<h5>Semantics:</h5>
3960
3961<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3962instruction, but may be replaced with substantially more complex code by the
3963garbage collector runtime, as needed.</p>
3964
3965</div>
3966
3967
3968<!-- _______________________________________________________________________ -->
3969<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00003970 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00003971</div>
3972
3973<div class="doc_text">
3974
3975<h5>Syntax:</h5>
3976
3977<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00003978 declare void @llvm.gcwrite(i8 * %P1, i8 * %Obj, i8 ** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00003979</pre>
3980
3981<h5>Overview:</h5>
3982
3983<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3984locations, allowing garbage collector implementations that require write
3985barriers (such as generational or reference counting collectors).</p>
3986
3987<h5>Arguments:</h5>
3988
Chris Lattner80626e92006-03-14 20:02:51 +00003989<p>The first argument is the reference to store, the second is the start of the
3990object to store it to, and the third is the address of the field of Obj to
3991store to. If the runtime does not require a pointer to the object, Obj may be
3992null.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00003993
3994<h5>Semantics:</h5>
3995
3996<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3997instruction, but may be replaced with substantially more complex code by the
3998garbage collector runtime, as needed.</p>
3999
4000</div>
4001
4002
4003
4004<!-- ======================================================================= -->
4005<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00004006 <a name="int_codegen">Code Generator Intrinsics</a>
4007</div>
4008
4009<div class="doc_text">
4010<p>
4011These intrinsics are provided by LLVM to expose special features that may only
4012be implemented with code generator support.
4013</p>
4014
4015</div>
4016
4017<!-- _______________________________________________________________________ -->
4018<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004019 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner10610642004-02-14 04:08:35 +00004020</div>
4021
4022<div class="doc_text">
4023
4024<h5>Syntax:</h5>
4025<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004026 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004027</pre>
4028
4029<h5>Overview:</h5>
4030
4031<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00004032The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
4033target-specific value indicating the return address of the current function
4034or one of its callers.
Chris Lattner10610642004-02-14 04:08:35 +00004035</p>
4036
4037<h5>Arguments:</h5>
4038
4039<p>
4040The argument to this intrinsic indicates which function to return the address
4041for. Zero indicates the calling function, one indicates its caller, etc. The
4042argument is <b>required</b> to be a constant integer value.
4043</p>
4044
4045<h5>Semantics:</h5>
4046
4047<p>
4048The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
4049the return address of the specified call frame, or zero if it cannot be
4050identified. The value returned by this intrinsic is likely to be incorrect or 0
4051for arguments other than zero, so it should only be used for debugging purposes.
4052</p>
4053
4054<p>
4055Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00004056aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00004057source-language caller.
4058</p>
4059</div>
4060
4061
4062<!-- _______________________________________________________________________ -->
4063<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004064 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner10610642004-02-14 04:08:35 +00004065</div>
4066
4067<div class="doc_text">
4068
4069<h5>Syntax:</h5>
4070<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004071 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004072</pre>
4073
4074<h5>Overview:</h5>
4075
4076<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00004077The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
4078target-specific frame pointer value for the specified stack frame.
Chris Lattner10610642004-02-14 04:08:35 +00004079</p>
4080
4081<h5>Arguments:</h5>
4082
4083<p>
4084The argument to this intrinsic indicates which function to return the frame
4085pointer for. Zero indicates the calling function, one indicates its caller,
4086etc. The argument is <b>required</b> to be a constant integer value.
4087</p>
4088
4089<h5>Semantics:</h5>
4090
4091<p>
4092The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
4093the frame address of the specified call frame, or zero if it cannot be
4094identified. The value returned by this intrinsic is likely to be incorrect or 0
4095for arguments other than zero, so it should only be used for debugging purposes.
4096</p>
4097
4098<p>
4099Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00004100aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00004101source-language caller.
4102</p>
4103</div>
4104
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004105<!-- _______________________________________________________________________ -->
4106<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004107 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner57e1f392006-01-13 02:03:13 +00004108</div>
4109
4110<div class="doc_text">
4111
4112<h5>Syntax:</h5>
4113<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004114 declare i8 *@llvm.stacksave()
Chris Lattner57e1f392006-01-13 02:03:13 +00004115</pre>
4116
4117<h5>Overview:</h5>
4118
4119<p>
4120The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
Reid Spencera3e435f2007-04-04 02:42:35 +00004121the function stack, for use with <a href="#int_stackrestore">
Chris Lattner57e1f392006-01-13 02:03:13 +00004122<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
4123features like scoped automatic variable sized arrays in C99.
4124</p>
4125
4126<h5>Semantics:</h5>
4127
4128<p>
4129This intrinsic returns a opaque pointer value that can be passed to <a
Reid Spencera3e435f2007-04-04 02:42:35 +00004130href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
Chris Lattner57e1f392006-01-13 02:03:13 +00004131<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
4132<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
4133state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
4134practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
4135that were allocated after the <tt>llvm.stacksave</tt> was executed.
4136</p>
4137
4138</div>
4139
4140<!-- _______________________________________________________________________ -->
4141<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004142 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner57e1f392006-01-13 02:03:13 +00004143</div>
4144
4145<div class="doc_text">
4146
4147<h5>Syntax:</h5>
4148<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004149 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner57e1f392006-01-13 02:03:13 +00004150</pre>
4151
4152<h5>Overview:</h5>
4153
4154<p>
4155The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
4156the function stack to the state it was in when the corresponding <a
Reid Spencera3e435f2007-04-04 02:42:35 +00004157href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
Chris Lattner57e1f392006-01-13 02:03:13 +00004158useful for implementing language features like scoped automatic variable sized
4159arrays in C99.
4160</p>
4161
4162<h5>Semantics:</h5>
4163
4164<p>
Reid Spencera3e435f2007-04-04 02:42:35 +00004165See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
Chris Lattner57e1f392006-01-13 02:03:13 +00004166</p>
4167
4168</div>
4169
4170
4171<!-- _______________________________________________________________________ -->
4172<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004173 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004174</div>
4175
4176<div class="doc_text">
4177
4178<h5>Syntax:</h5>
4179<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004180 declare void @llvm.prefetch(i8 * &lt;address&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004181 i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004182</pre>
4183
4184<h5>Overview:</h5>
4185
4186
4187<p>
4188The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00004189a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
4190no
4191effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00004192characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004193</p>
4194
4195<h5>Arguments:</h5>
4196
4197<p>
4198<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
4199determining if the fetch should be for a read (0) or write (1), and
4200<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00004201locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004202<tt>locality</tt> arguments must be constant integers.
4203</p>
4204
4205<h5>Semantics:</h5>
4206
4207<p>
4208This intrinsic does not modify the behavior of the program. In particular,
4209prefetches cannot trap and do not produce a value. On targets that support this
4210intrinsic, the prefetch can provide hints to the processor cache for better
4211performance.
4212</p>
4213
4214</div>
4215
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004216<!-- _______________________________________________________________________ -->
4217<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004218 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004219</div>
4220
4221<div class="doc_text">
4222
4223<h5>Syntax:</h5>
4224<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004225 declare void @llvm.pcmarker( i32 &lt;id&gt; )
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004226</pre>
4227
4228<h5>Overview:</h5>
4229
4230
4231<p>
John Criswellfc6b8952005-05-16 16:17:45 +00004232The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4233(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004234code to simulators and other tools. The method is target specific, but it is
4235expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00004236The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnerd07c3f42005-11-15 06:07:55 +00004237after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb3e7afd2006-03-24 07:16:10 +00004238optimizations. The intended use is to be inserted after optimizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00004239correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004240</p>
4241
4242<h5>Arguments:</h5>
4243
4244<p>
4245<tt>id</tt> is a numerical id identifying the marker.
4246</p>
4247
4248<h5>Semantics:</h5>
4249
4250<p>
4251This intrinsic does not modify the behavior of the program. Backends that do not
4252support this intrinisic may ignore it.
4253</p>
4254
4255</div>
4256
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004257<!-- _______________________________________________________________________ -->
4258<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004259 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004260</div>
4261
4262<div class="doc_text">
4263
4264<h5>Syntax:</h5>
4265<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004266 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004267</pre>
4268
4269<h5>Overview:</h5>
4270
4271
4272<p>
4273The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4274counter register (or similar low latency, high accuracy clocks) on those targets
4275that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4276As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4277should only be used for small timings.
4278</p>
4279
4280<h5>Semantics:</h5>
4281
4282<p>
4283When directly supported, reading the cycle counter should not modify any memory.
4284Implementations are allowed to either return a application specific value or a
4285system wide value. On backends without support, this is lowered to a constant 0.
4286</p>
4287
4288</div>
4289
Chris Lattner10610642004-02-14 04:08:35 +00004290<!-- ======================================================================= -->
4291<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00004292 <a name="int_libc">Standard C Library Intrinsics</a>
4293</div>
4294
4295<div class="doc_text">
4296<p>
Chris Lattner10610642004-02-14 04:08:35 +00004297LLVM provides intrinsics for a few important standard C library functions.
4298These intrinsics allow source-language front-ends to pass information about the
4299alignment of the pointer arguments to the code generator, providing opportunity
4300for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004301</p>
4302
4303</div>
4304
4305<!-- _______________________________________________________________________ -->
4306<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004307 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattner33aec9e2004-02-12 17:01:32 +00004308</div>
4309
4310<div class="doc_text">
4311
4312<h5>Syntax:</h5>
4313<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004314 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004315 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004316 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004317 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004318</pre>
4319
4320<h5>Overview:</h5>
4321
4322<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004323The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004324location to the destination location.
4325</p>
4326
4327<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004328Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4329intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004330</p>
4331
4332<h5>Arguments:</h5>
4333
4334<p>
4335The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004336the source. The third argument is an integer argument
Chris Lattner33aec9e2004-02-12 17:01:32 +00004337specifying the number of bytes to copy, and the fourth argument is the alignment
4338of the source and destination locations.
4339</p>
4340
Chris Lattner3301ced2004-02-12 21:18:15 +00004341<p>
4342If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004343the caller guarantees that both the source and destination pointers are aligned
4344to that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004345</p>
4346
Chris Lattner33aec9e2004-02-12 17:01:32 +00004347<h5>Semantics:</h5>
4348
4349<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004350The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004351location to the destination location, which are not allowed to overlap. It
4352copies "len" bytes of memory over. If the argument is known to be aligned to
4353some boundary, this can be specified as the fourth argument, otherwise it should
4354be set to 0 or 1.
4355</p>
4356</div>
4357
4358
Chris Lattner0eb51b42004-02-12 18:10:10 +00004359<!-- _______________________________________________________________________ -->
4360<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004361 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattner0eb51b42004-02-12 18:10:10 +00004362</div>
4363
4364<div class="doc_text">
4365
4366<h5>Syntax:</h5>
4367<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004368 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004369 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004370 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004371 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00004372</pre>
4373
4374<h5>Overview:</h5>
4375
4376<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004377The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4378location to the destination location. It is similar to the
4379'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004380</p>
4381
4382<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004383Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4384intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004385</p>
4386
4387<h5>Arguments:</h5>
4388
4389<p>
4390The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004391the source. The third argument is an integer argument
Chris Lattner0eb51b42004-02-12 18:10:10 +00004392specifying the number of bytes to copy, and the fourth argument is the alignment
4393of the source and destination locations.
4394</p>
4395
Chris Lattner3301ced2004-02-12 21:18:15 +00004396<p>
4397If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004398the caller guarantees that the source and destination pointers are aligned to
4399that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004400</p>
4401
Chris Lattner0eb51b42004-02-12 18:10:10 +00004402<h5>Semantics:</h5>
4403
4404<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004405The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner0eb51b42004-02-12 18:10:10 +00004406location to the destination location, which may overlap. It
4407copies "len" bytes of memory over. If the argument is known to be aligned to
4408some boundary, this can be specified as the fourth argument, otherwise it should
4409be set to 0 or 1.
4410</p>
4411</div>
4412
Chris Lattner8ff75902004-01-06 05:31:32 +00004413
Chris Lattner10610642004-02-14 04:08:35 +00004414<!-- _______________________________________________________________________ -->
4415<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004416 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner10610642004-02-14 04:08:35 +00004417</div>
4418
4419<div class="doc_text">
4420
4421<h5>Syntax:</h5>
4422<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004423 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004424 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004425 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004426 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004427</pre>
4428
4429<h5>Overview:</h5>
4430
4431<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004432The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner10610642004-02-14 04:08:35 +00004433byte value.
4434</p>
4435
4436<p>
4437Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4438does not return a value, and takes an extra alignment argument.
4439</p>
4440
4441<h5>Arguments:</h5>
4442
4443<p>
4444The first argument is a pointer to the destination to fill, the second is the
Chris Lattner5b310c32006-03-03 00:07:20 +00004445byte value to fill it with, the third argument is an integer
Chris Lattner10610642004-02-14 04:08:35 +00004446argument specifying the number of bytes to fill, and the fourth argument is the
4447known alignment of destination location.
4448</p>
4449
4450<p>
4451If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004452the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner10610642004-02-14 04:08:35 +00004453</p>
4454
4455<h5>Semantics:</h5>
4456
4457<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004458The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4459the
Chris Lattner10610642004-02-14 04:08:35 +00004460destination location. If the argument is known to be aligned to some boundary,
4461this can be specified as the fourth argument, otherwise it should be set to 0 or
44621.
4463</p>
4464</div>
4465
4466
Chris Lattner32006282004-06-11 02:28:03 +00004467<!-- _______________________________________________________________________ -->
4468<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004469 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattnera4d74142005-07-21 01:29:16 +00004470</div>
4471
4472<div class="doc_text">
4473
4474<h5>Syntax:</h5>
4475<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004476 declare float @llvm.sqrt.f32(float %Val)
4477 declare double @llvm.sqrt.f64(double %Val)
Chris Lattnera4d74142005-07-21 01:29:16 +00004478</pre>
4479
4480<h5>Overview:</h5>
4481
4482<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004483The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattnera4d74142005-07-21 01:29:16 +00004484returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
4485<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
4486negative numbers (which allows for better optimization).
4487</p>
4488
4489<h5>Arguments:</h5>
4490
4491<p>
4492The argument and return value are floating point numbers of the same type.
4493</p>
4494
4495<h5>Semantics:</h5>
4496
4497<p>
Dan Gohmand6257fe2007-07-16 14:37:41 +00004498This function returns the sqrt of the specified operand if it is a nonnegative
Chris Lattnera4d74142005-07-21 01:29:16 +00004499floating point number.
4500</p>
4501</div>
4502
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004503<!-- _______________________________________________________________________ -->
4504<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004505 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004506</div>
4507
4508<div class="doc_text">
4509
4510<h5>Syntax:</h5>
4511<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004512 declare float @llvm.powi.f32(float %Val, i32 %power)
4513 declare double @llvm.powi.f64(double %Val, i32 %power)
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004514</pre>
4515
4516<h5>Overview:</h5>
4517
4518<p>
4519The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4520specified (positive or negative) power. The order of evaluation of
4521multiplications is not defined.
4522</p>
4523
4524<h5>Arguments:</h5>
4525
4526<p>
4527The second argument is an integer power, and the first is a value to raise to
4528that power.
4529</p>
4530
4531<h5>Semantics:</h5>
4532
4533<p>
4534This function returns the first value raised to the second power with an
4535unspecified sequence of rounding operations.</p>
4536</div>
4537
4538
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004539<!-- ======================================================================= -->
4540<div class="doc_subsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00004541 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004542</div>
4543
4544<div class="doc_text">
4545<p>
Nate Begeman7e36c472006-01-13 23:26:38 +00004546LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004547These allow efficient code generation for some algorithms.
4548</p>
4549
4550</div>
4551
4552<!-- _______________________________________________________________________ -->
4553<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004554 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman7e36c472006-01-13 23:26:38 +00004555</div>
4556
4557<div class="doc_text">
4558
4559<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00004560<p>This is an overloaded intrinsic function. You can use bswap on any integer
4561type that is an even number of bytes (i.e. BitWidth % 16 == 0). Note the suffix
4562that includes the type for the result and the operand.
Nate Begeman7e36c472006-01-13 23:26:38 +00004563<pre>
Reid Spencer409e28f2007-04-01 08:04:23 +00004564 declare i16 @llvm.bswap.i16.i16(i16 &lt;id&gt;)
4565 declare i32 @llvm.bswap.i32.i32(i32 &lt;id&gt;)
Reid Spencer543ab1d2007-04-02 00:19:52 +00004566 declare i64 @llvm.bswap.i64.i64(i64 &lt;id&gt;)
Nate Begeman7e36c472006-01-13 23:26:38 +00004567</pre>
4568
4569<h5>Overview:</h5>
4570
4571<p>
Reid Spencer338ea092007-04-02 02:25:19 +00004572The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
Reid Spencer409e28f2007-04-01 08:04:23 +00004573values with an even number of bytes (positive multiple of 16 bits). These are
4574useful for performing operations on data that is not in the target's native
4575byte order.
Nate Begeman7e36c472006-01-13 23:26:38 +00004576</p>
4577
4578<h5>Semantics:</h5>
4579
4580<p>
Reid Spencer409e28f2007-04-01 08:04:23 +00004581The <tt>llvm.bswap.16.i16</tt> intrinsic returns an i16 value that has the high
Reid Spencerca86e162006-12-31 07:07:53 +00004582and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
4583intrinsic returns an i32 value that has the four bytes of the input i32
4584swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Reid Spencer409e28f2007-04-01 08:04:23 +00004585i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48.i48</tt>,
4586<tt>llvm.bswap.i64.i64</tt> and other intrinsics extend this concept to
4587additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Nate Begeman7e36c472006-01-13 23:26:38 +00004588</p>
4589
4590</div>
4591
4592<!-- _______________________________________________________________________ -->
4593<div class="doc_subsubsection">
Reid Spencer0b118202006-01-16 21:12:35 +00004594 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004595</div>
4596
4597<div class="doc_text">
4598
4599<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00004600<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
4601width. Not all targets support all bit widths however.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004602<pre>
Reid Spencer409e28f2007-04-01 08:04:23 +00004603 declare i32 @llvm.ctpop.i8 (i8 &lt;src&gt;)
4604 declare i32 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004605 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Reid Spencer409e28f2007-04-01 08:04:23 +00004606 declare i32 @llvm.ctpop.i64(i64 &lt;src&gt;)
4607 declare i32 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004608</pre>
4609
4610<h5>Overview:</h5>
4611
4612<p>
Chris Lattnerec6cb612006-01-16 22:38:59 +00004613The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4614value.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004615</p>
4616
4617<h5>Arguments:</h5>
4618
4619<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00004620The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004621integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004622</p>
4623
4624<h5>Semantics:</h5>
4625
4626<p>
4627The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4628</p>
4629</div>
4630
4631<!-- _______________________________________________________________________ -->
4632<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00004633 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004634</div>
4635
4636<div class="doc_text">
4637
4638<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00004639<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
4640integer bit width. Not all targets support all bit widths however.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004641<pre>
Reid Spencer409e28f2007-04-01 08:04:23 +00004642 declare i32 @llvm.ctlz.i8 (i8 &lt;src&gt;)
4643 declare i32 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004644 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Reid Spencer409e28f2007-04-01 08:04:23 +00004645 declare i32 @llvm.ctlz.i64(i64 &lt;src&gt;)
4646 declare i32 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004647</pre>
4648
4649<h5>Overview:</h5>
4650
4651<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004652The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4653leading zeros in a variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004654</p>
4655
4656<h5>Arguments:</h5>
4657
4658<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00004659The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004660integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004661</p>
4662
4663<h5>Semantics:</h5>
4664
4665<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00004666The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4667in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerca86e162006-12-31 07:07:53 +00004668of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00004669</p>
4670</div>
Chris Lattner32006282004-06-11 02:28:03 +00004671
4672
Chris Lattnereff29ab2005-05-15 19:39:26 +00004673
4674<!-- _______________________________________________________________________ -->
4675<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00004676 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnereff29ab2005-05-15 19:39:26 +00004677</div>
4678
4679<div class="doc_text">
4680
4681<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00004682<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
4683integer bit width. Not all targets support all bit widths however.
Chris Lattnereff29ab2005-05-15 19:39:26 +00004684<pre>
Reid Spencer409e28f2007-04-01 08:04:23 +00004685 declare i32 @llvm.cttz.i8 (i8 &lt;src&gt;)
4686 declare i32 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004687 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Reid Spencer409e28f2007-04-01 08:04:23 +00004688 declare i32 @llvm.cttz.i64(i64 &lt;src&gt;)
4689 declare i32 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnereff29ab2005-05-15 19:39:26 +00004690</pre>
4691
4692<h5>Overview:</h5>
4693
4694<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004695The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
4696trailing zeros.
Chris Lattnereff29ab2005-05-15 19:39:26 +00004697</p>
4698
4699<h5>Arguments:</h5>
4700
4701<p>
4702The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00004703integer type. The return type must match the argument type.
Chris Lattnereff29ab2005-05-15 19:39:26 +00004704</p>
4705
4706<h5>Semantics:</h5>
4707
4708<p>
4709The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
4710in a variable. If the src == 0 then the result is the size in bits of the type
4711of src. For example, <tt>llvm.cttz(2) = 1</tt>.
4712</p>
4713</div>
4714
Reid Spencer497d93e2007-04-01 08:27:01 +00004715<!-- _______________________________________________________________________ -->
4716<div class="doc_subsubsection">
Reid Spencerbeacf662007-04-10 02:51:31 +00004717 <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a>
Reid Spencera13ba7d2007-04-01 19:00:37 +00004718</div>
4719
4720<div class="doc_text">
4721
4722<h5>Syntax:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00004723<p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt>
Reid Spencera13ba7d2007-04-01 19:00:37 +00004724on any integer bit width.
4725<pre>
Reid Spencerbeacf662007-04-10 02:51:31 +00004726 declare i17 @llvm.part.select.i17.i17 (i17 %val, i32 %loBit, i32 %hiBit)
4727 declare i29 @llvm.part.select.i29.i29 (i29 %val, i32 %loBit, i32 %hiBit)
Reid Spencera13ba7d2007-04-01 19:00:37 +00004728</pre>
4729
4730<h5>Overview:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00004731<p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a
Reid Spencera13ba7d2007-04-01 19:00:37 +00004732range of bits from an integer value and returns them in the same bit width as
4733the original value.</p>
4734
4735<h5>Arguments:</h5>
4736<p>The first argument, <tt>%val</tt> and the result may be integer types of
4737any bit width but they must have the same bit width. The second and third
Reid Spencera3e435f2007-04-04 02:42:35 +00004738arguments must be <tt>i32</tt> type since they specify only a bit index.</p>
Reid Spencera13ba7d2007-04-01 19:00:37 +00004739
4740<h5>Semantics:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00004741<p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes
Reid Spencera3e435f2007-04-04 02:42:35 +00004742of operation: forwards and reverse. If <tt>%loBit</tt> is greater than
4743<tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it
4744operates in forward mode.</p>
4745<p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt>
4746right by <tt>%loBit</tt> bits and then ANDing it with a mask with
Reid Spencera13ba7d2007-04-01 19:00:37 +00004747only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p>
4748<ol>
4749 <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified
4750 by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li>
4751 <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value
4752 to determine the number of bits to retain.</li>
4753 <li>A mask of the retained bits is created by shifting a -1 value.</li>
4754 <li>The mask is ANDed with <tt>%val</tt> to produce the result.
4755</ol>
Reid Spencerd6a85b52007-05-14 16:14:57 +00004756<p>In reverse mode, a similar computation is made except that the bits are
4757returned in the reverse order. So, for example, if <tt>X</tt> has the value
4758<tt>i16 0x0ACF (101011001111)</tt> and we apply
4759<tt>part.select(i16 X, 8, 3)</tt> to it, we get back the value
4760<tt>i16 0x0026 (000000100110)</tt>.</p>
Reid Spencera13ba7d2007-04-01 19:00:37 +00004761</div>
4762
Reid Spencerf86037f2007-04-11 23:23:49 +00004763<div class="doc_subsubsection">
4764 <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a>
4765</div>
4766
4767<div class="doc_text">
4768
4769<h5>Syntax:</h5>
4770<p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt>
4771on any integer bit width.
4772<pre>
4773 declare i17 @llvm.part.set.i17.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi)
4774 declare i29 @llvm.part.set.i29.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi)
4775</pre>
4776
4777<h5>Overview:</h5>
4778<p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range
4779of bits in an integer value with another integer value. It returns the integer
4780with the replaced bits.</p>
4781
4782<h5>Arguments:</h5>
4783<p>The first argument, <tt>%val</tt> and the result may be integer types of
4784any bit width but they must have the same bit width. <tt>%val</tt> is the value
4785whose bits will be replaced. The second argument, <tt>%repl</tt> may be an
4786integer of any bit width. The third and fourth arguments must be <tt>i32</tt>
4787type since they specify only a bit index.</p>
4788
4789<h5>Semantics:</h5>
4790<p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes
4791of operation: forwards and reverse. If <tt>%lo</tt> is greater than
4792<tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it
4793operates in forward mode.</p>
4794<p>For both modes, the <tt>%repl</tt> value is prepared for use by either
4795truncating it down to the size of the replacement area or zero extending it
4796up to that size.</p>
4797<p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive)
4798are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit
4799in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up
4800to the <tt>%hi</tt>th bit.
Reid Spencerc6749c42007-05-14 16:50:20 +00004801<p>In reverse mode, a similar computation is made except that the bits are
4802reversed. That is, the <tt>0</tt>th bit in <tt>%repl</tt> replaces the
4803<tt>%hi</tt> bit in <tt>%val</tt> and etc. down to the <tt>%lo</tt>th bit.
Reid Spencerf86037f2007-04-11 23:23:49 +00004804<h5>Examples:</h5>
4805<pre>
Reid Spencerf0dbf642007-04-12 01:03:03 +00004806 llvm.part.set(0xFFFF, 0, 4, 7) -&gt; 0xFF0F
Reid Spencerc6749c42007-05-14 16:50:20 +00004807 llvm.part.set(0xFFFF, 0, 7, 4) -&gt; 0xFF0F
4808 llvm.part.set(0xFFFF, 1, 7, 4) -&gt; 0xFF8F
4809 llvm.part.set(0xFFFF, F, 8, 3) -&gt; 0xFFE7
Reid Spencerf0dbf642007-04-12 01:03:03 +00004810 llvm.part.set(0xFFFF, 0, 3, 8) -&gt; 0xFE07
Reid Spencerc8910842007-04-11 23:49:50 +00004811</pre>
Reid Spencerf86037f2007-04-11 23:23:49 +00004812</div>
4813
Chris Lattner8ff75902004-01-06 05:31:32 +00004814<!-- ======================================================================= -->
4815<div class="doc_subsection">
4816 <a name="int_debugger">Debugger Intrinsics</a>
4817</div>
4818
4819<div class="doc_text">
4820<p>
4821The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
4822are described in the <a
4823href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
4824Debugging</a> document.
4825</p>
4826</div>
4827
4828
Jim Laskeydd4ef1b2007-03-14 19:31:19 +00004829<!-- ======================================================================= -->
4830<div class="doc_subsection">
4831 <a name="int_eh">Exception Handling Intrinsics</a>
4832</div>
4833
4834<div class="doc_text">
4835<p> The LLVM exception handling intrinsics (which all start with
4836<tt>llvm.eh.</tt> prefix), are described in the <a
4837href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
4838Handling</a> document. </p>
4839</div>
4840
Tanya Lattner6d806e92007-06-15 20:50:54 +00004841<!-- ======================================================================= -->
4842<div class="doc_subsection">
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004843 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
4844</div>
4845
4846<div class="doc_text">
4847<p>
4848 These intrinsic functions expand the "universal IR" of LLVM to represent
4849 hardware constructs for atomic operations and memory synchronization. This
4850 provides an interface to the hardware, not an interface to the programmer. It
4851 is aimed at a low enough level to allow any programming models or APIs which
4852 need atomic behaviors to map cleanly onto it. It is also modeled primarily on
Chandler Carruth6813c152007-07-20 20:14:52 +00004853 hardware behavior. Just as hardware provides a "universal IR" for source
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004854 languages, it also provides a starting point for developing a "universal"
4855 atomic operation and synchronization IR.
4856</p>
4857<p>
4858 These do <em>not</em> form an API such as high-level threading libraries,
4859 software transaction memory systems, atomic primitives, and intrinsic
Reid Spencer20677642007-07-20 19:59:11 +00004860 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004861 application libraries. The hardware interface provided by LLVM should allow
4862 a clean implementation of all of these APIs and parallel programming models.
4863 No one model or paradigm should be selected above others unless the hardware
4864 itself ubiquitously does so.
4865</p>
4866</div>
4867
4868<!-- _______________________________________________________________________ -->
4869<div class="doc_subsubsection">
4870 <a name="int_lcs">'<tt>llvm.atomic.lcs.*</tt>' Intrinsic</a>
4871</div>
4872<div class="doc_text">
4873<h5>Syntax:</h5>
4874<p>
4875 This is an overloaded intrinsic. You can use <tt>llvm.atomic.lcs</tt> on any
Reid Spencer20677642007-07-20 19:59:11 +00004876 integer bit width. Not all targets support all bit widths however.</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004877<pre>
4878declare i8 @llvm.atomic.lcs.i8.i8p.i8.i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
4879declare i16 @llvm.atomic.lcs.i16.i16p.i16.i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
4880declare i32 @llvm.atomic.lcs.i32.i32p.i32.i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
4881declare i64 @llvm.atomic.lcs.i64.i64p.i64.i64( i64* &lt;ptr&gt;, i64 &lt;cmp&gt;, i64 &lt;val&gt; )
4882</pre>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004883<h5>Overview:</h5>
4884<p>
Chandler Carruth6813c152007-07-20 20:14:52 +00004885 This loads a value in memory and compares it to a given value. If they are
4886 equal, it stores a new value into the memory.
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004887</p>
4888<h5>Arguments:</h5>
4889<p>
4890 The <tt>llvm.atomic.lcs</tt> intrinsic takes three arguments. The result as
4891 well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
4892 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
4893 this integer type. While any bit width integer may be used, targets may only
4894 lower representations they support in hardware.
4895</p>
4896<h5>Semantics:</h5>
4897<p>
4898 This entire intrinsic must be executed atomically. It first loads the value
Chandler Carruth6813c152007-07-20 20:14:52 +00004899 in memory pointed to by <tt>ptr</tt> and compares it with the value
4900 <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The
4901 loaded value is yielded in all cases. This provides the equivalent of an
4902 atomic compare-and-swap operation within the SSA framework.
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004903</p>
4904<h5>Examples:</h5>
4905<pre>
4906%ptr = malloc i32
4907 store i32 4, %ptr
4908
4909%val1 = add i32 4, 4
4910%result1 = call i32 @llvm.atomic.lcs( i32* %ptr, i32 4, %val1 )
4911 <i>; yields {i32}:result1 = 4</i>
4912%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
4913%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
4914
4915%val2 = add i32 1, 1
4916%result2 = call i32 @llvm.atomic.lcs( i32* %ptr, i32 5, %val2 )
4917 <i>; yields {i32}:result2 = 8</i>
4918%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
4919%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
4920</pre>
4921</div>
4922
4923<!-- _______________________________________________________________________ -->
4924<div class="doc_subsubsection">
4925 <a name="int_ls">'<tt>llvm.atomic.ls.*</tt>' Intrinsic</a>
4926</div>
4927<div class="doc_text">
4928<h5>Syntax:</h5>
4929<p>
4930 This is an overloaded intrinsic. You can use <tt>llvm.atomic.ls</tt> on any
Reid Spencer20677642007-07-20 19:59:11 +00004931 integer bit width. Not all targets support all bit widths however.</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004932<pre>
4933declare i8 @llvm.atomic.ls.i8.i8p.i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
4934declare i16 @llvm.atomic.ls.i16.i16p.i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
4935declare i32 @llvm.atomic.ls.i32.i32p.i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
4936declare i64 @llvm.atomic.ls.i64.i64p.i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
4937</pre>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004938<h5>Overview:</h5>
4939<p>
Chandler Carruth6813c152007-07-20 20:14:52 +00004940 This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
4941 the value from memory. It then stores the value in <tt>val</tt> in the memory
4942 at <tt>ptr</tt>.
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004943</p>
4944<h5>Arguments:</h5>
4945<p>
4946 The <tt>llvm.atomic.ls</tt> intrinsic takes two arguments. Both the
4947 <tt>val</tt> argument and the result must be integers of the same bit width.
4948 The first argument, <tt>ptr</tt>, must be a pointer to a value of this
4949 integer type. The targets may only lower integer representations they
4950 support.
4951</p>
4952<h5>Semantics:</h5>
4953<p>
4954 This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
4955 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
4956 equivalent of an atomic swap operation within the SSA framework.
4957</p>
4958<h5>Examples:</h5>
4959<pre>
4960%ptr = malloc i32
4961 store i32 4, %ptr
4962
4963%val1 = add i32 4, 4
4964%result1 = call i32 @llvm.atomic.ls( i32* %ptr, i32 %val1 )
4965 <i>; yields {i32}:result1 = 4</i>
4966%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
4967%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
4968
4969%val2 = add i32 1, 1
4970%result2 = call i32 @llvm.atomic.ls( i32* %ptr, i32 %val2 )
4971 <i>; yields {i32}:result2 = 8</i>
4972%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
4973%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
4974</pre>
4975 </div>
4976
4977<!-- _______________________________________________________________________ -->
4978<div class="doc_subsubsection">
4979 <a name="int_las">'<tt>llvm.atomic.las.*</tt>' Intrinsic</a>
4980</div>
4981<div class="doc_text">
4982<h5>Syntax:</h5>
4983<p>
4984 This is an overloaded intrinsic. You can use <tt>llvm.atomic.las</tt> on any
Reid Spencer20677642007-07-20 19:59:11 +00004985 integer bit width. Not all targets support all bit widths however.</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004986<pre>
4987declare i8 @llvm.atomic.las.i8.i8p.i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
4988declare i16 @llvm.atomic.las.i16.i16p.i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
4989declare i32 @llvm.atomic.las.i32.i32p.i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
4990declare i64 @llvm.atomic.las.i64.i64p.i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
4991</pre>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004992<h5>Overview:</h5>
4993<p>
Chandler Carruth6813c152007-07-20 20:14:52 +00004994 This intrinsic adds <tt>delta</tt> to the value stored in memory at
Chandler Carruth2eb93b32007-07-20 19:34:37 +00004995 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
4996</p>
4997<h5>Arguments:</h5>
4998<p>
4999 The intrinsic takes two arguments, the first a pointer to an integer value
5000 and the second an integer value. The result is also an integer value. These
5001 integer types can have any bit width, but they must all have the same bit
5002 width. The targets may only lower integer representations they support.
5003</p>
5004<h5>Semantics:</h5>
5005<p>
5006 This intrinsic does a series of operations atomically. It first loads the
5007 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
5008 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
5009</p>
5010<h5>Examples:</h5>
5011<pre>
5012%ptr = malloc i32
5013 store i32 4, %ptr
5014%result1 = call i32 @llvm.atomic.las( i32* %ptr, i32 4 )
5015 <i>; yields {i32}:result1 = 4</i>
5016%result2 = call i32 @llvm.atomic.las( i32* %ptr, i32 2 )
5017 <i>; yields {i32}:result2 = 8</i>
5018%result3 = call i32 @llvm.atomic.las( i32* %ptr, i32 5 )
5019 <i>; yields {i32}:result3 = 10</i>
5020%memval = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
5021</pre>
5022</div>
5023
5024<!-- _______________________________________________________________________ -->
5025<div class="doc_subsubsection">
5026 <a name="int_lss">'<tt>llvm.atomic.lss.*</tt>' Intrinsic</a>
5027</div>
5028<div class="doc_text">
5029<h5>Syntax:</h5>
5030<p>
5031 This is an overloaded intrinsic. You can use <tt>llvm.atomic.lss</tt> on any
Reid Spencer20677642007-07-20 19:59:11 +00005032 integer bit width. Not all targets support all bit widths however.</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005033<pre>
5034declare i8 @llvm.atomic.lss.i8.i8.i8( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
5035declare i16 @llvm.atomic.lss.i16.i16.i16( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
5036declare i32 @llvm.atomic.lss.i32.i32.i32( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
5037declare i64 @llvm.atomic.lss.i64.i64.i64( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
5038</pre>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005039<h5>Overview:</h5>
5040<p>
Chandler Carruth6813c152007-07-20 20:14:52 +00005041 This intrinsic subtracts <tt>delta</tt> from the value stored in memory at
5042 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005043</p>
5044<h5>Arguments:</h5>
5045<p>
5046 The intrinsic takes two arguments, the first a pointer to an integer value
5047 and the second an integer value. The result is also an integer value. These
5048 integer types can have any bit width, but they must all have the same bit
5049 width. The targets may only lower integer representations they support.
5050</p>
5051<h5>Semantics:</h5>
5052<p>
5053 This intrinsic does a series of operations atomically. It first loads the
5054 value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>,
5055 stores the result to <tt>ptr</tt>. It yields the original value stored
5056 at <tt>ptr</tt>.
5057</p>
5058<h5>Examples:</h5>
5059<pre>
5060%ptr = malloc i32
5061 store i32 32, %ptr
5062%result1 = call i32 @llvm.atomic.lss( i32* %ptr, i32 4 )
5063 <i>; yields {i32}:result1 = 32</i>
5064%result2 = call i32 @llvm.atomic.lss( i32* %ptr, i32 2 )
5065 <i>; yields {i32}:result2 = 28</i>
5066%result3 = call i32 @llvm.atomic.lss( i32* %ptr, i32 5 )
5067 <i>; yields {i32}:result3 = 26</i>
5068%memval = load i32* %ptr <i>; yields {i32}:memval1 = 21</i>
5069</pre>
5070</div>
5071
5072<!-- _______________________________________________________________________ -->
5073<div class="doc_subsubsection">
5074 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
5075</div>
5076<div class="doc_text">
5077<h5>Syntax:</h5>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005078<pre>
5079declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt; )
5080</pre>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005081<h5>Overview:</h5>
5082<p>
5083 The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
5084 specific pairs of memory access types.
5085</p>
5086<h5>Arguments:</h5>
5087<p>
5088 The <tt>llvm.memory.barrier</tt> intrinsic requires four boolean arguments.
5089 Each argument enables a specific barrier as listed below.
Reid Spencer1cff4082007-07-20 20:03:33 +00005090</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005091 <ul>
5092 <li><tt>ll</tt>: load-load barrier</li>
5093 <li><tt>ls</tt>: load-store barrier</li>
5094 <li><tt>sl</tt>: store-load barrier</li>
5095 <li><tt>ss</tt>: store-store barrier</li>
5096 </ul>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005097<h5>Semantics:</h5>
5098<p>
5099 This intrinsic causes the system to enforce some ordering constraints upon
5100 the loads and stores of the program. This barrier does not indicate
5101 <em>when</em> any events will occur, it only enforces an <em>order</em> in
5102 which they occur. For any of the specified pairs of load and store operations
5103 (f.ex. load-load, or store-load), all of the first operations preceding the
5104 barrier will complete before any of the second operations succeeding the
5105 barrier begin. Specifically the semantics for each pairing is as follows:
Reid Spencer1cff4082007-07-20 20:03:33 +00005106</p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005107 <ul>
5108 <li><tt>ll</tt>: All loads before the barrier must complete before any load
5109 after the barrier begins.</li>
5110 <li><tt>ls</tt>: All loads before the barrier must complete before any
5111 store after the barrier begins.</li>
5112 <li><tt>ss</tt>: All stores before the barrier must complete before any
5113 store after the barrier begins.</li>
5114 <li><tt>sl</tt>: All stores before the barrier must complete before any
5115 load after the barrier begins.</li>
5116 </ul>
Reid Spencer1cff4082007-07-20 20:03:33 +00005117<p>
Chandler Carruth2eb93b32007-07-20 19:34:37 +00005118 These semantics are applied with a logical "and" behavior when more than one
5119 is enabled in a single memory barrier intrinsic.
5120</p>
5121<h5>Example:</h5>
5122<pre>
5123%ptr = malloc i32
5124 store i32 4, %ptr
5125
5126%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
5127 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
5128 <i>; guarantee the above finishes</i>
5129 store i32 8, %ptr <i>; before this begins</i>
5130</pre>
5131</div>
5132
5133<!-- ======================================================================= -->
5134<div class="doc_subsection">
Duncan Sands36397f52007-07-27 12:58:54 +00005135 <a name="int_trampoline">Trampoline Intrinsics</a>
5136</div>
5137
5138<div class="doc_text">
5139<p>
5140 These intrinsics make it possible to excise one parameter, marked with
5141 the <tt>nest</tt> attribute, from a function. The result is a callable
5142 function pointer lacking the nest parameter - the caller does not need
5143 to provide a value for it. Instead, the value to use is stored in
5144 advance in a "trampoline", a block of memory usually allocated
5145 on the stack, which also contains code to splice the nest value into the
5146 argument list. This is used to implement the GCC nested function address
5147 extension.
5148</p>
5149<p>
5150 For example, if the function is
5151 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
5152 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as follows:
5153<pre>
5154 %tramp1 = alloca [10 x i8], align 4 ; size and alignment only correct for X86
5155 %tramp = getelementptr [10 x i8]* %tramp1, i32 0, i32 0
5156 call void @llvm.init.trampoline( i8* %tramp, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
5157 %adj = call i8* @llvm.adjust.trampoline( i8* %tramp )
5158 %fp = bitcast i8* %adj to i32 (i32, i32)*
5159</pre>
5160 The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent to
5161 <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.
5162</p>
5163<p>
5164 Trampolines are currently only supported on the X86 architecture.
5165</p>
5166</div>
5167
5168<!-- _______________________________________________________________________ -->
5169<div class="doc_subsubsection">
5170 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
5171</div>
5172<div class="doc_text">
5173<h5>Syntax:</h5>
5174<pre>
5175declare void @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
5176</pre>
5177<h5>Overview:</h5>
5178<p>
5179 This initializes the memory pointed to by <tt>tramp</tt> as a trampoline.
5180</p>
5181<h5>Arguments:</h5>
5182<p>
5183 The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
5184 pointers. The <tt>tramp</tt> argument must point to a sufficiently large
5185 and sufficiently aligned block of memory; this memory is written to by the
5186 intrinsic. Currently LLVM provides no help in determining just how big and
5187 aligned the memory needs to be. The <tt>func</tt> argument must hold a
5188 function bitcast to an <tt>i8*</tt>.
5189</p>
5190<h5>Semantics:</h5>
5191<p>
5192 The block of memory pointed to by <tt>tramp</tt> is filled with target
5193 dependent code, turning it into a function.
5194 The new function's signature is the same as that of <tt>func</tt> with
5195 any arguments marked with the <tt>nest</tt> attribute removed. At most
5196 one such <tt>nest</tt> argument is allowed, and it must be of pointer
5197 type. Calling the new function is equivalent to calling <tt>func</tt>
5198 with the same argument list, but with <tt>nval</tt> used for the missing
5199 <tt>nest</tt> argument.
5200</p>
5201</div>
5202
5203<!-- _______________________________________________________________________ -->
5204<div class="doc_subsubsection">
5205 <a name="int_at">'<tt>llvm.adjust.trampoline</tt>' Intrinsic</a>
5206</div>
5207<div class="doc_text">
5208<h5>Syntax:</h5>
5209<pre>
5210declare i8* @llvm.adjust.trampoline(i8* &lt;tramp&gt;)
5211</pre>
5212<h5>Overview:</h5>
5213<p>
5214 This intrinsic returns a function pointer suitable for executing
5215 the trampoline code pointed to by <tt>tramp</tt>.
5216</p>
5217<h5>Arguments:</h5>
5218<p>
5219 The <tt>llvm.adjust.trampoline</tt> takes one argument, a pointer to a
5220 trampoline initialized by the
5221 <a href="#int_it">'<tt>llvm.init.trampoline</tt>' intrinsic</a>.
5222</p>
5223<h5>Semantics:</h5>
5224<p>
5225 A function pointer that can be used to execute the trampoline code in
5226 <tt>tramp</tt> is returned. The returned value should be bitcast to an
5227 <a href="#int_trampoline">appropriate function pointer type</a>
5228 before being called.
5229</p>
5230</div>
5231
5232<!-- ======================================================================= -->
5233<div class="doc_subsection">
Tanya Lattner6d806e92007-06-15 20:50:54 +00005234 <a name="int_general">General Intrinsics</a>
5235</div>
5236
5237<div class="doc_text">
5238<p> This class of intrinsics is designed to be generic and has
5239no specific purpose. </p>
5240</div>
5241
5242<!-- _______________________________________________________________________ -->
5243<div class="doc_subsubsection">
5244 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
5245</div>
5246
5247<div class="doc_text">
5248
5249<h5>Syntax:</h5>
5250<pre>
Tanya Lattnerd2e84422007-06-18 23:42:37 +00005251 declare void @llvm.var.annotation(i8* &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
Tanya Lattner6d806e92007-06-15 20:50:54 +00005252</pre>
5253
5254<h5>Overview:</h5>
5255
5256<p>
5257The '<tt>llvm.var.annotation</tt>' intrinsic
5258</p>
5259
5260<h5>Arguments:</h5>
5261
5262<p>
Tanya Lattnerd2e84422007-06-18 23:42:37 +00005263The first argument is a pointer to a value, the second is a pointer to a
5264global string, the third is a pointer to a global string which is the source
5265file name, and the last argument is the line number.
Tanya Lattner6d806e92007-06-15 20:50:54 +00005266</p>
5267
5268<h5>Semantics:</h5>
5269
5270<p>
5271This intrinsic allows annotation of local variables with arbitrary strings.
5272This can be useful for special purpose optimizations that want to look for these
5273 annotations. These have no other defined use, they are ignored by code
5274 generation and optimization.
5275</div>
5276
Jim Laskeydd4ef1b2007-03-14 19:31:19 +00005277
Chris Lattner00950542001-06-06 20:29:01 +00005278<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00005279<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00005280<address>
5281 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
5282 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
5283 <a href="http://validator.w3.org/check/referer"><img
5284 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
5285
5286 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00005287 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00005288 Last modified: $Date$
5289</address>
Misha Brukman9d0919f2003-11-08 01:05:38 +00005290</body>
5291</html>