blob: 71f9c11117847931d0c0d49ca8552c2f38c6a3d2 [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>
Gordon Henriksen80a75bf2007-12-10 03:18:06 +000029 <li><a href="#gc">Garbage Collector Names</a></li>
Chris Lattner4e9aba72006-01-23 23:23:47 +000030 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Reid Spencerde151942007-02-19 23:54:10 +000031 <li><a href="#datalayout">Data Layout</a></li>
Chris Lattnerfa730212004-12-09 16:11:40 +000032 </ol>
33 </li>
Chris Lattner00950542001-06-06 20:29:01 +000034 <li><a href="#typesystem">Type System</a>
35 <ol>
Chris Lattner4f69f462008-01-04 04:32:38 +000036 <li><a href="#t_classifications">Type Classifications</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +000037 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner261efe92003-11-25 01:02:51 +000038 <ol>
Chris Lattner4f69f462008-01-04 04:32:38 +000039 <li><a href="#t_floating">Floating Point Types</a></li>
40 <li><a href="#t_void">Void Type</a></li>
41 <li><a href="#t_label">Label Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000042 </ol>
43 </li>
Chris Lattner00950542001-06-06 20:29:01 +000044 <li><a href="#t_derived">Derived Types</a>
45 <ol>
Chris Lattnerb9488a62007-12-18 06:18:21 +000046 <li><a href="#t_integer">Integer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000047 <li><a href="#t_array">Array Type</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000048 <li><a href="#t_function">Function Type</a></li>
49 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000050 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth75e10682006-12-08 17:13:00 +000051 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer485bad12007-02-15 03:07:05 +000052 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner69c11bb2005-04-25 17:34:15 +000053 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000054 </ol>
55 </li>
56 </ol>
57 </li>
Chris Lattnerfa730212004-12-09 16:11:40 +000058 <li><a href="#constants">Constants</a>
Chris Lattnerc3f59762004-12-09 17:30:23 +000059 <ol>
60 <li><a href="#simpleconstants">Simple Constants</a>
61 <li><a href="#aggregateconstants">Aggregate Constants</a>
62 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
63 <li><a href="#undefvalues">Undefined Values</a>
64 <li><a href="#constantexprs">Constant Expressions</a>
65 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +000066 </li>
Chris Lattnere87d6532006-01-25 23:47:57 +000067 <li><a href="#othervalues">Other Values</a>
68 <ol>
69 <li><a href="#inlineasm">Inline Assembler Expressions</a>
70 </ol>
71 </li>
Chris Lattner00950542001-06-06 20:29:01 +000072 <li><a href="#instref">Instruction Reference</a>
73 <ol>
74 <li><a href="#terminators">Terminator Instructions</a>
75 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000076 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
77 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +000078 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
79 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000080 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner35eca582004-10-16 18:04:13 +000081 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000082 </ol>
83 </li>
Chris Lattner00950542001-06-06 20:29:01 +000084 <li><a href="#binaryops">Binary Operations</a>
85 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +000086 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
87 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
88 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer1628cec2006-10-26 06:15:43 +000089 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
90 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
91 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer0a783f72006-11-02 01:53:59 +000092 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
93 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
94 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +000095 </ol>
96 </li>
Chris Lattner00950542001-06-06 20:29:01 +000097 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
98 <ol>
Reid Spencer8e11bf82007-02-02 13:57:07 +000099 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
100 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
101 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000102 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000103 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000104 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000105 </ol>
106 </li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000107 <li><a href="#vectorops">Vector Operations</a>
108 <ol>
109 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
110 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
111 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattner3df241e2006-04-08 23:07:04 +0000112 </ol>
113 </li>
Chris Lattner884a9702006-08-15 00:45:58 +0000114 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner00950542001-06-06 20:29:01 +0000115 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000116 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
117 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
118 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino7b81c752006-02-17 21:18:08 +0000119 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
120 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
121 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000122 </ol>
123 </li>
Reid Spencer2fd21e62006-11-08 01:18:52 +0000124 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000125 <ol>
126 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
127 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
128 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
129 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
130 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencerd4448792006-11-09 23:03:26 +0000131 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
132 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
133 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
134 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencer72679252006-11-11 21:00:47 +0000135 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
136 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5c0ef472006-11-11 23:08:07 +0000137 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer9dee3ac2006-11-08 01:11:31 +0000138 </ol>
Chris Lattner00950542001-06-06 20:29:01 +0000139 <li><a href="#otherops">Other Operations</a>
140 <ol>
Reid Spencerf3a70a62006-11-18 21:50:54 +0000141 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
142 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Nate Begemanac80ade2008-05-12 19:01:56 +0000143 <li><a href="#i_vicmp">'<tt>vicmp</tt>' Instruction</a></li>
144 <li><a href="#i_vfcmp">'<tt>vfcmp</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000145 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnercc37aae2004-03-12 05:50:16 +0000146 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000147 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattnerfb6977d2006-01-13 23:26:01 +0000148 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Devang Patelc3fc6df2008-03-10 20:49:15 +0000149 <li><a href="#i_getresult">'<tt>getresult</tt>' Instruction</a></li>
Chris Lattner00950542001-06-06 20:29:01 +0000150 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000151 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000152 </ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000153 </li>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000154 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +0000155 <ol>
Chris Lattner261efe92003-11-25 01:02:51 +0000156 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
157 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000158 <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
159 <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
160 <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
Chris Lattner261efe92003-11-25 01:02:51 +0000161 </ol>
162 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000163 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
164 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000165 <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
166 <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
167 <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000168 </ol>
169 </li>
Chris Lattner10610642004-02-14 04:08:35 +0000170 <li><a href="#int_codegen">Code Generator Intrinsics</a>
171 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000172 <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
173 <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
174 <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
175 <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
176 <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
177 <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
178 <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswell7123e272004-04-09 16:43:20 +0000179 </ol>
180 </li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000181 <li><a href="#int_libc">Standard C Library Intrinsics</a>
182 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000183 <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
184 <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
185 <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
186 <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
187 <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Dan Gohman91c284c2007-10-15 20:30:11 +0000188 <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li>
189 <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li>
190 <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li>
Chris Lattner33aec9e2004-02-12 17:01:32 +0000191 </ol>
192 </li>
Nate Begeman7e36c472006-01-13 23:26:38 +0000193 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000194 <ol>
Reid Spencera3e435f2007-04-04 02:42:35 +0000195 <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattner8a886be2006-01-16 22:34:14 +0000196 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
197 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
198 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Reid Spencerf86037f2007-04-11 23:23:49 +0000199 <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li>
200 <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li>
Andrew Lenharthec370fd2005-05-03 18:01:48 +0000201 </ol>
202 </li>
Chris Lattnerd7923912004-05-23 21:06:01 +0000203 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Jim Laskeydd4ef1b2007-03-14 19:31:19 +0000204 <li><a href="#int_eh">Exception Handling intrinsics</a></li>
Duncan Sandsf7331b32007-09-11 14:10:23 +0000205 <li><a href="#int_trampoline">Trampoline Intrinsic</a>
Duncan Sands36397f52007-07-27 12:58:54 +0000206 <ol>
207 <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li>
Duncan Sands36397f52007-07-27 12:58:54 +0000208 </ol>
209 </li>
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +0000210 <li><a href="#int_atomics">Atomic intrinsics</a>
211 <ol>
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000212 <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li>
213 <li><a href="#int_atomic_lcs"><tt>llvm.atomic.lcs</tt></a></li>
214 <li><a href="#int_atomic_las"><tt>llvm.atomic.las</tt></a></li>
215 <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li>
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +0000216 </ol>
217 </li>
Reid Spencer20677642007-07-20 19:59:11 +0000218 <li><a href="#int_general">General intrinsics</a>
Tanya Lattner6d806e92007-06-15 20:50:54 +0000219 <ol>
Reid Spencer20677642007-07-20 19:59:11 +0000220 <li><a href="#int_var_annotation">
Tanya Lattner91d0b882007-09-22 00:01:26 +0000221 <tt>llvm.var.annotation</tt>' Intrinsic</a></li>
Tanya Lattnerb6367882007-09-21 22:59:12 +0000222 <li><a href="#int_annotation">
Tanya Lattner91d0b882007-09-22 00:01:26 +0000223 <tt>llvm.annotation.*</tt>' Intrinsic</a></li>
Anton Korobeynikov4cb86182008-01-15 22:31:34 +0000224 <li><a href="#int_trap">
225 <tt>llvm.trap</tt>' Intrinsic</a></li>
Tanya Lattnerb6367882007-09-21 22:59:12 +0000226 </ol>
Tanya Lattner6d806e92007-06-15 20:50:54 +0000227 </li>
Chris Lattner261efe92003-11-25 01:02:51 +0000228 </ol>
229 </li>
Chris Lattner00950542001-06-06 20:29:01 +0000230</ol>
Chris Lattnerd7923912004-05-23 21:06:01 +0000231
232<div class="doc_author">
233 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
234 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></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="abstract">Abstract </a></div>
239<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000240
Misha Brukman9d0919f2003-11-08 01:05:38 +0000241<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +0000242<p>This document is a reference manual for the LLVM assembly language.
243LLVM is an SSA based representation that provides type safety,
244low-level operations, flexibility, and the capability of representing
245'all' high-level languages cleanly. It is the common code
246representation used throughout all phases of the LLVM compilation
247strategy.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000248</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000249
Chris Lattner00950542001-06-06 20:29:01 +0000250<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000251<div class="doc_section"> <a name="introduction">Introduction</a> </div>
252<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000253
Misha Brukman9d0919f2003-11-08 01:05:38 +0000254<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000255
Chris Lattner261efe92003-11-25 01:02:51 +0000256<p>The LLVM code representation is designed to be used in three
Gabor Greif04367bf2007-07-06 22:07:22 +0000257different forms: as an in-memory compiler IR, as an on-disk bitcode
Chris Lattner261efe92003-11-25 01:02:51 +0000258representation (suitable for fast loading by a Just-In-Time compiler),
259and as a human readable assembly language representation. This allows
260LLVM to provide a powerful intermediate representation for efficient
261compiler transformations and analysis, while providing a natural means
262to debug and visualize the transformations. The three different forms
263of LLVM are all equivalent. This document describes the human readable
264representation and notation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000265
John Criswellc1f786c2005-05-13 22:25:59 +0000266<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner261efe92003-11-25 01:02:51 +0000267while being expressive, typed, and extensible at the same time. It
268aims to be a "universal IR" of sorts, by being at a low enough level
269that high-level ideas may be cleanly mapped to it (similar to how
270microprocessors are "universal IR's", allowing many source languages to
271be mapped to them). By providing type information, LLVM can be used as
272the target of optimizations: for example, through pointer analysis, it
273can be proven that a C automatic variable is never accessed outside of
274the current function... allowing it to be promoted to a simple SSA
275value instead of a memory location.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000276
Misha Brukman9d0919f2003-11-08 01:05:38 +0000277</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000278
Chris Lattner00950542001-06-06 20:29:01 +0000279<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +0000280<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000281
Misha Brukman9d0919f2003-11-08 01:05:38 +0000282<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000283
Chris Lattner261efe92003-11-25 01:02:51 +0000284<p>It is important to note that this document describes 'well formed'
285LLVM assembly language. There is a difference between what the parser
286accepts and what is considered 'well formed'. For example, the
287following instruction is syntactically okay, but not well formed:</p>
Chris Lattnerd7923912004-05-23 21:06:01 +0000288
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000289<div class="doc_code">
Chris Lattnerd7923912004-05-23 21:06:01 +0000290<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000291%x = <a href="#i_add">add</a> i32 1, %x
Chris Lattnerd7923912004-05-23 21:06:01 +0000292</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000293</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000294
Chris Lattner261efe92003-11-25 01:02:51 +0000295<p>...because the definition of <tt>%x</tt> does not dominate all of
296its uses. The LLVM infrastructure provides a verification pass that may
297be used to verify that an LLVM module is well formed. This pass is
John Criswellc1f786c2005-05-13 22:25:59 +0000298automatically run by the parser after parsing input assembly and by
Gabor Greif04367bf2007-07-06 22:07:22 +0000299the optimizer before it outputs bitcode. The violations pointed out
Chris Lattner261efe92003-11-25 01:02:51 +0000300by the verifier pass indicate bugs in transformation passes or input to
301the parser.</p>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000302</div>
Chris Lattnerd7923912004-05-23 21:06:01 +0000303
Chris Lattnercc689392007-10-03 17:34:29 +0000304<!-- Describe the typesetting conventions here. -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000305
Chris Lattner00950542001-06-06 20:29:01 +0000306<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000307<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner00950542001-06-06 20:29:01 +0000308<!-- *********************************************************************** -->
Chris Lattnerd7923912004-05-23 21:06:01 +0000309
Misha Brukman9d0919f2003-11-08 01:05:38 +0000310<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +0000311
Reid Spencer2c452282007-08-07 14:34:28 +0000312 <p>LLVM identifiers come in two basic types: global and local. Global
313 identifiers (functions, global variables) begin with the @ character. Local
314 identifiers (register names, types) begin with the % character. Additionally,
315 there are three different formats for identifiers, for different purposes:
Chris Lattnerd7923912004-05-23 21:06:01 +0000316
Chris Lattner00950542001-06-06 20:29:01 +0000317<ol>
Reid Spencer2c452282007-08-07 14:34:28 +0000318 <li>Named values are represented as a string of characters with their prefix.
319 For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual
320 regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
Chris Lattnere5d947b2004-12-09 16:36:40 +0000321 Identifiers which require other characters in their names can be surrounded
Reid Spencer2c452282007-08-07 14:34:28 +0000322 with quotes. In this way, anything except a <tt>&quot;</tt> character can
323 be used in a named value.</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000324
Reid Spencer2c452282007-08-07 14:34:28 +0000325 <li>Unnamed values are represented as an unsigned numeric value with their
326 prefix. For example, %12, @2, %44.</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000327
Reid Spencercc16dc32004-12-09 18:02:53 +0000328 <li>Constants, which are described in a <a href="#constants">section about
329 constants</a>, below.</li>
Misha Brukman9d0919f2003-11-08 01:05:38 +0000330</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000331
Reid Spencer2c452282007-08-07 14:34:28 +0000332<p>LLVM requires that values start with a prefix for two reasons: Compilers
Chris Lattnere5d947b2004-12-09 16:36:40 +0000333don't need to worry about name clashes with reserved words, and the set of
334reserved words may be expanded in the future without penalty. Additionally,
335unnamed identifiers allow a compiler to quickly come up with a temporary
336variable without having to avoid symbol table conflicts.</p>
337
Chris Lattner261efe92003-11-25 01:02:51 +0000338<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5c0ef472006-11-11 23:08:07 +0000339languages. There are keywords for different opcodes
340('<tt><a href="#i_add">add</a></tt>',
341 '<tt><a href="#i_bitcast">bitcast</a></tt>',
342 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerca86e162006-12-31 07:07:53 +0000343href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnere5d947b2004-12-09 16:36:40 +0000344and others. These reserved words cannot conflict with variable names, because
Reid Spencer2c452282007-08-07 14:34:28 +0000345none of them start with a prefix character ('%' or '@').</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000346
347<p>Here is an example of LLVM code to multiply the integer variable
348'<tt>%X</tt>' by 8:</p>
349
Misha Brukman9d0919f2003-11-08 01:05:38 +0000350<p>The easy way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000351
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000352<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000353<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000354%result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnere5d947b2004-12-09 16:36:40 +0000355</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000356</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000357
Misha Brukman9d0919f2003-11-08 01:05:38 +0000358<p>After strength reduction:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000359
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000360<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000361<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000362%result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnere5d947b2004-12-09 16:36:40 +0000363</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000364</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000365
Misha Brukman9d0919f2003-11-08 01:05:38 +0000366<p>And the hard way:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000367
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000368<div class="doc_code">
Chris Lattnere5d947b2004-12-09 16:36:40 +0000369<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000370<a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
371<a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
372%result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnere5d947b2004-12-09 16:36:40 +0000373</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000374</div>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000375
Chris Lattner261efe92003-11-25 01:02:51 +0000376<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
377important lexical features of LLVM:</p>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000378
Chris Lattner00950542001-06-06 20:29:01 +0000379<ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000380
381 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
382 line.</li>
383
384 <li>Unnamed temporaries are created when the result of a computation is not
385 assigned to a named value.</li>
386
Misha Brukman9d0919f2003-11-08 01:05:38 +0000387 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000388
Misha Brukman9d0919f2003-11-08 01:05:38 +0000389</ol>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000390
John Criswelle4c57cc2005-05-12 16:52:32 +0000391<p>...and it also shows a convention that we follow in this document. When
Chris Lattnere5d947b2004-12-09 16:36:40 +0000392demonstrating instructions, we will follow an instruction with a comment that
393defines the type and name of value produced. Comments are shown in italic
394text.</p>
395
Misha Brukman9d0919f2003-11-08 01:05:38 +0000396</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000397
398<!-- *********************************************************************** -->
399<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
400<!-- *********************************************************************** -->
401
402<!-- ======================================================================= -->
403<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
404</div>
405
406<div class="doc_text">
407
408<p>LLVM programs are composed of "Module"s, each of which is a
409translation unit of the input programs. Each module consists of
410functions, global variables, and symbol table entries. Modules may be
411combined together with the LLVM linker, which merges function (and
412global variable) definitions, resolves forward declarations, and merges
413symbol table entries. Here is an example of the "hello world" module:</p>
414
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000415<div class="doc_code">
Chris Lattnerfa730212004-12-09 16:11:40 +0000416<pre><i>; Declare the string constant as a global constant...</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000417<a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a
418 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 +0000419
420<i>; External declaration of the puts function</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000421<a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000422
423<i>; Definition of main function</i>
Chris Lattnera89e5f12007-06-12 17:00:26 +0000424define i32 @main() { <i>; i32()* </i>
Reid Spencerca86e162006-12-31 07:07:53 +0000425 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000426 %cast210 = <a
Chris Lattner6c0955b2007-06-12 17:01:15 +0000427 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* @.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000428
429 <i>; Call puts function to write out the string to stdout...</i>
430 <a
Chris Lattnera89e5f12007-06-12 17:00:26 +0000431 href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i>
Chris Lattnerfa730212004-12-09 16:11:40 +0000432 <a
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000433 href="#i_ret">ret</a> i32 0<br>}<br>
434</pre>
435</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000436
437<p>This example is made up of a <a href="#globalvars">global variable</a>
438named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
439function, and a <a href="#functionstructure">function definition</a>
440for "<tt>main</tt>".</p>
441
Chris Lattnere5d947b2004-12-09 16:36:40 +0000442<p>In general, a module is made up of a list of global values,
443where both functions and global variables are global values. Global values are
444represented by a pointer to a memory location (in this case, a pointer to an
445array of char, and a pointer to a function), and have one of the following <a
446href="#linkage">linkage types</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000447
Chris Lattnere5d947b2004-12-09 16:36:40 +0000448</div>
449
450<!-- ======================================================================= -->
451<div class="doc_subsection">
452 <a name="linkage">Linkage Types</a>
453</div>
454
455<div class="doc_text">
456
457<p>
458All Global Variables and Functions have one of the following types of linkage:
459</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000460
461<dl>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000462
Chris Lattnerfa730212004-12-09 16:11:40 +0000463 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000464
465 <dd>Global values with internal linkage are only directly accessible by
466 objects in the current module. In particular, linking code into a module with
467 an internal global value may cause the internal to be renamed as necessary to
468 avoid collisions. Because the symbol is internal to the module, all
469 references can be updated. This corresponds to the notion of the
Chris Lattner4887bd82007-01-14 06:51:48 +0000470 '<tt>static</tt>' keyword in C.
Chris Lattnerfa730212004-12-09 16:11:40 +0000471 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000472
Chris Lattnerfa730212004-12-09 16:11:40 +0000473 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000474
Chris Lattner4887bd82007-01-14 06:51:48 +0000475 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
476 the same name when linkage occurs. This is typically used to implement
477 inline functions, templates, or other code which must be generated in each
478 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
479 allowed to be discarded.
Chris Lattnerfa730212004-12-09 16:11:40 +0000480 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000481
Chris Lattnerfa730212004-12-09 16:11:40 +0000482 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000483
484 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
485 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattner4887bd82007-01-14 06:51:48 +0000486 used for globals that may be emitted in multiple translation units, but that
487 are not guaranteed to be emitted into every translation unit that uses them.
488 One example of this are common globals in C, such as "<tt>int X;</tt>" at
489 global scope.
Chris Lattnerfa730212004-12-09 16:11:40 +0000490 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000491
Chris Lattnerfa730212004-12-09 16:11:40 +0000492 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000493
494 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
495 pointer to array type. When two global variables with appending linkage are
496 linked together, the two global arrays are appended together. This is the
497 LLVM, typesafe, equivalent of having the system linker append together
498 "sections" with identical names when .o files are linked.
Chris Lattnerfa730212004-12-09 16:11:40 +0000499 </dd>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000500
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000501 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
502 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
503 until linked, if not linked, the symbol becomes null instead of being an
504 undefined reference.
505 </dd>
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000506
Chris Lattnerfa730212004-12-09 16:11:40 +0000507 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnere5d947b2004-12-09 16:36:40 +0000508
509 <dd>If none of the above identifiers are used, the global is externally
510 visible, meaning that it participates in linkage and can be used to resolve
511 external symbol references.
Chris Lattnerfa730212004-12-09 16:11:40 +0000512 </dd>
Reid Spencerc8910842007-04-11 23:49:50 +0000513</dl>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000514
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000515 <p>
516 The next two types of linkage are targeted for Microsoft Windows platform
517 only. They are designed to support importing (exporting) symbols from (to)
518 DLLs.
519 </p>
520
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000521 <dl>
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000522 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
523
524 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
525 or variable via a global pointer to a pointer that is set up by the DLL
526 exporting the symbol. On Microsoft Windows targets, the pointer name is
527 formed by combining <code>_imp__</code> and the function or variable name.
528 </dd>
529
530 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
531
532 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
533 pointer to a pointer in a DLL, so that it can be referenced with the
534 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
535 name is formed by combining <code>_imp__</code> and the function or variable
536 name.
537 </dd>
538
Chris Lattnerfa730212004-12-09 16:11:40 +0000539</dl>
540
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000541<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattnerfa730212004-12-09 16:11:40 +0000542variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
543variable and was linked with this one, one of the two would be renamed,
544preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
545external (i.e., lacking any linkage declarations), they are accessible
Reid Spencerac8d2762007-01-05 00:59:10 +0000546outside of the current module.</p>
547<p>It is illegal for a function <i>declaration</i>
548to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000549or <tt>extern_weak</tt>.</p>
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000550<p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt>
551linkages.
Chris Lattnerfa730212004-12-09 16:11:40 +0000552</div>
553
554<!-- ======================================================================= -->
555<div class="doc_subsection">
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000556 <a name="callingconv">Calling Conventions</a>
557</div>
558
559<div class="doc_text">
560
561<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
562and <a href="#i_invoke">invokes</a> can all have an optional calling convention
563specified for the call. The calling convention of any pair of dynamic
564caller/callee must match, or the behavior of the program is undefined. The
565following calling conventions are supported by LLVM, and more may be added in
566the future:</p>
567
568<dl>
569 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
570
571 <dd>This calling convention (the default if no other calling convention is
572 specified) matches the target C calling conventions. This calling convention
John Criswelle4c57cc2005-05-12 16:52:32 +0000573 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencerc28d2bc2006-12-31 21:30:18 +0000574 prototype and implemented declaration of the function (as does normal C).
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000575 </dd>
576
577 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
578
579 <dd>This calling convention attempts to make calls as fast as possible
580 (e.g. by passing things in registers). This calling convention allows the
581 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattner8cdc5bc2005-05-06 23:08:23 +0000582 without having to conform to an externally specified ABI. Implementations of
583 this convention should allow arbitrary tail call optimization to be supported.
584 This calling convention does not support varargs and requires the prototype of
585 all callees to exactly match the prototype of the function definition.
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000586 </dd>
587
588 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
589
590 <dd>This calling convention attempts to make code in the caller as efficient
591 as possible under the assumption that the call is not commonly executed. As
592 such, these calls often preserve all registers so that the call does not break
593 any live ranges in the caller side. This calling convention does not support
594 varargs and requires the prototype of all callees to exactly match the
595 prototype of the function definition.
596 </dd>
597
Chris Lattnercfe6b372005-05-07 01:46:40 +0000598 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000599
600 <dd>Any calling convention may be specified by number, allowing
601 target-specific calling conventions to be used. Target specific calling
602 conventions start at 64.
603 </dd>
Chris Lattnercfe6b372005-05-07 01:46:40 +0000604</dl>
Chris Lattnerbad10ee2005-05-06 22:57:40 +0000605
606<p>More calling conventions can be added/defined on an as-needed basis, to
607support pascal conventions or any other well-known target-independent
608convention.</p>
609
610</div>
611
612<!-- ======================================================================= -->
613<div class="doc_subsection">
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000614 <a name="visibility">Visibility Styles</a>
615</div>
616
617<div class="doc_text">
618
619<p>
620All Global Variables and Functions have one of the following visibility styles:
621</p>
622
623<dl>
624 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
625
626 <dd>On ELF, default visibility means that the declaration is visible to other
627 modules and, in shared libraries, means that the declared entity may be
628 overridden. On Darwin, default visibility means that the declaration is
629 visible to other modules. Default visibility corresponds to "external
630 linkage" in the language.
631 </dd>
632
633 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
634
635 <dd>Two declarations of an object with hidden visibility refer to the same
636 object if they are in the same shared object. Usually, hidden visibility
637 indicates that the symbol will not be placed into the dynamic symbol table,
638 so no other module (executable or shared library) can reference it
639 directly.
640 </dd>
641
Anton Korobeynikov6f9896f2007-04-29 18:35:00 +0000642 <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt>
643
644 <dd>On ELF, protected visibility indicates that the symbol will be placed in
645 the dynamic symbol table, but that references within the defining module will
646 bind to the local symbol. That is, the symbol cannot be overridden by another
647 module.
648 </dd>
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000649</dl>
650
651</div>
652
653<!-- ======================================================================= -->
654<div class="doc_subsection">
Chris Lattnerfa730212004-12-09 16:11:40 +0000655 <a name="globalvars">Global Variables</a>
656</div>
657
658<div class="doc_text">
659
Chris Lattner3689a342005-02-12 19:30:21 +0000660<p>Global variables define regions of memory allocated at compilation time
Chris Lattner88f6c462005-11-12 00:45:07 +0000661instead of run-time. Global variables may optionally be initialized, may have
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000662an explicit section to be placed in, and may have an optional explicit alignment
663specified. A variable may be defined as "thread_local", which means that it
664will not be shared by threads (each thread will have a separated copy of the
665variable). A variable may be defined as a global "constant," which indicates
666that the contents of the variable will <b>never</b> be modified (enabling better
Chris Lattner3689a342005-02-12 19:30:21 +0000667optimization, allowing the global data to be placed in the read-only section of
668an executable, etc). Note that variables that need runtime initialization
John Criswell0ec250c2005-10-24 16:17:18 +0000669cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner3689a342005-02-12 19:30:21 +0000670
671<p>
672LLVM explicitly allows <em>declarations</em> of global variables to be marked
673constant, even if the final definition of the global is not. This capability
674can be used to enable slightly better optimization of the program, but requires
675the language definition to guarantee that optimizations based on the
676'constantness' are valid for the translation units that do not include the
677definition.
678</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000679
680<p>As SSA values, global variables define pointer values that are in
681scope (i.e. they dominate) all basic blocks in the program. Global
682variables always define a pointer to their "content" type because they
683describe a region of memory, and all memory objects in LLVM are
684accessed through pointers.</p>
685
Christopher Lamb284d9922007-12-11 09:31:00 +0000686<p>A global variable may be declared to reside in a target-specifc numbered
687address space. For targets that support them, address spaces may affect how
688optimizations are performed and/or what target instructions are used to access
Christopher Lambd49e18d2007-12-12 08:44:39 +0000689the variable. The default address space is zero. The address space qualifier
690must precede any other attributes.</p>
Christopher Lamb284d9922007-12-11 09:31:00 +0000691
Chris Lattner88f6c462005-11-12 00:45:07 +0000692<p>LLVM allows an explicit section to be specified for globals. If the target
693supports it, it will emit globals to the section specified.</p>
694
Chris Lattner2cbdc452005-11-06 08:02:57 +0000695<p>An explicit alignment may be specified for a global. If not present, or if
696the alignment is set to zero, the alignment of the global is set by the target
697to whatever it feels convenient. If an explicit alignment is specified, the
698global is forced to have at least that much alignment. All alignments must be
699a power of 2.</p>
700
Christopher Lamb284d9922007-12-11 09:31:00 +0000701<p>For example, the following defines a global in a numbered address space with
702an initializer, section, and alignment:</p>
Chris Lattner68027ea2007-01-14 00:27:09 +0000703
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000704<div class="doc_code">
Chris Lattner68027ea2007-01-14 00:27:09 +0000705<pre>
Christopher Lamb284d9922007-12-11 09:31:00 +0000706@G = constant float 1.0 addrspace(5), section "foo", align 4
Chris Lattner68027ea2007-01-14 00:27:09 +0000707</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000708</div>
Chris Lattner68027ea2007-01-14 00:27:09 +0000709
Chris Lattnerfa730212004-12-09 16:11:40 +0000710</div>
711
712
713<!-- ======================================================================= -->
714<div class="doc_subsection">
715 <a name="functionstructure">Functions</a>
716</div>
717
718<div class="doc_text">
719
Reid Spencerca86e162006-12-31 07:07:53 +0000720<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
721an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000722<a href="#visibility">visibility style</a>, an optional
Reid Spencerca86e162006-12-31 07:07:53 +0000723<a href="#callingconv">calling convention</a>, a return type, an optional
724<a href="#paramattrs">parameter attribute</a> for the return type, a function
725name, a (possibly empty) argument list (each with optional
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000726<a href="#paramattrs">parameter attributes</a>), an optional section, an
Gordon Henriksene754abe2007-12-10 03:30:21 +0000727optional alignment, an optional <a href="#gc">garbage collector name</a>, an
Gordon Henriksen80a75bf2007-12-10 03:18:06 +0000728opening curly brace, a list of basic blocks, and a closing curly brace.
Anton Korobeynikov8cea37b2007-01-23 12:35:46 +0000729
730LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
731optional <a href="#linkage">linkage type</a>, an optional
732<a href="#visibility">visibility style</a>, an optional
733<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerca86e162006-12-31 07:07:53 +0000734<a href="#paramattrs">parameter attribute</a> for the return type, a function
Gordon Henriksen80a75bf2007-12-10 03:18:06 +0000735name, a possibly empty list of arguments, an optional alignment, and an optional
Gordon Henriksene754abe2007-12-10 03:30:21 +0000736<a href="#gc">garbage collector name</a>.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +0000737
738<p>A function definition contains a list of basic blocks, forming the CFG for
739the function. Each basic block may optionally start with a label (giving the
740basic block a symbol table entry), contains a list of instructions, and ends
741with a <a href="#terminators">terminator</a> instruction (such as a branch or
742function return).</p>
743
Chris Lattner4a3c9012007-06-08 16:52:14 +0000744<p>The first basic block in a function is special in two ways: it is immediately
Chris Lattnerfa730212004-12-09 16:11:40 +0000745executed on entrance to the function, and it is not allowed to have predecessor
746basic blocks (i.e. there can not be any branches to the entry block of a
747function). Because the block can have no predecessors, it also cannot have any
748<a href="#i_phi">PHI nodes</a>.</p>
749
Chris Lattner88f6c462005-11-12 00:45:07 +0000750<p>LLVM allows an explicit section to be specified for functions. If the target
751supports it, it will emit functions to the section specified.</p>
752
Chris Lattner2cbdc452005-11-06 08:02:57 +0000753<p>An explicit alignment may be specified for a function. If not present, or if
754the alignment is set to zero, the alignment of the function is set by the target
755to whatever it feels convenient. If an explicit alignment is specified, the
756function is forced to have at least that much alignment. All alignments must be
757a power of 2.</p>
758
Chris Lattnerfa730212004-12-09 16:11:40 +0000759</div>
760
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000761
762<!-- ======================================================================= -->
763<div class="doc_subsection">
764 <a name="aliasstructure">Aliases</a>
765</div>
766<div class="doc_text">
767 <p>Aliases act as "second name" for the aliasee value (which can be either
Anton Korobeynikov726d45c2008-03-22 08:36:14 +0000768 function, global variable, another alias or bitcast of global value). Aliases
769 may have an optional <a href="#linkage">linkage type</a>, and an
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000770 optional <a href="#visibility">visibility style</a>.</p>
771
772 <h5>Syntax:</h5>
773
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000774<div class="doc_code">
Bill Wendlingaac388b2007-05-29 09:42:13 +0000775<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000776@&lt;Name&gt; = [Linkage] [Visibility] alias &lt;AliaseeTy&gt; @&lt;Aliasee&gt;
Bill Wendlingaac388b2007-05-29 09:42:13 +0000777</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000778</div>
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000779
780</div>
781
782
783
Chris Lattner4e9aba72006-01-23 23:23:47 +0000784<!-- ======================================================================= -->
Reid Spencerca86e162006-12-31 07:07:53 +0000785<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
786<div class="doc_text">
787 <p>The return type and each parameter of a function type may have a set of
788 <i>parameter attributes</i> associated with them. Parameter attributes are
789 used to communicate additional information about the result or parameters of
Duncan Sandsdc024672007-11-27 13:23:08 +0000790 a function. Parameter attributes are considered to be part of the function,
791 not of the function type, so functions with different parameter attributes
792 can have the same function type.</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000793
Reid Spencer950e9f82007-01-15 18:27:39 +0000794 <p>Parameter attributes are simple keywords that follow the type specified. If
795 multiple parameter attributes are needed, they are space separated. For
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000796 example:</p>
797
798<div class="doc_code">
799<pre>
Duncan Sandsdc024672007-11-27 13:23:08 +0000800declare i32 @printf(i8* noalias , ...) nounwind
801declare i32 @atoi(i8*) nounwind readonly
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000802</pre>
803</div>
804
Duncan Sandsdc024672007-11-27 13:23:08 +0000805 <p>Note that any attributes for the function result (<tt>nounwind</tt>,
806 <tt>readonly</tt>) come immediately after the argument list.</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000807
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000808 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerca86e162006-12-31 07:07:53 +0000809 <dl>
Reid Spencer9445e9a2007-07-19 23:13:04 +0000810 <dt><tt>zeroext</tt></dt>
Reid Spencerca86e162006-12-31 07:07:53 +0000811 <dd>This indicates that the parameter should be zero extended just before
812 a call to this function.</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000813
Reid Spencer9445e9a2007-07-19 23:13:04 +0000814 <dt><tt>signext</tt></dt>
Reid Spencerca86e162006-12-31 07:07:53 +0000815 <dd>This indicates that the parameter should be sign extended just before
816 a call to this function.</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000817
Anton Korobeynikov34d6dea2007-01-28 14:30:45 +0000818 <dt><tt>inreg</tt></dt>
819 <dd>This indicates that the parameter should be placed in register (if
Anton Korobeynikov66a8c8c2007-01-28 15:27:21 +0000820 possible) during assembling function call. Support for this attribute is
821 target-specific</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000822
823 <dt><tt>byval</tt></dt>
Chris Lattner0747baa2008-01-15 04:34:22 +0000824 <dd>This indicates that the pointer parameter should really be passed by
825 value to the function. The attribute implies that a hidden copy of the
826 pointee is made between the caller and the callee, so the callee is unable
827 to modify the value in the callee. This attribute is only valid on llvm
828 pointer arguments. It is generally used to pass structs and arrays by
829 value, but is also valid on scalars (even though this is silly).</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000830
Anton Korobeynikov34d6dea2007-01-28 14:30:45 +0000831 <dt><tt>sret</tt></dt>
Duncan Sandse26dec62008-02-18 04:19:38 +0000832 <dd>This indicates that the pointer parameter specifies the address of a
833 structure that is the return value of the function in the source program.
Duncan Sandsb7f0c082008-03-17 12:17:41 +0000834 Loads and stores to the structure are assumed not to trap.
Duncan Sandse26dec62008-02-18 04:19:38 +0000835 May only be applied to the first parameter.</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000836
Zhou Shengfebca342007-06-05 05:28:26 +0000837 <dt><tt>noalias</tt></dt>
Owen Anderson117bbd32008-02-18 04:09:01 +0000838 <dd>This indicates that the parameter does not alias any global or any other
839 parameter. The caller is responsible for ensuring that this is the case,
840 usually by placing the value in a stack allocation.</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000841
Reid Spencer2dc52012007-03-22 02:18:56 +0000842 <dt><tt>noreturn</tt></dt>
843 <dd>This function attribute indicates that the function never returns. This
844 indicates to LLVM that every call to this function should be treated as if
845 an <tt>unreachable</tt> instruction immediately followed the call.</dd>
Chris Lattner47507de2008-01-11 06:20:47 +0000846
Reid Spencer67606122007-03-22 02:02:11 +0000847 <dt><tt>nounwind</tt></dt>
Duncan Sandsb7f0c082008-03-17 12:17:41 +0000848 <dd>This function attribute indicates that no exceptions unwind out of the
849 function. Usually this is because the function makes no use of exceptions,
850 but it may also be that the function catches any exceptions thrown when
851 executing it.</dd>
852
Duncan Sands50f19f52007-07-27 19:57:41 +0000853 <dt><tt>nest</tt></dt>
854 <dd>This indicates that the parameter can be excised using the
855 <a href="#int_trampoline">trampoline intrinsics</a>.</dd>
Duncan Sandsed4a2f12007-11-22 20:23:04 +0000856 <dt><tt>readonly</tt></dt>
Duncan Sandsf04d5842007-11-14 21:14:02 +0000857 <dd>This function attribute indicates that the function has no side-effects
Duncan Sandsed4a2f12007-11-22 20:23:04 +0000858 except for producing a return value or throwing an exception. The value
859 returned must only depend on the function arguments and/or global variables.
860 It may use values obtained by dereferencing pointers.</dd>
861 <dt><tt>readnone</tt></dt>
862 <dd>A <tt>readnone</tt> function has the same restrictions as a <tt>readonly</tt>
Duncan Sandsf04d5842007-11-14 21:14:02 +0000863 function, but in addition it is not allowed to dereference any pointer arguments
864 or global variables.
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000865 </dl>
Reid Spencerca86e162006-12-31 07:07:53 +0000866
Reid Spencerca86e162006-12-31 07:07:53 +0000867</div>
868
869<!-- ======================================================================= -->
Chris Lattner4e9aba72006-01-23 23:23:47 +0000870<div class="doc_subsection">
Gordon Henriksen80a75bf2007-12-10 03:18:06 +0000871 <a name="gc">Garbage Collector Names</a>
872</div>
873
874<div class="doc_text">
875<p>Each function may specify a garbage collector name, which is simply a
876string.</p>
877
878<div class="doc_code"><pre
879>define void @f() gc "name" { ...</pre></div>
880
881<p>The compiler declares the supported values of <i>name</i>. Specifying a
882collector which will cause the compiler to alter its output in order to support
883the named garbage collection algorithm.</p>
884</div>
885
886<!-- ======================================================================= -->
887<div class="doc_subsection">
Chris Lattner1eeeb0c2006-04-08 04:40:53 +0000888 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner4e9aba72006-01-23 23:23:47 +0000889</div>
890
891<div class="doc_text">
892<p>
893Modules may contain "module-level inline asm" blocks, which corresponds to the
894GCC "file scope inline asm" blocks. These blocks are internally concatenated by
895LLVM and treated as a single unit, but may be separated in the .ll file if
896desired. The syntax is very simple:
897</p>
898
Bill Wendling2f7a8b02007-05-29 09:04:49 +0000899<div class="doc_code">
900<pre>
901module asm "inline asm code goes here"
902module asm "more can go here"
903</pre>
904</div>
Chris Lattner4e9aba72006-01-23 23:23:47 +0000905
906<p>The strings can contain any character by escaping non-printable characters.
907 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
908 for the number.
909</p>
910
911<p>
912 The inline asm code is simply printed to the machine code .s file when
913 assembly code is generated.
914</p>
915</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000916
Reid Spencerde151942007-02-19 23:54:10 +0000917<!-- ======================================================================= -->
918<div class="doc_subsection">
919 <a name="datalayout">Data Layout</a>
920</div>
921
922<div class="doc_text">
923<p>A module may specify a target specific data layout string that specifies how
Reid Spencerc8910842007-04-11 23:49:50 +0000924data is to be laid out in memory. The syntax for the data layout is simply:</p>
925<pre> target datalayout = "<i>layout specification</i>"</pre>
926<p>The <i>layout specification</i> consists of a list of specifications
927separated by the minus sign character ('-'). Each specification starts with a
928letter and may include other information after the letter to define some
929aspect of the data layout. The specifications accepted are as follows: </p>
Reid Spencerde151942007-02-19 23:54:10 +0000930<dl>
931 <dt><tt>E</tt></dt>
932 <dd>Specifies that the target lays out data in big-endian form. That is, the
933 bits with the most significance have the lowest address location.</dd>
934 <dt><tt>e</tt></dt>
935 <dd>Specifies that hte target lays out data in little-endian form. That is,
936 the bits with the least significance have the lowest address location.</dd>
937 <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
938 <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and
939 <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i>
940 alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted
941 too.</dd>
942 <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
943 <dd>This specifies the alignment for an integer type of a given bit
944 <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd>
945 <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
946 <dd>This specifies the alignment for a vector type of a given bit
947 <i>size</i>.</dd>
948 <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
949 <dd>This specifies the alignment for a floating point type of a given bit
950 <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64
951 (double).</dd>
952 <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt>
953 <dd>This specifies the alignment for an aggregate type of a given bit
954 <i>size</i>.</dd>
955</dl>
956<p>When constructing the data layout for a given target, LLVM starts with a
957default set of specifications which are then (possibly) overriden by the
958specifications in the <tt>datalayout</tt> keyword. The default specifications
959are given in this list:</p>
960<ul>
961 <li><tt>E</tt> - big endian</li>
962 <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li>
963 <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li>
964 <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li>
965 <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li>
966 <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li>
967 <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred
968 alignment of 64-bits</li>
969 <li><tt>f32:32:32</tt> - float is 32-bit aligned</li>
970 <li><tt>f64:64:64</tt> - double is 64-bit aligned</li>
971 <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li>
972 <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li>
973 <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li>
974</ul>
975<p>When llvm is determining the alignment for a given type, it uses the
976following rules:
977<ol>
978 <li>If the type sought is an exact match for one of the specifications, that
979 specification is used.</li>
980 <li>If no match is found, and the type sought is an integer type, then the
981 smallest integer type that is larger than the bitwidth of the sought type is
982 used. If none of the specifications are larger than the bitwidth then the the
983 largest integer type is used. For example, given the default specifications
984 above, the i7 type will use the alignment of i8 (next largest) while both
985 i65 and i256 will use the alignment of i64 (largest specified).</li>
986 <li>If no match is found, and the type sought is a vector type, then the
987 largest vector type that is smaller than the sought vector type will be used
988 as a fall back. This happens because <128 x double> can be implemented in
989 terms of 64 <2 x double>, for example.</li>
990</ol>
991</div>
Chris Lattnerfa730212004-12-09 16:11:40 +0000992
Chris Lattner00950542001-06-06 20:29:01 +0000993<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +0000994<div class="doc_section"> <a name="typesystem">Type System</a> </div>
995<!-- *********************************************************************** -->
Chris Lattnerfa730212004-12-09 16:11:40 +0000996
Misha Brukman9d0919f2003-11-08 01:05:38 +0000997<div class="doc_text">
Chris Lattnerfa730212004-12-09 16:11:40 +0000998
Misha Brukman9d0919f2003-11-08 01:05:38 +0000999<p>The LLVM type system is one of the most important features of the
Chris Lattner261efe92003-11-25 01:02:51 +00001000intermediate representation. Being typed enables a number of
1001optimizations to be performed on the IR directly, without having to do
1002extra analyses on the side before the transformation. A strong type
1003system makes it easier to read the generated code and enables novel
1004analyses and transformations that are not feasible to perform on normal
1005three address code representations.</p>
Chris Lattnerfa730212004-12-09 16:11:40 +00001006
1007</div>
1008
Chris Lattner00950542001-06-06 20:29:01 +00001009<!-- ======================================================================= -->
Chris Lattner4f69f462008-01-04 04:32:38 +00001010<div class="doc_subsection"> <a name="t_classifications">Type
Chris Lattner261efe92003-11-25 01:02:51 +00001011Classifications</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001012<div class="doc_text">
Chris Lattner4f69f462008-01-04 04:32:38 +00001013<p>The types fall into a few useful
Chris Lattner261efe92003-11-25 01:02:51 +00001014classifications:</p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001015
1016<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00001017 <tbody>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001018 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner261efe92003-11-25 01:02:51 +00001019 <tr>
Chris Lattner4f69f462008-01-04 04:32:38 +00001020 <td><a href="#t_integer">integer</a></td>
Reid Spencer2b916312007-05-16 18:44:01 +00001021 <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +00001022 </tr>
1023 <tr>
Chris Lattner4f69f462008-01-04 04:32:38 +00001024 <td><a href="#t_floating">floating point</a></td>
1025 <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td>
Chris Lattner261efe92003-11-25 01:02:51 +00001026 </tr>
1027 <tr>
1028 <td><a name="t_firstclass">first class</a></td>
Chris Lattner4f69f462008-01-04 04:32:38 +00001029 <td><a href="#t_integer">integer</a>,
1030 <a href="#t_floating">floating point</a>,
1031 <a href="#t_pointer">pointer</a>,
1032 <a href="#t_vector">vector</a>
Reid Spencerca86e162006-12-31 07:07:53 +00001033 </td>
Chris Lattner261efe92003-11-25 01:02:51 +00001034 </tr>
Chris Lattner4f69f462008-01-04 04:32:38 +00001035 <tr>
1036 <td><a href="#t_primitive">primitive</a></td>
1037 <td><a href="#t_label">label</a>,
1038 <a href="#t_void">void</a>,
1039 <a href="#t_integer">integer</a>,
1040 <a href="#t_floating">floating point</a>.</td>
1041 </tr>
1042 <tr>
1043 <td><a href="#t_derived">derived</a></td>
1044 <td><a href="#t_integer">integer</a>,
1045 <a href="#t_array">array</a>,
1046 <a href="#t_function">function</a>,
1047 <a href="#t_pointer">pointer</a>,
1048 <a href="#t_struct">structure</a>,
1049 <a href="#t_pstruct">packed structure</a>,
1050 <a href="#t_vector">vector</a>,
1051 <a href="#t_opaque">opaque</a>.
1052 </tr>
Chris Lattner261efe92003-11-25 01:02:51 +00001053 </tbody>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001054</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001055
Chris Lattner261efe92003-11-25 01:02:51 +00001056<p>The <a href="#t_firstclass">first class</a> types are perhaps the
1057most important. Values of these types are the only ones which can be
1058produced by instructions, passed as arguments, or used as operands to
1059instructions. This means that all structures and arrays must be
1060manipulated either by pointer or by component.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001061</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001062
Chris Lattner00950542001-06-06 20:29:01 +00001063<!-- ======================================================================= -->
Chris Lattner4f69f462008-01-04 04:32:38 +00001064<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Chris Lattner8f8c7b72008-01-04 04:34:14 +00001065
Chris Lattner4f69f462008-01-04 04:32:38 +00001066<div class="doc_text">
1067<p>The primitive types are the fundamental building blocks of the LLVM
1068system.</p>
1069
Chris Lattner8f8c7b72008-01-04 04:34:14 +00001070</div>
1071
Chris Lattner4f69f462008-01-04 04:32:38 +00001072<!-- _______________________________________________________________________ -->
1073<div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div>
1074
1075<div class="doc_text">
1076 <table>
1077 <tbody>
1078 <tr><th>Type</th><th>Description</th></tr>
1079 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
1080 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
1081 <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr>
1082 <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr>
1083 <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr>
1084 </tbody>
1085 </table>
1086</div>
1087
1088<!-- _______________________________________________________________________ -->
1089<div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div>
1090
1091<div class="doc_text">
1092<h5>Overview:</h5>
1093<p>The void type does not represent any value and has no size.</p>
1094
1095<h5>Syntax:</h5>
1096
1097<pre>
1098 void
1099</pre>
1100</div>
1101
1102<!-- _______________________________________________________________________ -->
1103<div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div>
1104
1105<div class="doc_text">
1106<h5>Overview:</h5>
1107<p>The label type represents code labels.</p>
1108
1109<h5>Syntax:</h5>
1110
1111<pre>
1112 label
1113</pre>
1114</div>
1115
1116
1117<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001118<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001119
Misha Brukman9d0919f2003-11-08 01:05:38 +00001120<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001121
Chris Lattner261efe92003-11-25 01:02:51 +00001122<p>The real power in LLVM comes from the derived types in the system.
1123This is what allows a programmer to represent arrays, functions,
1124pointers, and other useful types. Note that these derived types may be
1125recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001126
Misha Brukman9d0919f2003-11-08 01:05:38 +00001127</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001128
Chris Lattner00950542001-06-06 20:29:01 +00001129<!-- _______________________________________________________________________ -->
Reid Spencer2b916312007-05-16 18:44:01 +00001130<div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div>
1131
1132<div class="doc_text">
1133
1134<h5>Overview:</h5>
1135<p>The integer type is a very simple derived type that simply specifies an
1136arbitrary bit width for the integer type desired. Any bit width from 1 bit to
11372^23-1 (about 8 million) can be specified.</p>
1138
1139<h5>Syntax:</h5>
1140
1141<pre>
1142 iN
1143</pre>
1144
1145<p>The number of bits the integer will occupy is specified by the <tt>N</tt>
1146value.</p>
1147
1148<h5>Examples:</h5>
1149<table class="layout">
Chris Lattnerb9488a62007-12-18 06:18:21 +00001150 <tbody>
1151 <tr>
1152 <td><tt>i1</tt></td>
1153 <td>a single-bit integer.</td>
1154 </tr><tr>
1155 <td><tt>i32</tt></td>
1156 <td>a 32-bit integer.</td>
1157 </tr><tr>
1158 <td><tt>i1942652</tt></td>
1159 <td>a really big integer of over 1 million bits.</td>
Reid Spencer2b916312007-05-16 18:44:01 +00001160 </tr>
Chris Lattnerb9488a62007-12-18 06:18:21 +00001161 </tbody>
Reid Spencer2b916312007-05-16 18:44:01 +00001162</table>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001163</div>
Reid Spencer2b916312007-05-16 18:44:01 +00001164
1165<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001166<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001167
Misha Brukman9d0919f2003-11-08 01:05:38 +00001168<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001169
Chris Lattner00950542001-06-06 20:29:01 +00001170<h5>Overview:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001171
Misha Brukman9d0919f2003-11-08 01:05:38 +00001172<p>The array type is a very simple derived type that arranges elements
Chris Lattner261efe92003-11-25 01:02:51 +00001173sequentially in memory. The array type requires a size (number of
1174elements) and an underlying data type.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001175
Chris Lattner7faa8832002-04-14 06:13:44 +00001176<h5>Syntax:</h5>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001177
1178<pre>
1179 [&lt;# elements&gt; x &lt;elementtype&gt;]
1180</pre>
1181
John Criswelle4c57cc2005-05-12 16:52:32 +00001182<p>The number of elements is a constant integer value; elementtype may
Chris Lattner261efe92003-11-25 01:02:51 +00001183be any type with a size.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001184
Chris Lattner7faa8832002-04-14 06:13:44 +00001185<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001186<table class="layout">
1187 <tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001188 <td class="left"><tt>[40 x i32]</tt></td>
1189 <td class="left">Array of 40 32-bit integer values.</td>
1190 </tr>
1191 <tr class="layout">
1192 <td class="left"><tt>[41 x i32]</tt></td>
1193 <td class="left">Array of 41 32-bit integer values.</td>
1194 </tr>
1195 <tr class="layout">
1196 <td class="left"><tt>[4 x i8]</tt></td>
1197 <td class="left">Array of 4 8-bit integer values.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001198 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001199</table>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001200<p>Here are some examples of multidimensional arrays:</p>
1201<table class="layout">
1202 <tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001203 <td class="left"><tt>[3 x [4 x i32]]</tt></td>
1204 <td class="left">3x4 array of 32-bit integer values.</td>
1205 </tr>
1206 <tr class="layout">
1207 <td class="left"><tt>[12 x [10 x float]]</tt></td>
1208 <td class="left">12x10 array of single precision floating point values.</td>
1209 </tr>
1210 <tr class="layout">
1211 <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td>
1212 <td class="left">2x3x4 array of 16-bit integer values.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001213 </tr>
1214</table>
Chris Lattnere67a9512005-06-24 17:22:57 +00001215
John Criswell0ec250c2005-10-24 16:17:18 +00001216<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
1217length array. Normally, accesses past the end of an array are undefined in
Chris Lattnere67a9512005-06-24 17:22:57 +00001218LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
1219As a special case, however, zero length arrays are recognized to be variable
1220length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerca86e162006-12-31 07:07:53 +00001221type "{ i32, [0 x float]}", for example.</p>
Chris Lattnere67a9512005-06-24 17:22:57 +00001222
Misha Brukman9d0919f2003-11-08 01:05:38 +00001223</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001224
Chris Lattner00950542001-06-06 20:29:01 +00001225<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001226<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001227<div class="doc_text">
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001228
Chris Lattner00950542001-06-06 20:29:01 +00001229<h5>Overview:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001230
Chris Lattner261efe92003-11-25 01:02:51 +00001231<p>The function type can be thought of as a function signature. It
Devang Patela582f402008-03-24 05:35:41 +00001232consists of a return type and a list of formal parameter types. The
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001233return type of a function type is a scalar type, a void type, or a struct type.
Devang Patel7a3ad1a2008-03-24 20:52:42 +00001234If the return type is a struct type then all struct elements must be of first
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001235class types, and the struct must have at least one element.</p>
Devang Patelc3fc6df2008-03-10 20:49:15 +00001236
Chris Lattner00950542001-06-06 20:29:01 +00001237<h5>Syntax:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001238
1239<pre>
1240 &lt;returntype list&gt; (&lt;parameter list&gt;)
1241</pre>
1242
John Criswell0ec250c2005-10-24 16:17:18 +00001243<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukmanc24b7582004-08-12 20:16:08 +00001244specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner27f71f22003-09-03 00:41:47 +00001245which indicates that the function takes a variable number of arguments.
1246Variable argument functions can access their arguments with the <a
Devang Patelc3fc6df2008-03-10 20:49:15 +00001247 href="#int_varargs">variable argument handling intrinsic</a> functions.
1248'<tt>&lt;returntype list&gt;</tt>' is a comma-separated list of
1249<a href="#t_firstclass">first class</a> type specifiers.</p>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001250
Chris Lattner00950542001-06-06 20:29:01 +00001251<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001252<table class="layout">
1253 <tr class="layout">
Reid Spencer92f82302006-12-31 07:18:34 +00001254 <td class="left"><tt>i32 (i32)</tt></td>
1255 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001256 </td>
Reid Spencer92f82302006-12-31 07:18:34 +00001257 </tr><tr class="layout">
Reid Spencer9445e9a2007-07-19 23:13:04 +00001258 <td class="left"><tt>float&nbsp;(i16&nbsp;signext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencerf17a0b72006-12-31 07:20:23 +00001259 </tt></td>
Reid Spencer92f82302006-12-31 07:18:34 +00001260 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
1261 an <tt>i16</tt> that should be sign extended and a
Reid Spencerca86e162006-12-31 07:07:53 +00001262 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer92f82302006-12-31 07:18:34 +00001263 <tt>float</tt>.
1264 </td>
1265 </tr><tr class="layout">
1266 <td class="left"><tt>i32 (i8*, ...)</tt></td>
1267 <td class="left">A vararg function that takes at least one
Reid Spencera5173382007-01-04 16:43:23 +00001268 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer92f82302006-12-31 07:18:34 +00001269 which returns an integer. This is the signature for <tt>printf</tt> in
1270 LLVM.
Reid Spencerd3f876c2004-11-01 08:19:36 +00001271 </td>
Devang Patela582f402008-03-24 05:35:41 +00001272 </tr><tr class="layout">
1273 <td class="left"><tt>{i32, i32} (i32)</tt></td>
Devang Patel3a5bff82008-03-24 18:10:52 +00001274 <td class="left">A function taking an <tt>i32></tt>, returning two
1275 <tt> i32 </tt> values as an aggregate of type <tt>{ i32, i32 }</tt>
Devang Patela582f402008-03-24 05:35:41 +00001276 </td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001277 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001278</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00001279
Misha Brukman9d0919f2003-11-08 01:05:38 +00001280</div>
Chris Lattner00950542001-06-06 20:29:01 +00001281<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001282<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001283<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001284<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001285<p>The structure type is used to represent a collection of data members
1286together in memory. The packing of the field types is defined to match
1287the ABI of the underlying processor. The elements of a structure may
1288be any type that has a size.</p>
1289<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1290and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1291field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1292instruction.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001293<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001294<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner00950542001-06-06 20:29:01 +00001295<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001296<table class="layout">
1297 <tr class="layout">
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001298 <td class="left"><tt>{ i32, i32, i32 }</tt></td>
1299 <td class="left">A triple of three <tt>i32</tt> values</td>
1300 </tr><tr class="layout">
1301 <td class="left"><tt>{&nbsp;float,&nbsp;i32&nbsp;(i32)&nbsp;*&nbsp;}</tt></td>
1302 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1303 second element is a <a href="#t_pointer">pointer</a> to a
1304 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1305 an <tt>i32</tt>.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001306 </tr>
Chris Lattner00950542001-06-06 20:29:01 +00001307</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001308</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001309
Chris Lattner00950542001-06-06 20:29:01 +00001310<!-- _______________________________________________________________________ -->
Andrew Lenharth75e10682006-12-08 17:13:00 +00001311<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1312</div>
1313<div class="doc_text">
1314<h5>Overview:</h5>
1315<p>The packed structure type is used to represent a collection of data members
1316together in memory. There is no padding between fields. Further, the alignment
1317of a packed structure is 1 byte. The elements of a packed structure may
1318be any type that has a size.</p>
1319<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1320and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1321field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1322instruction.</p>
1323<h5>Syntax:</h5>
1324<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1325<h5>Examples:</h5>
1326<table class="layout">
1327 <tr class="layout">
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001328 <td class="left"><tt>&lt; { i32, i32, i32 } &gt;</tt></td>
1329 <td class="left">A triple of three <tt>i32</tt> values</td>
1330 </tr><tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001331 <td class="left"><tt>&lt; { float, i32 (i32)* } &gt;</tt></td>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001332 <td class="left">A pair, where the first element is a <tt>float</tt> and the
1333 second element is a <a href="#t_pointer">pointer</a> to a
1334 <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning
1335 an <tt>i32</tt>.</td>
Andrew Lenharth75e10682006-12-08 17:13:00 +00001336 </tr>
1337</table>
1338</div>
1339
1340<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001341<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001342<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00001343<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001344<p>As in many languages, the pointer type represents a pointer or
Christopher Lamb284d9922007-12-11 09:31:00 +00001345reference to another object, which must live in memory. Pointer types may have
1346an optional address space attribute defining the target-specific numbered
1347address space where the pointed-to object resides. The default address space is
1348zero.</p>
Chris Lattner7faa8832002-04-14 06:13:44 +00001349<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001350<pre> &lt;type&gt; *<br></pre>
Chris Lattner7faa8832002-04-14 06:13:44 +00001351<h5>Examples:</h5>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001352<table class="layout">
1353 <tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001354 <td class="left"><tt>[4x i32]*</tt></td>
1355 <td class="left">A <a href="#t_pointer">pointer</a> to <a
1356 href="#t_array">array</a> of four <tt>i32</tt> values.</td>
1357 </tr>
1358 <tr class="layout">
1359 <td class="left"><tt>i32 (i32 *) *</tt></td>
1360 <td class="left"> A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerca86e162006-12-31 07:07:53 +00001361 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
Chris Lattner23ff1f92007-12-19 05:04:11 +00001362 <tt>i32</tt>.</td>
1363 </tr>
1364 <tr class="layout">
1365 <td class="left"><tt>i32 addrspace(5)*</tt></td>
1366 <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value
1367 that resides in address space #5.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001368 </tr>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001369</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001370</div>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001371
Chris Lattnera58561b2004-08-12 19:12:28 +00001372<!-- _______________________________________________________________________ -->
Reid Spencer485bad12007-02-15 03:07:05 +00001373<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001374<div class="doc_text">
Chris Lattner69c11bb2005-04-25 17:34:15 +00001375
Chris Lattnera58561b2004-08-12 19:12:28 +00001376<h5>Overview:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001377
Reid Spencer485bad12007-02-15 03:07:05 +00001378<p>A vector type is a simple derived type that represents a vector
1379of elements. Vector types are used when multiple primitive data
Chris Lattnera58561b2004-08-12 19:12:28 +00001380are operated in parallel using a single instruction (SIMD).
Reid Spencer485bad12007-02-15 03:07:05 +00001381A vector type requires a size (number of
Chris Lattnerb8d172f2005-11-10 01:44:22 +00001382elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer485bad12007-02-15 03:07:05 +00001383of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnera58561b2004-08-12 19:12:28 +00001384considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001385
Chris Lattnera58561b2004-08-12 19:12:28 +00001386<h5>Syntax:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001387
1388<pre>
1389 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1390</pre>
1391
John Criswellc1f786c2005-05-13 22:25:59 +00001392<p>The number of elements is a constant integer value; elementtype may
Chris Lattner3b19d652007-01-15 01:54:13 +00001393be any integer or floating point type.</p>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001394
Chris Lattnera58561b2004-08-12 19:12:28 +00001395<h5>Examples:</h5>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001396
Reid Spencerd3f876c2004-11-01 08:19:36 +00001397<table class="layout">
1398 <tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001399 <td class="left"><tt>&lt;4 x i32&gt;</tt></td>
1400 <td class="left">Vector of 4 32-bit integer values.</td>
1401 </tr>
1402 <tr class="layout">
1403 <td class="left"><tt>&lt;8 x float&gt;</tt></td>
1404 <td class="left">Vector of 8 32-bit floating-point values.</td>
1405 </tr>
1406 <tr class="layout">
1407 <td class="left"><tt>&lt;2 x i64&gt;</tt></td>
1408 <td class="left">Vector of 2 64-bit integer values.</td>
Reid Spencerd3f876c2004-11-01 08:19:36 +00001409 </tr>
1410</table>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001411</div>
1412
Chris Lattner69c11bb2005-04-25 17:34:15 +00001413<!-- _______________________________________________________________________ -->
1414<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1415<div class="doc_text">
1416
1417<h5>Overview:</h5>
1418
1419<p>Opaque types are used to represent unknown types in the system. This
Gordon Henriksen8ac04ff2007-10-14 00:34:53 +00001420corresponds (for example) to the C notion of a forward declared structure type.
Chris Lattner69c11bb2005-04-25 17:34:15 +00001421In LLVM, opaque types can eventually be resolved to any type (not just a
1422structure type).</p>
1423
1424<h5>Syntax:</h5>
1425
1426<pre>
1427 opaque
1428</pre>
1429
1430<h5>Examples:</h5>
1431
1432<table class="layout">
1433 <tr class="layout">
Chris Lattner23ff1f92007-12-19 05:04:11 +00001434 <td class="left"><tt>opaque</tt></td>
1435 <td class="left">An opaque type.</td>
Chris Lattner69c11bb2005-04-25 17:34:15 +00001436 </tr>
1437</table>
1438</div>
1439
1440
Chris Lattnerc3f59762004-12-09 17:30:23 +00001441<!-- *********************************************************************** -->
1442<div class="doc_section"> <a name="constants">Constants</a> </div>
1443<!-- *********************************************************************** -->
1444
1445<div class="doc_text">
1446
1447<p>LLVM has several different basic types of constants. This section describes
1448them all and their syntax.</p>
1449
1450</div>
1451
1452<!-- ======================================================================= -->
Reid Spencercc16dc32004-12-09 18:02:53 +00001453<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001454
1455<div class="doc_text">
1456
1457<dl>
1458 <dt><b>Boolean constants</b></dt>
1459
1460 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencerc78f3372007-01-12 03:35:51 +00001461 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattnerc3f59762004-12-09 17:30:23 +00001462 </dd>
1463
1464 <dt><b>Integer constants</b></dt>
1465
Reid Spencercc16dc32004-12-09 18:02:53 +00001466 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencera5173382007-01-04 16:43:23 +00001467 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattnerc3f59762004-12-09 17:30:23 +00001468 integer types.
1469 </dd>
1470
1471 <dt><b>Floating point constants</b></dt>
1472
1473 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1474 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattnera73afe02008-04-01 18:45:27 +00001475 notation (see below). The assembler requires the exact decimal value of
1476 a floating-point constant. For example, the assembler accepts 1.25 but
1477 rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point
1478 constants must have a <a href="#t_floating">floating point</a> type. </dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001479
1480 <dt><b>Null pointer constants</b></dt>
1481
John Criswell9e2485c2004-12-10 15:51:16 +00001482 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattnerc3f59762004-12-09 17:30:23 +00001483 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1484
1485</dl>
1486
John Criswell9e2485c2004-12-10 15:51:16 +00001487<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattnerc3f59762004-12-09 17:30:23 +00001488of floating point constants. For example, the form '<tt>double
14890x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
14904.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencercc16dc32004-12-09 18:02:53 +00001491(and the only time that they are generated by the disassembler) is when a
1492floating point constant must be emitted but it cannot be represented as a
1493decimal floating point number. For example, NaN's, infinities, and other
1494special values are represented in their IEEE hexadecimal format so that
1495assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001496
1497</div>
1498
1499<!-- ======================================================================= -->
1500<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1501</div>
1502
1503<div class="doc_text">
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001504<p>Aggregate constants arise from aggregation of simple constants
1505and smaller aggregate constants.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001506
1507<dl>
1508 <dt><b>Structure constants</b></dt>
1509
1510 <dd>Structure constants are represented with notation similar to structure
1511 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner64910ee2007-12-25 20:34:52 +00001512 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>",
1513 where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>". Structure constants
Chris Lattnerd4f6b172005-03-07 22:13:59 +00001514 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattnerc3f59762004-12-09 17:30:23 +00001515 types of elements must match those specified by the type.
1516 </dd>
1517
1518 <dt><b>Array constants</b></dt>
1519
1520 <dd>Array constants are represented with notation similar to array type
1521 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerca86e162006-12-31 07:07:53 +00001522 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattnerc3f59762004-12-09 17:30:23 +00001523 constants must have <a href="#t_array">array type</a>, and the number and
1524 types of elements must match those specified by the type.
1525 </dd>
1526
Reid Spencer485bad12007-02-15 03:07:05 +00001527 <dt><b>Vector constants</b></dt>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001528
Reid Spencer485bad12007-02-15 03:07:05 +00001529 <dd>Vector constants are represented with notation similar to vector type
Chris Lattnerc3f59762004-12-09 17:30:23 +00001530 definitions (a comma separated list of elements, surrounded by
Reid Spencerca86e162006-12-31 07:07:53 +00001531 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Jeff Cohen6f1cc772007-04-22 01:17:39 +00001532 i32 11, i32 74, i32 100 &gt;</tt>". Vector constants must have <a
Reid Spencer485bad12007-02-15 03:07:05 +00001533 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattnerc3f59762004-12-09 17:30:23 +00001534 match those specified by the type.
1535 </dd>
1536
1537 <dt><b>Zero initialization</b></dt>
1538
1539 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1540 value to zero of <em>any</em> type, including scalar and aggregate types.
1541 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell0ec250c2005-10-24 16:17:18 +00001542 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattnerc3f59762004-12-09 17:30:23 +00001543 initializers.
1544 </dd>
1545</dl>
1546
1547</div>
1548
1549<!-- ======================================================================= -->
1550<div class="doc_subsection">
1551 <a name="globalconstants">Global Variable and Function Addresses</a>
1552</div>
1553
1554<div class="doc_text">
1555
1556<p>The addresses of <a href="#globalvars">global variables</a> and <a
1557href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswell9e2485c2004-12-10 15:51:16 +00001558constants. These constants are explicitly referenced when the <a
1559href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattnerc3f59762004-12-09 17:30:23 +00001560href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1561file:</p>
1562
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001563<div class="doc_code">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001564<pre>
Chris Lattnera18a4242007-06-06 18:28:13 +00001565@X = global i32 17
1566@Y = global i32 42
1567@Z = global [2 x i32*] [ i32* @X, i32* @Y ]
Chris Lattnerc3f59762004-12-09 17:30:23 +00001568</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001569</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001570
1571</div>
1572
1573<!-- ======================================================================= -->
Reid Spencer2dc45b82004-12-09 18:13:12 +00001574<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001575<div class="doc_text">
Reid Spencer2dc45b82004-12-09 18:13:12 +00001576 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswellc1f786c2005-05-13 22:25:59 +00001577 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer2dc45b82004-12-09 18:13:12 +00001578 a constant is permitted.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001579
Reid Spencer2dc45b82004-12-09 18:13:12 +00001580 <p>Undefined values indicate to the compiler that the program is well defined
1581 no matter what value is used, giving the compiler more freedom to optimize.
1582 </p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001583</div>
1584
1585<!-- ======================================================================= -->
1586<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1587</div>
1588
1589<div class="doc_text">
1590
1591<p>Constant expressions are used to allow expressions involving other constants
1592to be used as constants. Constant expressions may be of any <a
John Criswellc1f786c2005-05-13 22:25:59 +00001593href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattnerc3f59762004-12-09 17:30:23 +00001594that does not have side effects (e.g. load and call are not supported). The
1595following is the syntax for constant expressions:</p>
1596
1597<dl>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001598 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1599 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattner3b19d652007-01-15 01:54:13 +00001600 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001601
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001602 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1603 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattner3b19d652007-01-15 01:54:13 +00001604 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001605
1606 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1607 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattner3b19d652007-01-15 01:54:13 +00001608 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001609
1610 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1611 <dd>Truncate a floating point constant to another floating point type. The
1612 size of CST must be larger than the size of TYPE. Both types must be
1613 floating point.</dd>
1614
1615 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1616 <dd>Floating point extend a constant to another type. The size of CST must be
1617 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1618
Reid Spencer1539a1c2007-07-31 14:40:14 +00001619 <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001620 <dd>Convert a floating point constant to the corresponding unsigned integer
Nate Begemanb348d182007-11-17 03:58:34 +00001621 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
1622 or vector floating point type. Both CST and TYPE must be scalars, or vectors
1623 of the same number of elements. If the value won't fit in the integer type,
1624 the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001625
Reid Spencerd4448792006-11-09 23:03:26 +00001626 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001627 <dd>Convert a floating point constant to the corresponding signed integer
Nate Begemanb348d182007-11-17 03:58:34 +00001628 constant. TYPE must be a scalar or vector integer type. CST must be of scalar
1629 or vector floating point type. Both CST and TYPE must be scalars, or vectors
1630 of the same number of elements. If the value won't fit in the integer type,
1631 the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001632
Reid Spencerd4448792006-11-09 23:03:26 +00001633 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001634 <dd>Convert an unsigned integer constant to the corresponding floating point
Nate Begemanb348d182007-11-17 03:58:34 +00001635 constant. TYPE must be a scalar or vector floating point type. CST must be of
1636 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
1637 of the same number of elements. If the value won't fit in the floating point
1638 type, the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001639
Reid Spencerd4448792006-11-09 23:03:26 +00001640 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001641 <dd>Convert a signed integer constant to the corresponding floating point
Nate Begemanb348d182007-11-17 03:58:34 +00001642 constant. TYPE must be a scalar or vector floating point type. CST must be of
1643 scalar or vector integer type. Both CST and TYPE must be scalars, or vectors
1644 of the same number of elements. If the value won't fit in the floating point
1645 type, the results are undefined.</dd>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001646
Reid Spencer5c0ef472006-11-11 23:08:07 +00001647 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1648 <dd>Convert a pointer typed constant to the corresponding integer constant
1649 TYPE must be an integer type. CST must be of pointer type. The CST value is
1650 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1651
1652 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1653 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1654 pointer type. CST must be of integer type. The CST value is zero extended,
1655 truncated, or unchanged to make it fit in a pointer size. This one is
1656 <i>really</i> dangerous!</dd>
1657
1658 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001659 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1660 identical (same number of bits). The conversion is done as if the CST value
1661 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5c0ef472006-11-11 23:08:07 +00001662 with this operator, just the type. This can be used for conversion of
Reid Spencer485bad12007-02-15 03:07:05 +00001663 vector types to any other type, as long as they have the same bit width. For
Reid Spencer5c0ef472006-11-11 23:08:07 +00001664 pointers it is only valid to cast to another pointer type.
Reid Spencer9dee3ac2006-11-08 01:11:31 +00001665 </dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001666
1667 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1668
1669 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1670 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1671 instruction, the index list may have zero or more indexes, which are required
1672 to make sense for the type of "CSTPTR".</dd>
1673
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001674 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1675
1676 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer01c42592006-12-04 19:23:19 +00001677 constants.</dd>
1678
1679 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1680 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1681
1682 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1683 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001684
Nate Begemanac80ade2008-05-12 19:01:56 +00001685 <dt><b><tt>vicmp COND ( VAL1, VAL2 )</tt></b></dt>
1686 <dd>Performs the <a href="#i_vicmp">vicmp operation</a> on constants.</dd>
1687
1688 <dt><b><tt>vfcmp COND ( VAL1, VAL2 )</tt></b></dt>
1689 <dd>Performs the <a href="#i_vfcmp">vfcmp operation</a> on constants.</dd>
1690
Robert Bocchino9fbe1452006-01-10 19:31:34 +00001691 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1692
1693 <dd>Perform the <a href="#i_extractelement">extractelement
1694 operation</a> on constants.
1695
Robert Bocchino05ccd702006-01-15 20:48:27 +00001696 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1697
1698 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer01c42592006-12-04 19:23:19 +00001699 operation</a> on constants.</dd>
Robert Bocchino05ccd702006-01-15 20:48:27 +00001700
Chris Lattnerc1989542006-04-08 00:13:41 +00001701
1702 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1703
1704 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer01c42592006-12-04 19:23:19 +00001705 operation</a> on constants.</dd>
Chris Lattnerc1989542006-04-08 00:13:41 +00001706
Chris Lattnerc3f59762004-12-09 17:30:23 +00001707 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1708
Reid Spencer2dc45b82004-12-09 18:13:12 +00001709 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1710 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattnerc3f59762004-12-09 17:30:23 +00001711 binary</a> operations. The constraints on operands are the same as those for
1712 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswelle4c57cc2005-05-12 16:52:32 +00001713 values are allowed).</dd>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001714</dl>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001715</div>
Chris Lattner9ee5d222004-03-08 16:49:10 +00001716
Chris Lattner00950542001-06-06 20:29:01 +00001717<!-- *********************************************************************** -->
Chris Lattnere87d6532006-01-25 23:47:57 +00001718<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1719<!-- *********************************************************************** -->
1720
1721<!-- ======================================================================= -->
1722<div class="doc_subsection">
1723<a name="inlineasm">Inline Assembler Expressions</a>
1724</div>
1725
1726<div class="doc_text">
1727
1728<p>
1729LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1730Module-Level Inline Assembly</a>) through the use of a special value. This
1731value represents the inline assembler as a string (containing the instructions
1732to emit), a list of operand constraints (stored as a string), and a flag that
1733indicates whether or not the inline asm expression has side effects. An example
1734inline assembler expression is:
1735</p>
1736
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001737<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001738<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001739i32 (i32) asm "bswap $0", "=r,r"
Chris Lattnere87d6532006-01-25 23:47:57 +00001740</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001741</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001742
1743<p>
1744Inline assembler expressions may <b>only</b> be used as the callee operand of
1745a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1746</p>
1747
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001748<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001749<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001750%X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattnere87d6532006-01-25 23:47:57 +00001751</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001752</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001753
1754<p>
1755Inline asms with side effects not visible in the constraint list must be marked
1756as having side effects. This is done through the use of the
1757'<tt>sideeffect</tt>' keyword, like so:
1758</p>
1759
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001760<div class="doc_code">
Chris Lattnere87d6532006-01-25 23:47:57 +00001761<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001762call void asm sideeffect "eieio", ""()
Chris Lattnere87d6532006-01-25 23:47:57 +00001763</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00001764</div>
Chris Lattnere87d6532006-01-25 23:47:57 +00001765
1766<p>TODO: The format of the asm and constraints string still need to be
1767documented here. Constraints on what can be done (e.g. duplication, moving, etc
1768need to be documented).
1769</p>
1770
1771</div>
1772
1773<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00001774<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1775<!-- *********************************************************************** -->
Chris Lattnerc3f59762004-12-09 17:30:23 +00001776
Misha Brukman9d0919f2003-11-08 01:05:38 +00001777<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001778
Chris Lattner261efe92003-11-25 01:02:51 +00001779<p>The LLVM instruction set consists of several different
1780classifications of instructions: <a href="#terminators">terminator
John Criswellc1f786c2005-05-13 22:25:59 +00001781instructions</a>, <a href="#binaryops">binary instructions</a>,
1782<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner261efe92003-11-25 01:02:51 +00001783 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1784instructions</a>.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001785
Misha Brukman9d0919f2003-11-08 01:05:38 +00001786</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001787
Chris Lattner00950542001-06-06 20:29:01 +00001788<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00001789<div class="doc_subsection"> <a name="terminators">Terminator
1790Instructions</a> </div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001791
Misha Brukman9d0919f2003-11-08 01:05:38 +00001792<div class="doc_text">
Chris Lattnerc3f59762004-12-09 17:30:23 +00001793
Chris Lattner261efe92003-11-25 01:02:51 +00001794<p>As mentioned <a href="#functionstructure">previously</a>, every
1795basic block in a program ends with a "Terminator" instruction, which
1796indicates which block should be executed after the current block is
1797finished. These terminator instructions typically yield a '<tt>void</tt>'
1798value: they produce control flow, not values (the one exception being
1799the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswell9e2485c2004-12-10 15:51:16 +00001800<p>There are six different terminator instructions: the '<a
Chris Lattner261efe92003-11-25 01:02:51 +00001801 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1802instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner35eca582004-10-16 18:04:13 +00001803the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1804 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1805 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001806
Misha Brukman9d0919f2003-11-08 01:05:38 +00001807</div>
Chris Lattnerc3f59762004-12-09 17:30:23 +00001808
Chris Lattner00950542001-06-06 20:29:01 +00001809<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001810<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1811Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001812<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001813<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001814<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 +00001815 ret void <i>; Return from void function</i>
Devang Patelc3fc6df2008-03-10 20:49:15 +00001816 ret &lt;type&gt; &lt;value&gt;, &lt;type&gt; &lt;value&gt; <i>; Return two values from a non-void function </i>
Chris Lattner00950542001-06-06 20:29:01 +00001817</pre>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001818
Chris Lattner00950542001-06-06 20:29:01 +00001819<h5>Overview:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001820
Chris Lattner261efe92003-11-25 01:02:51 +00001821<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswellc1f786c2005-05-13 22:25:59 +00001822value) from a function back to the caller.</p>
John Criswell4457dc92004-04-09 16:48:45 +00001823<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001824returns value(s) and then causes control flow, and one that just causes
Chris Lattner261efe92003-11-25 01:02:51 +00001825control flow to occur.</p>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001826
Chris Lattner00950542001-06-06 20:29:01 +00001827<h5>Arguments:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001828
1829<p>The '<tt>ret</tt>' instruction may return zero, one or multiple values.
1830The type of each return value must be a '<a href="#t_firstclass">first
1831class</a>' type. Note that a function is not <a href="#wellformed">well
1832formed</a> if there exists a '<tt>ret</tt>' instruction inside of the
1833function that returns values that do not match the return type of the
1834function.</p>
1835
Chris Lattner00950542001-06-06 20:29:01 +00001836<h5>Semantics:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001837
Chris Lattner261efe92003-11-25 01:02:51 +00001838<p>When the '<tt>ret</tt>' instruction is executed, control flow
1839returns back to the calling function's context. If the caller is a "<a
John Criswellfa081872004-06-25 15:16:57 +00001840 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner261efe92003-11-25 01:02:51 +00001841the instruction after the call. If the caller was an "<a
1842 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswelle4c57cc2005-05-12 16:52:32 +00001843at the beginning of the "normal" destination block. If the instruction
Chris Lattner261efe92003-11-25 01:02:51 +00001844returns a value, that value shall set the call or invoke instruction's
Devang Patelc3fc6df2008-03-10 20:49:15 +00001845return value. If the instruction returns multiple values then these
Devang Patel0dbb4a12008-03-11 05:51:59 +00001846values can only be accessed through a '<a href="#i_getresult"><tt>getresult</tt>
1847</a>' instruction.</p>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001848
Chris Lattner00950542001-06-06 20:29:01 +00001849<h5>Example:</h5>
Chris Lattnerf4cde4e2008-04-23 04:59:35 +00001850
1851<pre>
1852 ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner7faa8832002-04-14 06:13:44 +00001853 ret void <i>; Return from a void function</i>
Devang Patelc3fc6df2008-03-10 20:49:15 +00001854 ret i32 4, i8 2 <i>; Return two values 4 and 2 </i>
Chris Lattner00950542001-06-06 20:29:01 +00001855</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001856</div>
Chris Lattner00950542001-06-06 20:29:01 +00001857<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00001858<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001859<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001860<h5>Syntax:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001861<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 +00001862</pre>
Chris Lattner00950542001-06-06 20:29:01 +00001863<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001864<p>The '<tt>br</tt>' instruction is used to cause control flow to
1865transfer to a different basic block in the current function. There are
1866two forms of this instruction, corresponding to a conditional branch
1867and an unconditional branch.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001868<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00001869<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencerc78f3372007-01-12 03:35:51 +00001870single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Reid Spencerde151942007-02-19 23:54:10 +00001871unconditional form of the '<tt>br</tt>' instruction takes a single
1872'<tt>label</tt>' value as a target.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001873<h5>Semantics:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001874<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00001875argument is evaluated. If the value is <tt>true</tt>, control flows
1876to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1877control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001878<h5>Example:</h5>
Reid Spencerc78f3372007-01-12 03:35:51 +00001879<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 +00001880 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 +00001881</div>
Chris Lattner00950542001-06-06 20:29:01 +00001882<!-- _______________________________________________________________________ -->
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001883<div class="doc_subsubsection">
1884 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1885</div>
1886
Misha Brukman9d0919f2003-11-08 01:05:38 +00001887<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00001888<h5>Syntax:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001889
1890<pre>
1891 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1892</pre>
1893
Chris Lattner00950542001-06-06 20:29:01 +00001894<h5>Overview:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001895
1896<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1897several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman9d0919f2003-11-08 01:05:38 +00001898instruction, allowing a branch to occur to one of many possible
1899destinations.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001900
1901
Chris Lattner00950542001-06-06 20:29:01 +00001902<h5>Arguments:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001903
1904<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1905comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1906an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1907table is not allowed to contain duplicate constant entries.</p>
1908
Chris Lattner00950542001-06-06 20:29:01 +00001909<h5>Semantics:</h5>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001910
Chris Lattner261efe92003-11-25 01:02:51 +00001911<p>The <tt>switch</tt> instruction specifies a table of values and
1912destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswell84114752004-06-25 16:05:06 +00001913table is searched for the given value. If the value is found, control flow is
1914transfered to the corresponding destination; otherwise, control flow is
1915transfered to the default destination.</p>
Chris Lattner00950542001-06-06 20:29:01 +00001916
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001917<h5>Implementation:</h5>
1918
1919<p>Depending on properties of the target machine and the particular
1920<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswell84114752004-06-25 16:05:06 +00001921ways. For example, it could be generated as a series of chained conditional
1922branches or with a lookup table.</p>
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001923
1924<h5>Example:</h5>
1925
1926<pre>
1927 <i>; Emulate a conditional br instruction</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00001928 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerca86e162006-12-31 07:07:53 +00001929 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001930
1931 <i>; Emulate an unconditional br instruction</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001932 switch i32 0, label %dest [ ]
Chris Lattnerc88c17b2004-02-24 04:54:45 +00001933
1934 <i>; Implement a jump table:</i>
Reid Spencerca86e162006-12-31 07:07:53 +00001935 switch i32 %val, label %otherwise [ i32 0, label %onzero
1936 i32 1, label %onone
1937 i32 2, label %ontwo ]
Chris Lattner00950542001-06-06 20:29:01 +00001938</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00001939</div>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001940
Chris Lattner00950542001-06-06 20:29:01 +00001941<!-- _______________________________________________________________________ -->
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001942<div class="doc_subsubsection">
1943 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1944</div>
1945
Misha Brukman9d0919f2003-11-08 01:05:38 +00001946<div class="doc_text">
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001947
Chris Lattner00950542001-06-06 20:29:01 +00001948<h5>Syntax:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001949
1950<pre>
Nick Lewyckyd703f652008-03-16 07:18:12 +00001951 &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 +00001952 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001953</pre>
1954
Chris Lattner6536cfe2002-05-06 22:08:29 +00001955<h5>Overview:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001956
1957<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1958function, with the possibility of control flow transfer to either the
John Criswelle4c57cc2005-05-12 16:52:32 +00001959'<tt>normal</tt>' label or the
1960'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001961"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1962"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswelle4c57cc2005-05-12 16:52:32 +00001963href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
Devang Patelc3fc6df2008-03-10 20:49:15 +00001964continued at the dynamically nearest "exception" label. If the callee function
Devang Patel0dbb4a12008-03-11 05:51:59 +00001965returns multiple values then individual return values are only accessible through
1966a '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001967
Chris Lattner00950542001-06-06 20:29:01 +00001968<h5>Arguments:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001969
Misha Brukman9d0919f2003-11-08 01:05:38 +00001970<p>This instruction requires several arguments:</p>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001971
Chris Lattner00950542001-06-06 20:29:01 +00001972<ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001973 <li>
Duncan Sands8036ca42007-03-30 12:22:09 +00001974 The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001975 convention</a> the call should use. If none is specified, the call defaults
1976 to using C calling conventions.
1977 </li>
1978 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1979 function value being invoked. In most cases, this is a direct function
1980 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1981 an arbitrary pointer to function value.
1982 </li>
1983
1984 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1985 function to be invoked. </li>
1986
1987 <li>'<tt>function args</tt>': argument list whose types match the function
1988 signature argument types. If the function signature indicates the function
1989 accepts a variable number of arguments, the extra arguments can be
1990 specified. </li>
1991
1992 <li>'<tt>normal label</tt>': the label reached when the called function
1993 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1994
1995 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1996 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1997
Chris Lattner00950542001-06-06 20:29:01 +00001998</ol>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00001999
Chris Lattner00950542001-06-06 20:29:01 +00002000<h5>Semantics:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002001
Misha Brukman9d0919f2003-11-08 01:05:38 +00002002<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002003href="#i_call">call</a></tt>' instruction in most regards. The primary
2004difference is that it establishes an association with a label, which is used by
2005the runtime library to unwind the stack.</p>
2006
2007<p>This instruction is used in languages with destructors to ensure that proper
2008cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
2009exception. Additionally, this is important for implementation of
2010'<tt>catch</tt>' clauses in high-level languages that support them.</p>
2011
Chris Lattner00950542001-06-06 20:29:01 +00002012<h5>Example:</h5>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00002013<pre>
Nick Lewyckyd703f652008-03-16 07:18:12 +00002014 %retval = invoke i32 @Test(i32 15) to label %Continue
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002015 unwind label %TestCleanup <i>; {i32}:retval set</i>
Nick Lewyckyd703f652008-03-16 07:18:12 +00002016 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002017 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner00950542001-06-06 20:29:01 +00002018</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002019</div>
Chris Lattner35eca582004-10-16 18:04:13 +00002020
2021
Chris Lattner27f71f22003-09-03 00:41:47 +00002022<!-- _______________________________________________________________________ -->
Chris Lattner35eca582004-10-16 18:04:13 +00002023
Chris Lattner261efe92003-11-25 01:02:51 +00002024<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
2025Instruction</a> </div>
Chris Lattner35eca582004-10-16 18:04:13 +00002026
Misha Brukman9d0919f2003-11-08 01:05:38 +00002027<div class="doc_text">
Chris Lattner35eca582004-10-16 18:04:13 +00002028
Chris Lattner27f71f22003-09-03 00:41:47 +00002029<h5>Syntax:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00002030<pre>
2031 unwind
2032</pre>
2033
Chris Lattner27f71f22003-09-03 00:41:47 +00002034<h5>Overview:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00002035
2036<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
2037at the first callee in the dynamic call stack which used an <a
2038href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
2039primarily used to implement exception handling.</p>
2040
Chris Lattner27f71f22003-09-03 00:41:47 +00002041<h5>Semantics:</h5>
Chris Lattner35eca582004-10-16 18:04:13 +00002042
Chris Lattner72ed2002008-04-19 21:01:16 +00002043<p>The '<tt>unwind</tt>' instruction causes execution of the current function to
Chris Lattner35eca582004-10-16 18:04:13 +00002044immediately halt. The dynamic call stack is then searched for the first <a
2045href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
2046execution continues at the "exceptional" destination block specified by the
2047<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
2048dynamic call chain, undefined behavior results.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002049</div>
Chris Lattner35eca582004-10-16 18:04:13 +00002050
2051<!-- _______________________________________________________________________ -->
2052
2053<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
2054Instruction</a> </div>
2055
2056<div class="doc_text">
2057
2058<h5>Syntax:</h5>
2059<pre>
2060 unreachable
2061</pre>
2062
2063<h5>Overview:</h5>
2064
2065<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
2066instruction is used to inform the optimizer that a particular portion of the
2067code is not reachable. This can be used to indicate that the code after a
2068no-return function cannot be reached, and other facts.</p>
2069
2070<h5>Semantics:</h5>
2071
2072<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
2073</div>
2074
2075
2076
Chris Lattner00950542001-06-06 20:29:01 +00002077<!-- ======================================================================= -->
Chris Lattner261efe92003-11-25 01:02:51 +00002078<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002079<div class="doc_text">
Chris Lattner261efe92003-11-25 01:02:51 +00002080<p>Binary operators are used to do most of the computation in a
Chris Lattner5a158142008-04-01 18:47:32 +00002081program. They require two operands of the same type, execute an operation on them, and
John Criswell9e2485c2004-12-10 15:51:16 +00002082produce a single value. The operands might represent
Reid Spencer485bad12007-02-15 03:07:05 +00002083multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattner5a158142008-04-01 18:47:32 +00002084The result value has the same type as its operands.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002085<p>There are several different binary operators:</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002086</div>
Chris Lattner00950542001-06-06 20:29:01 +00002087<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002088<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
2089Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002090<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002091<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002092<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 +00002093</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002094<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002095<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002096<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002097<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnera58561b2004-08-12 19:12:28 +00002098 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
Reid Spencer485bad12007-02-15 03:07:05 +00002099 This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00002100Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002101<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002102<p>The value produced is the integer or floating point sum of the two
2103operands.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002104<p>If an integer sum has unsigned overflow, the result returned is the
2105mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2106the result.</p>
2107<p>Because LLVM integers use a two's complement representation, this
2108instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002109<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002110<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00002111</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002112</div>
Chris Lattner00950542001-06-06 20:29:01 +00002113<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002114<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
2115Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002116<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002117<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002118<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 +00002119</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002120<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002121<p>The '<tt>sub</tt>' instruction returns the difference of its two
2122operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002123<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
2124instruction present in most other intermediate representations.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002125<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002126<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00002127 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00002128values.
Reid Spencer485bad12007-02-15 03:07:05 +00002129This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00002130Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002131<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002132<p>The value produced is the integer or floating point difference of
2133the two operands.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002134<p>If an integer difference has unsigned overflow, the result returned is the
2135mathematical result modulo 2<sup>n</sup>, where n is the bit width of
2136the result.</p>
2137<p>Because LLVM integers use a two's complement representation, this
2138instruction is appropriate for both signed and unsigned integers.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002139<h5>Example:</h5>
Bill Wendlingaac388b2007-05-29 09:42:13 +00002140<pre>
2141 &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002142 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner00950542001-06-06 20:29:01 +00002143</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002144</div>
Chris Lattner00950542001-06-06 20:29:01 +00002145<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002146<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
2147Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002148<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002149<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002150<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 +00002151</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002152<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002153<p>The '<tt>mul</tt>' instruction returns the product of its two
2154operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002155<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002156<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner261efe92003-11-25 01:02:51 +00002157 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnera58561b2004-08-12 19:12:28 +00002158values.
Reid Spencer485bad12007-02-15 03:07:05 +00002159This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnera58561b2004-08-12 19:12:28 +00002160Both arguments must have identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002161<h5>Semantics:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002162<p>The value produced is the integer or floating point product of the
Misha Brukman9d0919f2003-11-08 01:05:38 +00002163two operands.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002164<p>If the result of an integer multiplication has unsigned overflow,
2165the result returned is the mathematical result modulo
21662<sup>n</sup>, where n is the bit width of the result.</p>
2167<p>Because LLVM integers use a two's complement representation, and the
2168result is the same width as the operands, this instruction returns the
2169correct result for both signed and unsigned integers. If a full product
2170(e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands
2171should be sign-extended or zero-extended as appropriate to the
2172width of the full product.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002173<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002174<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner00950542001-06-06 20:29:01 +00002175</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002176</div>
Chris Lattner00950542001-06-06 20:29:01 +00002177<!-- _______________________________________________________________________ -->
Reid Spencer1628cec2006-10-26 06:15:43 +00002178<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
2179</a></div>
2180<div class="doc_text">
2181<h5>Syntax:</h5>
2182<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2183</pre>
2184<h5>Overview:</h5>
2185<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
2186operands.</p>
2187<h5>Arguments:</h5>
2188<p>The two arguments to the '<tt>udiv</tt>' instruction must be
2189<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer485bad12007-02-15 03:07:05 +00002190types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer1628cec2006-10-26 06:15:43 +00002191of the values in which case the elements must be integers.</p>
2192<h5>Semantics:</h5>
Chris Lattner5ec89832008-01-28 00:36:27 +00002193<p>The value produced is the unsigned integer quotient of the two operands.</p>
2194<p>Note that unsigned integer division and signed integer division are distinct
2195operations; for signed integer division, use '<tt>sdiv</tt>'.</p>
2196<p>Division by zero leads to undefined behavior.</p>
Reid Spencer1628cec2006-10-26 06:15:43 +00002197<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002198<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00002199</pre>
2200</div>
2201<!-- _______________________________________________________________________ -->
2202<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
2203</a> </div>
2204<div class="doc_text">
2205<h5>Syntax:</h5>
2206<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2207</pre>
2208<h5>Overview:</h5>
2209<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
2210operands.</p>
2211<h5>Arguments:</h5>
2212<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
2213<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer485bad12007-02-15 03:07:05 +00002214types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer1628cec2006-10-26 06:15:43 +00002215of the values in which case the elements must be integers.</p>
2216<h5>Semantics:</h5>
Chris Lattnera73afe02008-04-01 18:45:27 +00002217<p>The value produced is the signed integer quotient of the two operands rounded towards zero.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002218<p>Note that signed integer division and unsigned integer division are distinct
2219operations; for unsigned integer division, use '<tt>udiv</tt>'.</p>
2220<p>Division by zero leads to undefined behavior. Overflow also leads to
2221undefined behavior; this is a rare case, but can occur, for example,
2222by doing a 32-bit division of -2147483648 by -1.</p>
Reid Spencer1628cec2006-10-26 06:15:43 +00002223<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002224<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer1628cec2006-10-26 06:15:43 +00002225</pre>
2226</div>
2227<!-- _______________________________________________________________________ -->
2228<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002229Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002230<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002231<h5>Syntax:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002232<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 +00002233</pre>
2234<h5>Overview:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002235<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner261efe92003-11-25 01:02:51 +00002236operands.</p>
2237<h5>Arguments:</h5>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002238<p>The two arguments to the '<tt>fdiv</tt>' instruction must be
Reid Spencer1628cec2006-10-26 06:15:43 +00002239<a href="#t_floating">floating point</a> values. Both arguments must have
Reid Spencer485bad12007-02-15 03:07:05 +00002240identical types. This instruction can also take <a href="#t_vector">vector</a>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002241versions of floating point values.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002242<h5>Semantics:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002243<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002244<h5>Example:</h5>
Reid Spencer1628cec2006-10-26 06:15:43 +00002245<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002246</pre>
2247</div>
2248<!-- _______________________________________________________________________ -->
Reid Spencer0a783f72006-11-02 01:53:59 +00002249<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
2250</div>
2251<div class="doc_text">
2252<h5>Syntax:</h5>
2253<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2254</pre>
2255<h5>Overview:</h5>
2256<p>The '<tt>urem</tt>' instruction returns the remainder from the
2257unsigned division of its two arguments.</p>
2258<h5>Arguments:</h5>
2259<p>The two arguments to the '<tt>urem</tt>' instruction must be
2260<a href="#t_integer">integer</a> values. Both arguments must have identical
Dan Gohman80176312007-11-05 23:35:22 +00002261types. This instruction can also take <a href="#t_vector">vector</a> versions
2262of the values in which case the elements must be integers.</p>
Reid Spencer0a783f72006-11-02 01:53:59 +00002263<h5>Semantics:</h5>
2264<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
Chris Lattnera73afe02008-04-01 18:45:27 +00002265This instruction always performs an unsigned division to get the remainder.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002266<p>Note that unsigned integer remainder and signed integer remainder are
2267distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p>
2268<p>Taking the remainder of a division by zero leads to undefined behavior.</p>
Reid Spencer0a783f72006-11-02 01:53:59 +00002269<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002270<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00002271</pre>
2272
2273</div>
2274<!-- _______________________________________________________________________ -->
2275<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner261efe92003-11-25 01:02:51 +00002276Instruction</a> </div>
2277<div class="doc_text">
2278<h5>Syntax:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002279<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 +00002280</pre>
2281<h5>Overview:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002282<p>The '<tt>srem</tt>' instruction returns the remainder from the
Dan Gohman80176312007-11-05 23:35:22 +00002283signed division of its two operands. This instruction can also take
2284<a href="#t_vector">vector</a> versions of the values in which case
2285the elements must be integers.</p>
Chris Lattnerc7d3ab32008-01-04 04:33:49 +00002286
Chris Lattner261efe92003-11-25 01:02:51 +00002287<h5>Arguments:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002288<p>The two arguments to the '<tt>srem</tt>' instruction must be
2289<a href="#t_integer">integer</a> values. Both arguments must have identical
2290types.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002291<h5>Semantics:</h5>
Reid Spencer0a783f72006-11-02 01:53:59 +00002292<p>This instruction returns the <i>remainder</i> of a division (where the result
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002293has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i>
2294operator (where the result has the same sign as the divisor, <tt>var2</tt>) of
2295a value. For more information about the difference, see <a
Chris Lattner261efe92003-11-25 01:02:51 +00002296 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002297Math Forum</a>. For a table of how this is implemented in various languages,
Reid Spencer64f5c6c2007-03-24 22:40:44 +00002298please see <a href="http://en.wikipedia.org/wiki/Modulo_operation">
Reid Spencerc9fdfc82007-03-24 22:23:39 +00002299Wikipedia: modulo operation</a>.</p>
Chris Lattner5ec89832008-01-28 00:36:27 +00002300<p>Note that signed integer remainder and unsigned integer remainder are
2301distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p>
2302<p>Taking the remainder of a division by zero leads to undefined behavior.
2303Overflow also leads to undefined behavior; this is a rare case, but can occur,
2304for example, by taking the remainder of a 32-bit division of -2147483648 by -1.
2305(The remainder doesn't actually overflow, but this rule lets srem be
2306implemented using instructions that return both the result of the division
2307and the remainder.)</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002308<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002309<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer0a783f72006-11-02 01:53:59 +00002310</pre>
2311
2312</div>
2313<!-- _______________________________________________________________________ -->
2314<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
2315Instruction</a> </div>
2316<div class="doc_text">
2317<h5>Syntax:</h5>
2318<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2319</pre>
2320<h5>Overview:</h5>
2321<p>The '<tt>frem</tt>' instruction returns the remainder from the
2322division of its two operands.</p>
2323<h5>Arguments:</h5>
2324<p>The two arguments to the '<tt>frem</tt>' instruction must be
2325<a href="#t_floating">floating point</a> values. Both arguments must have
Dan Gohman80176312007-11-05 23:35:22 +00002326identical types. This instruction can also take <a href="#t_vector">vector</a>
2327versions of floating point values.</p>
Reid Spencer0a783f72006-11-02 01:53:59 +00002328<h5>Semantics:</h5>
Chris Lattnera73afe02008-04-01 18:45:27 +00002329<p>This instruction returns the <i>remainder</i> of a division.
2330The remainder has the same sign as the dividend.</p>
Reid Spencer0a783f72006-11-02 01:53:59 +00002331<h5>Example:</h5>
2332<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002333</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002334</div>
Robert Bocchino7b81c752006-02-17 21:18:08 +00002335
Reid Spencer8e11bf82007-02-02 13:57:07 +00002336<!-- ======================================================================= -->
2337<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
2338Operations</a> </div>
2339<div class="doc_text">
2340<p>Bitwise binary operators are used to do various forms of
2341bit-twiddling in a program. They are generally very efficient
2342instructions and can commonly be strength reduced from other
Chris Lattnera73afe02008-04-01 18:45:27 +00002343instructions. They require two operands of the same type, execute an operation on them,
2344and produce a single value. The resulting value is the same type as its operands.</p>
Reid Spencer8e11bf82007-02-02 13:57:07 +00002345</div>
2346
Reid Spencer569f2fa2007-01-31 21:39:12 +00002347<!-- _______________________________________________________________________ -->
2348<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2349Instruction</a> </div>
2350<div class="doc_text">
2351<h5>Syntax:</h5>
2352<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2353</pre>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002354
Reid Spencer569f2fa2007-01-31 21:39:12 +00002355<h5>Overview:</h5>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002356
Reid Spencer569f2fa2007-01-31 21:39:12 +00002357<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2358the left a specified number of bits.</p>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002359
Reid Spencer569f2fa2007-01-31 21:39:12 +00002360<h5>Arguments:</h5>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002361
Reid Spencer569f2fa2007-01-31 21:39:12 +00002362<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
Chris Lattner72ed2002008-04-19 21:01:16 +00002363 href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an
2364unsigned value.</p>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002365
Reid Spencer569f2fa2007-01-31 21:39:12 +00002366<h5>Semantics:</h5>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002367
Chris Lattnera73afe02008-04-01 18:45:27 +00002368<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup> mod 2<sup>n</sup>,
2369where n is the width of the result. If <tt>var2</tt> is (statically or dynamically) negative or
2370equal to or larger than the number of bits in <tt>var1</tt>, the result is undefined.</p>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002371
Reid Spencer569f2fa2007-01-31 21:39:12 +00002372<h5>Example:</h5><pre>
2373 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
2374 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
2375 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002376 &lt;result&gt; = shl i32 1, 32 <i>; undefined</i>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002377</pre>
2378</div>
2379<!-- _______________________________________________________________________ -->
2380<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
2381Instruction</a> </div>
2382<div class="doc_text">
2383<h5>Syntax:</h5>
2384<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2385</pre>
2386
2387<h5>Overview:</h5>
2388<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002389operand shifted to the right a specified number of bits with zero fill.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002390
2391<h5>Arguments:</h5>
2392<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
Chris Lattner72ed2002008-04-19 21:01:16 +00002393<a href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an
2394unsigned value.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002395
2396<h5>Semantics:</h5>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002397
Reid Spencer569f2fa2007-01-31 21:39:12 +00002398<p>This instruction always performs a logical shift right operation. The most
2399significant bits of the result will be filled with zero bits after the
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002400shift. If <tt>var2</tt> is (statically or dynamically) equal to or larger than
2401the number of bits in <tt>var1</tt>, the result is undefined.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002402
2403<h5>Example:</h5>
2404<pre>
2405 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
2406 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
2407 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
2408 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002409 &lt;result&gt; = lshr i32 1, 32 <i>; undefined</i>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002410</pre>
2411</div>
2412
Reid Spencer8e11bf82007-02-02 13:57:07 +00002413<!-- _______________________________________________________________________ -->
Reid Spencer569f2fa2007-01-31 21:39:12 +00002414<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2415Instruction</a> </div>
2416<div class="doc_text">
2417
2418<h5>Syntax:</h5>
2419<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2420</pre>
2421
2422<h5>Overview:</h5>
2423<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002424operand shifted to the right a specified number of bits with sign extension.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002425
2426<h5>Arguments:</h5>
2427<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
Chris Lattner72ed2002008-04-19 21:01:16 +00002428<a href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an
2429unsigned value.</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002430
2431<h5>Semantics:</h5>
2432<p>This instruction always performs an arithmetic shift right operation,
2433The most significant bits of the result will be filled with the sign bit
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002434of <tt>var1</tt>. If <tt>var2</tt> is (statically or dynamically) equal to or
2435larger than the number of bits in <tt>var1</tt>, the result is undefined.
2436</p>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002437
2438<h5>Example:</h5>
2439<pre>
2440 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
2441 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
2442 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
2443 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
Chris Lattner6ccc2d52007-10-03 21:01:14 +00002444 &lt;result&gt; = ashr i32 1, 32 <i>; undefined</i>
Reid Spencer569f2fa2007-01-31 21:39:12 +00002445</pre>
2446</div>
2447
Chris Lattner00950542001-06-06 20:29:01 +00002448<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002449<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
2450Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002451<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002452<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002453<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 +00002454</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002455<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002456<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
2457its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002458<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002459<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002460 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002461identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002462<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002463<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002464<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002465<div style="align: center">
Misha Brukman9d0919f2003-11-08 01:05:38 +00002466<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner261efe92003-11-25 01:02:51 +00002467 <tbody>
2468 <tr>
2469 <td>In0</td>
2470 <td>In1</td>
2471 <td>Out</td>
2472 </tr>
2473 <tr>
2474 <td>0</td>
2475 <td>0</td>
2476 <td>0</td>
2477 </tr>
2478 <tr>
2479 <td>0</td>
2480 <td>1</td>
2481 <td>0</td>
2482 </tr>
2483 <tr>
2484 <td>1</td>
2485 <td>0</td>
2486 <td>0</td>
2487 </tr>
2488 <tr>
2489 <td>1</td>
2490 <td>1</td>
2491 <td>1</td>
2492 </tr>
2493 </tbody>
2494</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002495</div>
Chris Lattner00950542001-06-06 20:29:01 +00002496<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002497<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
2498 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
2499 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner00950542001-06-06 20:29:01 +00002500</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002501</div>
Chris Lattner00950542001-06-06 20:29:01 +00002502<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002503<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002504<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002505<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002506<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 +00002507</pre>
Chris Lattner261efe92003-11-25 01:02:51 +00002508<h5>Overview:</h5>
2509<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2510or of its two operands.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002511<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002512<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002513 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002514identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002515<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002516<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002517<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002518<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002519<table border="1" cellspacing="0" cellpadding="4">
2520 <tbody>
2521 <tr>
2522 <td>In0</td>
2523 <td>In1</td>
2524 <td>Out</td>
2525 </tr>
2526 <tr>
2527 <td>0</td>
2528 <td>0</td>
2529 <td>0</td>
2530 </tr>
2531 <tr>
2532 <td>0</td>
2533 <td>1</td>
2534 <td>1</td>
2535 </tr>
2536 <tr>
2537 <td>1</td>
2538 <td>0</td>
2539 <td>1</td>
2540 </tr>
2541 <tr>
2542 <td>1</td>
2543 <td>1</td>
2544 <td>1</td>
2545 </tr>
2546 </tbody>
2547</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002548</div>
Chris Lattner00950542001-06-06 20:29:01 +00002549<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002550<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2551 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2552 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner00950542001-06-06 20:29:01 +00002553</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002554</div>
Chris Lattner00950542001-06-06 20:29:01 +00002555<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002556<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2557Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002558<div class="doc_text">
Chris Lattner00950542001-06-06 20:29:01 +00002559<h5>Syntax:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002560<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 +00002561</pre>
Chris Lattner00950542001-06-06 20:29:01 +00002562<h5>Overview:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002563<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2564or of its two operands. The <tt>xor</tt> is used to implement the
2565"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002566<h5>Arguments:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002567<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner3b19d652007-01-15 01:54:13 +00002568 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner261efe92003-11-25 01:02:51 +00002569identical types.</p>
Chris Lattner00950542001-06-06 20:29:01 +00002570<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002571<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002572<p> </p>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002573<div style="align: center">
Chris Lattner261efe92003-11-25 01:02:51 +00002574<table border="1" cellspacing="0" cellpadding="4">
2575 <tbody>
2576 <tr>
2577 <td>In0</td>
2578 <td>In1</td>
2579 <td>Out</td>
2580 </tr>
2581 <tr>
2582 <td>0</td>
2583 <td>0</td>
2584 <td>0</td>
2585 </tr>
2586 <tr>
2587 <td>0</td>
2588 <td>1</td>
2589 <td>1</td>
2590 </tr>
2591 <tr>
2592 <td>1</td>
2593 <td>0</td>
2594 <td>1</td>
2595 </tr>
2596 <tr>
2597 <td>1</td>
2598 <td>1</td>
2599 <td>0</td>
2600 </tr>
2601 </tbody>
2602</table>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00002603</div>
Chris Lattner261efe92003-11-25 01:02:51 +00002604<p> </p>
Chris Lattner00950542001-06-06 20:29:01 +00002605<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002606<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2607 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2608 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2609 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner00950542001-06-06 20:29:01 +00002610</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002611</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002612
Chris Lattner00950542001-06-06 20:29:01 +00002613<!-- ======================================================================= -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002614<div class="doc_subsection">
Chris Lattner3df241e2006-04-08 23:07:04 +00002615 <a name="vectorops">Vector Operations</a>
2616</div>
2617
2618<div class="doc_text">
2619
2620<p>LLVM supports several instructions to represent vector operations in a
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002621target-independent manner. These instructions cover the element-access and
Chris Lattner3df241e2006-04-08 23:07:04 +00002622vector-specific operations needed to process vectors effectively. While LLVM
2623does directly support these vector operations, many sophisticated algorithms
2624will want to use target-specific intrinsics to take full advantage of a specific
2625target.</p>
2626
2627</div>
2628
2629<!-- _______________________________________________________________________ -->
2630<div class="doc_subsubsection">
2631 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2632</div>
2633
2634<div class="doc_text">
2635
2636<h5>Syntax:</h5>
2637
2638<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002639 &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 +00002640</pre>
2641
2642<h5>Overview:</h5>
2643
2644<p>
2645The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer485bad12007-02-15 03:07:05 +00002646element from a vector at a specified index.
Chris Lattner3df241e2006-04-08 23:07:04 +00002647</p>
2648
2649
2650<h5>Arguments:</h5>
2651
2652<p>
2653The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer485bad12007-02-15 03:07:05 +00002654value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattner3df241e2006-04-08 23:07:04 +00002655an index indicating the position from which to extract the element.
2656The index may be a variable.</p>
2657
2658<h5>Semantics:</h5>
2659
2660<p>
2661The result is a scalar of the same type as the element type of
2662<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2663<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2664results are undefined.
2665</p>
2666
2667<h5>Example:</h5>
2668
2669<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002670 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattner3df241e2006-04-08 23:07:04 +00002671</pre>
2672</div>
2673
2674
2675<!-- _______________________________________________________________________ -->
2676<div class="doc_subsubsection">
2677 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2678</div>
2679
2680<div class="doc_text">
2681
2682<h5>Syntax:</h5>
2683
2684<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002685 &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 +00002686</pre>
2687
2688<h5>Overview:</h5>
2689
2690<p>
2691The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer485bad12007-02-15 03:07:05 +00002692element into a vector at a specified index.
Chris Lattner3df241e2006-04-08 23:07:04 +00002693</p>
2694
2695
2696<h5>Arguments:</h5>
2697
2698<p>
2699The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer485bad12007-02-15 03:07:05 +00002700value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattner3df241e2006-04-08 23:07:04 +00002701scalar value whose type must equal the element type of the first
2702operand. The third operand is an index indicating the position at
2703which to insert the value. The index may be a variable.</p>
2704
2705<h5>Semantics:</h5>
2706
2707<p>
Reid Spencer485bad12007-02-15 03:07:05 +00002708The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattner3df241e2006-04-08 23:07:04 +00002709element values are those of <tt>val</tt> except at position
2710<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2711exceeds the length of <tt>val</tt>, the results are undefined.
2712</p>
2713
2714<h5>Example:</h5>
2715
2716<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002717 %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 +00002718</pre>
2719</div>
2720
2721<!-- _______________________________________________________________________ -->
2722<div class="doc_subsubsection">
2723 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2724</div>
2725
2726<div class="doc_text">
2727
2728<h5>Syntax:</h5>
2729
2730<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002731 &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 +00002732</pre>
2733
2734<h5>Overview:</h5>
2735
2736<p>
2737The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2738from two input vectors, returning a vector of the same type.
2739</p>
2740
2741<h5>Arguments:</h5>
2742
2743<p>
2744The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2745with types that match each other and types that match the result of the
2746instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerca86e162006-12-31 07:07:53 +00002747of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattner3df241e2006-04-08 23:07:04 +00002748</p>
2749
2750<p>
2751The shuffle mask operand is required to be a constant vector with either
2752constant integer or undef values.
2753</p>
2754
2755<h5>Semantics:</h5>
2756
2757<p>
2758The elements of the two input vectors are numbered from left to right across
2759both of the vectors. The shuffle mask operand specifies, for each element of
2760the result vector, which element of the two input registers the result element
2761gets. The element selector may be undef (meaning "don't care") and the second
2762operand may be undef if performing a shuffle from only one vector.
2763</p>
2764
2765<h5>Example:</h5>
2766
2767<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002768 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002769 &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 +00002770 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2771 &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 +00002772</pre>
2773</div>
2774
Tanya Lattner09474292006-04-14 19:24:33 +00002775
Chris Lattner3df241e2006-04-08 23:07:04 +00002776<!-- ======================================================================= -->
2777<div class="doc_subsection">
Chris Lattner884a9702006-08-15 00:45:58 +00002778 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002779</div>
2780
Misha Brukman9d0919f2003-11-08 01:05:38 +00002781<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002782
Chris Lattner261efe92003-11-25 01:02:51 +00002783<p>A key design point of an SSA-based representation is how it
2784represents memory. In LLVM, no memory locations are in SSA form, which
2785makes things very simple. This section describes how to read, write,
John Criswell9e2485c2004-12-10 15:51:16 +00002786allocate, and free memory in LLVM.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002787
Misha Brukman9d0919f2003-11-08 01:05:38 +00002788</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002789
Chris Lattner00950542001-06-06 20:29:01 +00002790<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002791<div class="doc_subsubsection">
2792 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2793</div>
2794
Misha Brukman9d0919f2003-11-08 01:05:38 +00002795<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002796
Chris Lattner00950542001-06-06 20:29:01 +00002797<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002798
2799<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002800 &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 +00002801</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002802
Chris Lattner00950542001-06-06 20:29:01 +00002803<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002804
Chris Lattner261efe92003-11-25 01:02:51 +00002805<p>The '<tt>malloc</tt>' instruction allocates memory from the system
Christopher Lamb303dae92007-12-17 01:00:21 +00002806heap and returns a pointer to it. The object is always allocated in the generic
2807address space (address space zero).</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002808
Chris Lattner00950542001-06-06 20:29:01 +00002809<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002810
2811<p>The '<tt>malloc</tt>' instruction allocates
2812<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswell6e4ca612004-02-24 16:13:56 +00002813bytes of memory from the operating system and returns a pointer of the
Chris Lattner2cbdc452005-11-06 08:02:57 +00002814appropriate type to the program. If "NumElements" is specified, it is the
Gabor Greif1acd2ee2008-02-09 22:24:34 +00002815number of elements allocated, otherwise "NumElements" is defaulted to be one.
Chris Lattner4316dec2008-04-02 00:38:26 +00002816If a constant alignment is specified, the value result of the allocation is guaranteed to
Gabor Greif1acd2ee2008-02-09 22:24:34 +00002817be aligned to at least that boundary. If not specified, or if zero, the target can
2818choose to align the allocation on any convenient boundary.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002819
Misha Brukman9d0919f2003-11-08 01:05:38 +00002820<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002821
Chris Lattner00950542001-06-06 20:29:01 +00002822<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002823
Chris Lattner261efe92003-11-25 01:02:51 +00002824<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
Chris Lattner72ed2002008-04-19 21:01:16 +00002825a pointer is returned. The result of a zero byte allocattion is undefined. The
2826result is null if there is insufficient memory available.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002827
Chris Lattner2cbdc452005-11-06 08:02:57 +00002828<h5>Example:</h5>
2829
2830<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002831 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002832
Bill Wendlingaac388b2007-05-29 09:42:13 +00002833 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2834 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2835 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2836 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2837 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner00950542001-06-06 20:29:01 +00002838</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002839</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002840
Chris Lattner00950542001-06-06 20:29:01 +00002841<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002842<div class="doc_subsubsection">
2843 <a name="i_free">'<tt>free</tt>' Instruction</a>
2844</div>
2845
Misha Brukman9d0919f2003-11-08 01:05:38 +00002846<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002847
Chris Lattner00950542001-06-06 20:29:01 +00002848<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002849
2850<pre>
2851 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner00950542001-06-06 20:29:01 +00002852</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002853
Chris Lattner00950542001-06-06 20:29:01 +00002854<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002855
Chris Lattner261efe92003-11-25 01:02:51 +00002856<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswellc1f786c2005-05-13 22:25:59 +00002857memory heap to be reallocated in the future.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002858
Chris Lattner00950542001-06-06 20:29:01 +00002859<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002860
Chris Lattner261efe92003-11-25 01:02:51 +00002861<p>'<tt>value</tt>' shall be a pointer value that points to a value
2862that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2863instruction.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002864
Chris Lattner00950542001-06-06 20:29:01 +00002865<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002866
John Criswell9e2485c2004-12-10 15:51:16 +00002867<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattnere0db56d2008-04-19 22:41:32 +00002868after this instruction executes. If the pointer is null, the operation
2869is a noop.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002870
Chris Lattner00950542001-06-06 20:29:01 +00002871<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002872
2873<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002874 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2875 free [4 x i8]* %array
Chris Lattner00950542001-06-06 20:29:01 +00002876</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002877</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002878
Chris Lattner00950542001-06-06 20:29:01 +00002879<!-- _______________________________________________________________________ -->
Chris Lattner2cbdc452005-11-06 08:02:57 +00002880<div class="doc_subsubsection">
2881 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2882</div>
2883
Misha Brukman9d0919f2003-11-08 01:05:38 +00002884<div class="doc_text">
Chris Lattner2cbdc452005-11-06 08:02:57 +00002885
Chris Lattner00950542001-06-06 20:29:01 +00002886<h5>Syntax:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002887
2888<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002889 &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 +00002890</pre>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002891
Chris Lattner00950542001-06-06 20:29:01 +00002892<h5>Overview:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002893
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002894<p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the
2895currently executing function, to be automatically released when this function
Christopher Lamb303dae92007-12-17 01:00:21 +00002896returns to its caller. The object is always allocated in the generic address
2897space (address space zero).</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002898
Chris Lattner00950542001-06-06 20:29:01 +00002899<h5>Arguments:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002900
John Criswell9e2485c2004-12-10 15:51:16 +00002901<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner261efe92003-11-25 01:02:51 +00002902bytes of memory on the runtime stack, returning a pointer of the
Gabor Greif1acd2ee2008-02-09 22:24:34 +00002903appropriate type to the program. If "NumElements" is specified, it is the
2904number of elements allocated, otherwise "NumElements" is defaulted to be one.
Chris Lattner4316dec2008-04-02 00:38:26 +00002905If a constant alignment is specified, the value result of the allocation is guaranteed
Gabor Greif1acd2ee2008-02-09 22:24:34 +00002906to be aligned to at least that boundary. If not specified, or if zero, the target
2907can choose to align the allocation on any convenient boundary.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002908
Misha Brukman9d0919f2003-11-08 01:05:38 +00002909<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002910
Chris Lattner00950542001-06-06 20:29:01 +00002911<h5>Semantics:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002912
Chris Lattner72ed2002008-04-19 21:01:16 +00002913<p>Memory is allocated; a pointer is returned. The operation is undefiend if
2914there is insufficient stack space for the allocation. '<tt>alloca</tt>'d
Chris Lattner261efe92003-11-25 01:02:51 +00002915memory is automatically released when the function returns. The '<tt>alloca</tt>'
2916instruction is commonly used to represent automatic variables that must
2917have an address available. When the function returns (either with the <tt><a
John Criswelldae2e932005-05-12 16:55:34 +00002918 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Chris Lattner4316dec2008-04-02 00:38:26 +00002919instructions), the memory is reclaimed. Allocating zero bytes
2920is legal, but the result is undefined.</p>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002921
Chris Lattner00950542001-06-06 20:29:01 +00002922<h5>Example:</h5>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002923
2924<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00002925 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00002926 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2927 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
Reid Spencerca86e162006-12-31 07:07:53 +00002928 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner00950542001-06-06 20:29:01 +00002929</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002930</div>
Chris Lattner2cbdc452005-11-06 08:02:57 +00002931
Chris Lattner00950542001-06-06 20:29:01 +00002932<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002933<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2934Instruction</a> </div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002935<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002936<h5>Syntax:</h5>
Christopher Lamb2330e4d2007-04-21 08:16:25 +00002937<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 +00002938<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002939<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002940<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002941<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell0ec250c2005-10-24 16:17:18 +00002942address from which to load. The pointer must point to a <a
Chris Lattnere53e5082004-06-03 22:57:15 +00002943 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell0ec250c2005-10-24 16:17:18 +00002944marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner261efe92003-11-25 01:02:51 +00002945the number or order of execution of this <tt>load</tt> with other
2946volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2947instructions. </p>
Chris Lattnera31d1d72008-01-06 21:04:43 +00002948<p>
Chris Lattner4316dec2008-04-02 00:38:26 +00002949The optional constant "align" argument specifies the alignment of the operation
Chris Lattnera31d1d72008-01-06 21:04:43 +00002950(that is, the alignment of the memory address). A value of 0 or an
2951omitted "align" argument means that the operation has the preferential
2952alignment for the target. It is the responsibility of the code emitter
2953to ensure that the alignment information is correct. Overestimating
2954the alignment results in an undefined behavior. Underestimating the
2955alignment may produce less efficient code. An alignment of 1 is always
2956safe.
2957</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002958<h5>Semantics:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002959<p>The location of memory pointed to is loaded.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002960<h5>Examples:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00002961<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner261efe92003-11-25 01:02:51 +00002962 <a
Reid Spencerca86e162006-12-31 07:07:53 +00002963 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2964 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002965</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002966</div>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002967<!-- _______________________________________________________________________ -->
Chris Lattner261efe92003-11-25 01:02:51 +00002968<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2969Instruction</a> </div>
Reid Spencer035ab572006-11-09 21:18:01 +00002970<div class="doc_text">
Chris Lattner2b7d3202002-05-06 03:03:22 +00002971<h5>Syntax:</h5>
Christopher Lamb2330e4d2007-04-21 08:16:25 +00002972<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt;[, align &lt;alignment&gt;] <i>; yields {void}</i>
2973 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 +00002974</pre>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002975<h5>Overview:</h5>
Misha Brukman9d0919f2003-11-08 01:05:38 +00002976<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002977<h5>Arguments:</h5>
Chris Lattner261efe92003-11-25 01:02:51 +00002978<p>There are two arguments to the '<tt>store</tt>' instruction: a value
Jeff Cohen6f1cc772007-04-22 01:17:39 +00002979to store and an address at which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner4316dec2008-04-02 00:38:26 +00002980operand must be a pointer to the <a href="#t_firstclass">first class</a> type
2981of the '<tt>&lt;value&gt;</tt>'
John Criswellc1f786c2005-05-13 22:25:59 +00002982operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner261efe92003-11-25 01:02:51 +00002983optimizer is not allowed to modify the number or order of execution of
2984this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2985 href="#i_store">store</a></tt> instructions.</p>
Chris Lattnera31d1d72008-01-06 21:04:43 +00002986<p>
Chris Lattner4316dec2008-04-02 00:38:26 +00002987The optional constant "align" argument specifies the alignment of the operation
Chris Lattnera31d1d72008-01-06 21:04:43 +00002988(that is, the alignment of the memory address). A value of 0 or an
2989omitted "align" argument means that the operation has the preferential
2990alignment for the target. It is the responsibility of the code emitter
2991to ensure that the alignment information is correct. Overestimating
2992the alignment results in an undefined behavior. Underestimating the
2993alignment may produce less efficient code. An alignment of 1 is always
2994safe.
2995</p>
Chris Lattner261efe92003-11-25 01:02:51 +00002996<h5>Semantics:</h5>
2997<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2998at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner2b7d3202002-05-06 03:03:22 +00002999<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003000<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Bill Wendling8c6c72d2007-10-22 05:10:05 +00003001 store i32 3, i32* %ptr <i>; yields {void}</i>
3002 %val = <a href="#i_load">load</a> i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner2b7d3202002-05-06 03:03:22 +00003003</pre>
Reid Spencer47ce1792006-11-09 21:15:49 +00003004</div>
3005
Chris Lattner2b7d3202002-05-06 03:03:22 +00003006<!-- _______________________________________________________________________ -->
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003007<div class="doc_subsubsection">
3008 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
3009</div>
3010
Misha Brukman9d0919f2003-11-08 01:05:38 +00003011<div class="doc_text">
Chris Lattner7faa8832002-04-14 06:13:44 +00003012<h5>Syntax:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003013<pre>
3014 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
3015</pre>
3016
Chris Lattner7faa8832002-04-14 06:13:44 +00003017<h5>Overview:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003018
3019<p>
3020The '<tt>getelementptr</tt>' instruction is used to get the address of a
3021subelement of an aggregate data structure.</p>
3022
Chris Lattner7faa8832002-04-14 06:13:44 +00003023<h5>Arguments:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003024
Reid Spencer85f5b5b2006-12-04 21:29:24 +00003025<p>This instruction takes a list of integer operands that indicate what
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003026elements of the aggregate object to index to. The actual types of the arguments
3027provided depend on the type of the first pointer argument. The
3028'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswellfc6b8952005-05-16 16:17:45 +00003029levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerca86e162006-12-31 07:07:53 +00003030structure, only <tt>i32</tt> integer constants are allowed. When indexing
Chris Lattner05d67092008-04-24 05:59:56 +00003031into an array or pointer, only integers of 32 or 64 bits are allowed; 32-bit
3032values will be sign extended to 64-bits if required.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003033
Chris Lattner261efe92003-11-25 01:02:51 +00003034<p>For example, let's consider a C code fragment and how it gets
3035compiled to LLVM:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003036
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003037<div class="doc_code">
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003038<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003039struct RT {
3040 char A;
Chris Lattnercabc8462007-05-29 15:43:56 +00003041 int B[10][20];
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003042 char C;
3043};
3044struct ST {
Chris Lattnercabc8462007-05-29 15:43:56 +00003045 int X;
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003046 double Y;
3047 struct RT Z;
3048};
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003049
Chris Lattnercabc8462007-05-29 15:43:56 +00003050int *foo(struct ST *s) {
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003051 return &amp;s[1].Z.B[5][13];
3052}
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003053</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003054</div>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003055
Misha Brukman9d0919f2003-11-08 01:05:38 +00003056<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003057
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003058<div class="doc_code">
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003059<pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003060%RT = type { i8 , [10 x [20 x i32]], i8 }
3061%ST = type { i32, double, %RT }
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003062
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003063define i32* %foo(%ST* %s) {
3064entry:
3065 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
3066 ret i32* %reg
3067}
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003068</pre>
Bill Wendling2f7a8b02007-05-29 09:04:49 +00003069</div>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003070
Chris Lattner7faa8832002-04-14 06:13:44 +00003071<h5>Semantics:</h5>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003072
3073<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswellc1f786c2005-05-13 22:25:59 +00003074on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencer85f5b5b2006-12-04 21:29:24 +00003075and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencer42ddd842006-12-03 16:53:48 +00003076<a href="#t_integer">integer</a> type but the value will always be sign extended
Chris Lattner4316dec2008-04-02 00:38:26 +00003077to 64-bits. <a href="#t_struct">Structure</a> and <a href="#t_pstruct">packed
3078structure</a> types require <tt>i32</tt> <b>constants</b>.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003079
Misha Brukman9d0919f2003-11-08 01:05:38 +00003080<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerca86e162006-12-31 07:07:53 +00003081type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003082}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerca86e162006-12-31 07:07:53 +00003083the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
3084i8 }</tt>' type, another structure. The third index indexes into the second
3085element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003086array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerca86e162006-12-31 07:07:53 +00003087'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
3088to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003089
Chris Lattner261efe92003-11-25 01:02:51 +00003090<p>Note that it is perfectly legal to index partially through a
3091structure, returning a pointer to an inner element. Because of this,
3092the LLVM code for the given testcase is equivalent to:</p>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003093
3094<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003095 define i32* %foo(%ST* %s) {
3096 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
Jeff Cohen6f1cc772007-04-22 01:17:39 +00003097 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
3098 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
Reid Spencerca86e162006-12-31 07:07:53 +00003099 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
3100 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
3101 ret i32* %t5
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003102 }
Chris Lattner6536cfe2002-05-06 22:08:29 +00003103</pre>
Chris Lattnere67a9512005-06-24 17:22:57 +00003104
3105<p>Note that it is undefined to access an array out of bounds: array and
3106pointer indexes must always be within the defined bounds of the array type.
Chris Lattner05d67092008-04-24 05:59:56 +00003107The one exception for this rule is zero length arrays. These arrays are
Chris Lattnere67a9512005-06-24 17:22:57 +00003108defined to be accessible as variable length arrays, which requires access
3109beyond the zero'th element.</p>
3110
Chris Lattner884a9702006-08-15 00:45:58 +00003111<p>The getelementptr instruction is often confusing. For some more insight
3112into how it works, see <a href="GetElementPtr.html">the getelementptr
3113FAQ</a>.</p>
3114
Chris Lattner7faa8832002-04-14 06:13:44 +00003115<h5>Example:</h5>
Chris Lattnere67a9512005-06-24 17:22:57 +00003116
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003117<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003118 <i>; yields [12 x i8]*:aptr</i>
3119 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003120</pre>
Chris Lattnerf74d5c72004-04-05 01:30:49 +00003121</div>
Reid Spencer47ce1792006-11-09 21:15:49 +00003122
Chris Lattner00950542001-06-06 20:29:01 +00003123<!-- ======================================================================= -->
Reid Spencer2fd21e62006-11-08 01:18:52 +00003124<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003125</div>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003126<div class="doc_text">
Reid Spencer2fd21e62006-11-08 01:18:52 +00003127<p>The instructions in this category are the conversion instructions (casting)
3128which all take a single operand and a type. They perform various bit conversions
3129on the operand.</p>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003130</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003131
Chris Lattner6536cfe2002-05-06 22:08:29 +00003132<!-- _______________________________________________________________________ -->
Chris Lattnercc37aae2004-03-12 05:50:16 +00003133<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003134 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
3135</div>
3136<div class="doc_text">
3137
3138<h5>Syntax:</h5>
3139<pre>
3140 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3141</pre>
3142
3143<h5>Overview:</h5>
3144<p>
3145The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
3146</p>
3147
3148<h5>Arguments:</h5>
3149<p>
3150The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
3151be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattner3b19d652007-01-15 01:54:13 +00003152and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencerd4448792006-11-09 23:03:26 +00003153type. The bit size of <tt>value</tt> must be larger than the bit size of
3154<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003155
3156<h5>Semantics:</h5>
3157<p>
3158The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencerd4448792006-11-09 23:03:26 +00003159and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
3160larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
3161It will always truncate bits.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003162
3163<h5>Example:</h5>
3164<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003165 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00003166 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
3167 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003168</pre>
3169</div>
3170
3171<!-- _______________________________________________________________________ -->
3172<div class="doc_subsubsection">
3173 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
3174</div>
3175<div class="doc_text">
3176
3177<h5>Syntax:</h5>
3178<pre>
3179 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3180</pre>
3181
3182<h5>Overview:</h5>
3183<p>The '<tt>zext</tt>' instruction zero extends its operand to type
3184<tt>ty2</tt>.</p>
3185
3186
3187<h5>Arguments:</h5>
3188<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattner3b19d652007-01-15 01:54:13 +00003189<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3190also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencerd4448792006-11-09 23:03:26 +00003191<tt>value</tt> must be smaller than the bit size of the destination type,
3192<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003193
3194<h5>Semantics:</h5>
3195<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
Chris Lattnerd1d25172007-05-24 19:13:27 +00003196bits until it reaches the size of the destination type, <tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003197
Reid Spencerb5929522007-01-12 15:46:11 +00003198<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003199
3200<h5>Example:</h5>
3201<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003202 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00003203 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003204</pre>
3205</div>
3206
3207<!-- _______________________________________________________________________ -->
3208<div class="doc_subsubsection">
3209 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
3210</div>
3211<div class="doc_text">
3212
3213<h5>Syntax:</h5>
3214<pre>
3215 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3216</pre>
3217
3218<h5>Overview:</h5>
3219<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
3220
3221<h5>Arguments:</h5>
3222<p>
3223The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattner3b19d652007-01-15 01:54:13 +00003224<a href="#t_integer">integer</a> type, and a type to cast it to, which must
3225also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencerd4448792006-11-09 23:03:26 +00003226<tt>value</tt> must be smaller than the bit size of the destination type,
3227<tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003228
3229<h5>Semantics:</h5>
3230<p>
3231The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
3232bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
Chris Lattnerd1d25172007-05-24 19:13:27 +00003233the type <tt>ty2</tt>.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003234
Reid Spencerc78f3372007-01-12 03:35:51 +00003235<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003236
3237<h5>Example:</h5>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003238<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003239 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencerc78f3372007-01-12 03:35:51 +00003240 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003241</pre>
3242</div>
3243
3244<!-- _______________________________________________________________________ -->
3245<div class="doc_subsubsection">
Reid Spencer3fa91b02006-11-09 21:48:10 +00003246 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
3247</div>
3248
3249<div class="doc_text">
3250
3251<h5>Syntax:</h5>
3252
3253<pre>
3254 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3255</pre>
3256
3257<h5>Overview:</h5>
3258<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
3259<tt>ty2</tt>.</p>
3260
3261
3262<h5>Arguments:</h5>
3263<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
3264 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
3265cast it to. The size of <tt>value</tt> must be larger than the size of
3266<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
3267<i>no-op cast</i>.</p>
3268
3269<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003270<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
3271<a href="#t_floating">floating point</a> type to a smaller
3272<a href="#t_floating">floating point</a> type. If the value cannot fit within
3273the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer3fa91b02006-11-09 21:48:10 +00003274
3275<h5>Example:</h5>
3276<pre>
3277 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
3278 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
3279</pre>
3280</div>
3281
3282<!-- _______________________________________________________________________ -->
3283<div class="doc_subsubsection">
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003284 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
3285</div>
3286<div class="doc_text">
3287
3288<h5>Syntax:</h5>
3289<pre>
3290 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3291</pre>
3292
3293<h5>Overview:</h5>
3294<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
3295floating point value.</p>
3296
3297<h5>Arguments:</h5>
3298<p>The '<tt>fpext</tt>' instruction takes a
3299<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencerd4448792006-11-09 23:03:26 +00003300and a <a href="#t_floating">floating point</a> type to cast it to. The source
3301type must be smaller than the destination type.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003302
3303<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003304<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
Duncan Sands8036ca42007-03-30 12:22:09 +00003305<a href="#t_floating">floating point</a> type to a larger
3306<a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
Reid Spencerd4448792006-11-09 23:03:26 +00003307used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5c0ef472006-11-11 23:08:07 +00003308<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003309
3310<h5>Example:</h5>
3311<pre>
3312 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
3313 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
3314</pre>
3315</div>
3316
3317<!-- _______________________________________________________________________ -->
3318<div class="doc_subsubsection">
Reid Spencer24d6da52007-01-21 00:29:26 +00003319 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003320</div>
3321<div class="doc_text">
3322
3323<h5>Syntax:</h5>
3324<pre>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003325 &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 +00003326</pre>
3327
3328<h5>Overview:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003329<p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003330unsigned integer equivalent of type <tt>ty2</tt>.
3331</p>
3332
3333<h5>Arguments:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003334<p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a
Nate Begemanb348d182007-11-17 03:58:34 +00003335scalar or vector <a href="#t_floating">floating point</a> value, and a type
3336to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
3337type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
3338vector integer type with the same number of elements as <tt>ty</tt></p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003339
3340<h5>Semantics:</h5>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003341<p> The '<tt>fptoui</tt>' instruction converts its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003342<a href="#t_floating">floating point</a> operand into the nearest (rounding
3343towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
3344the results are undefined.</p>
3345
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003346<h5>Example:</h5>
3347<pre>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003348 %X = fptoui double 123.0 to i32 <i>; yields i32:123</i>
Chris Lattner88519042007-09-22 03:17:52 +00003349 %Y = fptoui float 1.0E+300 to i1 <i>; yields undefined:1</i>
Reid Spencer1539a1c2007-07-31 14:40:14 +00003350 %X = fptoui float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003351</pre>
3352</div>
3353
3354<!-- _______________________________________________________________________ -->
3355<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003356 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003357</div>
3358<div class="doc_text">
3359
3360<h5>Syntax:</h5>
3361<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003362 &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 +00003363</pre>
3364
3365<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003366<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003367<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnercc37aae2004-03-12 05:50:16 +00003368</p>
3369
Chris Lattner6536cfe2002-05-06 22:08:29 +00003370<h5>Arguments:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003371<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Nate Begemanb348d182007-11-17 03:58:34 +00003372scalar or vector <a href="#t_floating">floating point</a> value, and a type
3373to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>
3374type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a
3375vector integer type with the same number of elements as <tt>ty</tt></p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003376
Chris Lattner6536cfe2002-05-06 22:08:29 +00003377<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003378<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003379<a href="#t_floating">floating point</a> operand into the nearest (rounding
3380towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
3381the results are undefined.</p>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003382
Chris Lattner33ba0d92001-07-09 00:26:23 +00003383<h5>Example:</h5>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003384<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003385 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
Chris Lattner88519042007-09-22 03:17:52 +00003386 %Y = fptosi float 1.0E-247 to i1 <i>; yields undefined:1</i>
Reid Spencerca86e162006-12-31 07:07:53 +00003387 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003388</pre>
3389</div>
3390
3391<!-- _______________________________________________________________________ -->
3392<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003393 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003394</div>
3395<div class="doc_text">
3396
3397<h5>Syntax:</h5>
3398<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003399 &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 +00003400</pre>
3401
3402<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003403<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003404integer and converts that value to the <tt>ty2</tt> type.</p>
3405
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003406<h5>Arguments:</h5>
Nate Begemanb348d182007-11-17 03:58:34 +00003407<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a
3408scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
3409to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
3410type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
3411floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003412
3413<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003414<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003415integer quantity and converts it to the corresponding floating point value. If
Jeff Cohencb757312007-04-22 14:56:37 +00003416the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003417
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003418<h5>Example:</h5>
3419<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003420 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003421 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003422</pre>
3423</div>
3424
3425<!-- _______________________________________________________________________ -->
3426<div class="doc_subsubsection">
Reid Spencerd4448792006-11-09 23:03:26 +00003427 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003428</div>
3429<div class="doc_text">
3430
3431<h5>Syntax:</h5>
3432<pre>
Reid Spencerd4448792006-11-09 23:03:26 +00003433 &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 +00003434</pre>
3435
3436<h5>Overview:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003437<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003438integer and converts that value to the <tt>ty2</tt> type.</p>
3439
3440<h5>Arguments:</h5>
Nate Begemanb348d182007-11-17 03:58:34 +00003441<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a
3442scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it
3443to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>
3444type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector
3445floating point type with the same number of elements as <tt>ty</tt></p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003446
3447<h5>Semantics:</h5>
Reid Spencerd4448792006-11-09 23:03:26 +00003448<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003449integer quantity and converts it to the corresponding floating point value. If
Jeff Cohencb757312007-04-22 14:56:37 +00003450the value cannot fit in the floating point value, the results are undefined.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003451
3452<h5>Example:</h5>
3453<pre>
Reid Spencerca86e162006-12-31 07:07:53 +00003454 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003455 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003456</pre>
3457</div>
3458
3459<!-- _______________________________________________________________________ -->
3460<div class="doc_subsubsection">
Reid Spencer72679252006-11-11 21:00:47 +00003461 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3462</div>
3463<div class="doc_text">
3464
3465<h5>Syntax:</h5>
3466<pre>
3467 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3468</pre>
3469
3470<h5>Overview:</h5>
3471<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3472the integer type <tt>ty2</tt>.</p>
3473
3474<h5>Arguments:</h5>
3475<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
Duncan Sands8036ca42007-03-30 12:22:09 +00003476must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to
Reid Spencer72679252006-11-11 21:00:47 +00003477<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3478
3479<h5>Semantics:</h5>
3480<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3481<tt>ty2</tt> by interpreting the pointer value as an integer and either
3482truncating or zero extending that value to the size of the integer type. If
3483<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3484<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
Jeff Cohenb627eab2007-04-29 01:07:00 +00003485are the same size, then nothing is done (<i>no-op cast</i>) other than a type
3486change.</p>
Reid Spencer72679252006-11-11 21:00:47 +00003487
3488<h5>Example:</h5>
3489<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003490 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i>
3491 %Y = ptrtoint i32* %x to i64 <i>; yields zero extension on 32-bit architecture</i>
Reid Spencer72679252006-11-11 21:00:47 +00003492</pre>
3493</div>
3494
3495<!-- _______________________________________________________________________ -->
3496<div class="doc_subsubsection">
3497 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3498</div>
3499<div class="doc_text">
3500
3501<h5>Syntax:</h5>
3502<pre>
3503 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3504</pre>
3505
3506<h5>Overview:</h5>
3507<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3508a pointer type, <tt>ty2</tt>.</p>
3509
3510<h5>Arguments:</h5>
Duncan Sands8036ca42007-03-30 12:22:09 +00003511<p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a>
Reid Spencer72679252006-11-11 21:00:47 +00003512value to cast, and a type to cast it to, which must be a
Anton Korobeynikov7f705592007-01-12 19:20:47 +00003513<a href="#t_pointer">pointer</a> type.
Reid Spencer72679252006-11-11 21:00:47 +00003514
3515<h5>Semantics:</h5>
3516<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3517<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3518the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3519size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3520the size of a pointer then a zero extension is done. If they are the same size,
3521nothing is done (<i>no-op cast</i>).</p>
3522
3523<h5>Example:</h5>
3524<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003525 %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i>
3526 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i>
3527 %Y = inttoptr i64 0 to i32* <i>; yields truncation on 32-bit architecture</i>
Reid Spencer72679252006-11-11 21:00:47 +00003528</pre>
3529</div>
3530
3531<!-- _______________________________________________________________________ -->
3532<div class="doc_subsubsection">
Reid Spencer5c0ef472006-11-11 23:08:07 +00003533 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003534</div>
3535<div class="doc_text">
3536
3537<h5>Syntax:</h5>
3538<pre>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003539 &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 +00003540</pre>
3541
3542<h5>Overview:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003543<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003544<tt>ty2</tt> without changing any bits.</p>
3545
3546<h5>Arguments:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003547<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003548a first class value, and a type to cast it to, which must also be a <a
3549 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencer19b569f2007-01-09 20:08:58 +00003550and the destination type, <tt>ty2</tt>, must be identical. If the source
3551type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003552
3553<h5>Semantics:</h5>
Reid Spencer5c0ef472006-11-11 23:08:07 +00003554<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer72679252006-11-11 21:00:47 +00003555<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3556this conversion. The conversion is done as if the <tt>value</tt> had been
3557stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3558converted to other pointer types with this instruction. To convert pointers to
3559other types, use the <a href="#i_inttoptr">inttoptr</a> or
3560<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer9dee3ac2006-11-08 01:11:31 +00003561
3562<h5>Example:</h5>
3563<pre>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003564 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
Reid Spencerca86e162006-12-31 07:07:53 +00003565 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3566 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner33ba0d92001-07-09 00:26:23 +00003567</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00003568</div>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003569
Reid Spencer2fd21e62006-11-08 01:18:52 +00003570<!-- ======================================================================= -->
3571<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3572<div class="doc_text">
3573<p>The instructions in this category are the "miscellaneous"
3574instructions, which defy better classification.</p>
3575</div>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003576
3577<!-- _______________________________________________________________________ -->
3578<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3579</div>
3580<div class="doc_text">
3581<h5>Syntax:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003582<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 +00003583</pre>
3584<h5>Overview:</h5>
3585<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
Chris Lattner4316dec2008-04-02 00:38:26 +00003586of its two integer or pointer operands.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003587<h5>Arguments:</h5>
3588<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
Jeff Cohenb627eab2007-04-29 01:07:00 +00003589the condition code indicating the kind of comparison to perform. It is not
3590a value, just a keyword. The possible condition code are:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003591<ol>
3592 <li><tt>eq</tt>: equal</li>
3593 <li><tt>ne</tt>: not equal </li>
3594 <li><tt>ugt</tt>: unsigned greater than</li>
3595 <li><tt>uge</tt>: unsigned greater or equal</li>
3596 <li><tt>ult</tt>: unsigned less than</li>
3597 <li><tt>ule</tt>: unsigned less or equal</li>
3598 <li><tt>sgt</tt>: signed greater than</li>
3599 <li><tt>sge</tt>: signed greater or equal</li>
3600 <li><tt>slt</tt>: signed less than</li>
3601 <li><tt>sle</tt>: signed less or equal</li>
3602</ol>
Chris Lattner3b19d652007-01-15 01:54:13 +00003603<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Reid Spencer350f8aa2007-01-04 05:19:58 +00003604<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003605<h5>Semantics:</h5>
3606<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3607the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencerc78f3372007-01-12 03:35:51 +00003608yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003609<ol>
3610 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3611 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3612 </li>
3613 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3614 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3615 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3616 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3617 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3618 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3619 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3620 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3621 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3622 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3623 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3624 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3625 <li><tt>sge</tt>: interprets the operands as signed values and yields
3626 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3627 <li><tt>slt</tt>: interprets the operands as signed values and yields
3628 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3629 <li><tt>sle</tt>: interprets the operands as signed values and yields
3630 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003631</ol>
3632<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
Jeff Cohenb627eab2007-04-29 01:07:00 +00003633values are compared as if they were integers.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003634
3635<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003636<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3637 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3638 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3639 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3640 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3641 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003642</pre>
3643</div>
3644
3645<!-- _______________________________________________________________________ -->
3646<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3647</div>
3648<div class="doc_text">
3649<h5>Syntax:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003650<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 +00003651</pre>
3652<h5>Overview:</h5>
3653<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3654of its floating point operands.</p>
3655<h5>Arguments:</h5>
3656<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
Jeff Cohenb627eab2007-04-29 01:07:00 +00003657the condition code indicating the kind of comparison to perform. It is not
3658a value, just a keyword. The possible condition code are:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003659<ol>
Reid Spencerb7f26282006-11-19 03:00:14 +00003660 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003661 <li><tt>oeq</tt>: ordered and equal</li>
3662 <li><tt>ogt</tt>: ordered and greater than </li>
3663 <li><tt>oge</tt>: ordered and greater than or equal</li>
3664 <li><tt>olt</tt>: ordered and less than </li>
3665 <li><tt>ole</tt>: ordered and less than or equal</li>
3666 <li><tt>one</tt>: ordered and not equal</li>
3667 <li><tt>ord</tt>: ordered (no nans)</li>
3668 <li><tt>ueq</tt>: unordered or equal</li>
3669 <li><tt>ugt</tt>: unordered or greater than </li>
3670 <li><tt>uge</tt>: unordered or greater than or equal</li>
3671 <li><tt>ult</tt>: unordered or less than </li>
3672 <li><tt>ule</tt>: unordered or less than or equal</li>
3673 <li><tt>une</tt>: unordered or not equal</li>
3674 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003675 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003676</ol>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003677<p><i>Ordered</i> means that neither operand is a QNAN while
Reid Spencer93a49852006-12-06 07:08:07 +00003678<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer350f8aa2007-01-04 05:19:58 +00003679<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3680<a href="#t_floating">floating point</a> typed. They must have identical
3681types.</p>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003682<h5>Semantics:</h5>
Nate Begemanac80ade2008-05-12 19:01:56 +00003683<p>The '<tt>fcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt>
3684according to the condition code given as <tt>cond</tt>. The comparison performed
3685always yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerf3a70a62006-11-18 21:50:54 +00003686<ol>
3687 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003688 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003689 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003690 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003691 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003692 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003693 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003694 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003695 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003696 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003697 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003698 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerf3a70a62006-11-18 21:50:54 +00003699 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003700 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3701 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003702 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003703 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003704 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003705 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003706 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003707 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003708 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003709 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003710 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003711 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerf3a70a62006-11-18 21:50:54 +00003712 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerb7f26282006-11-19 03:00:14 +00003713 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003714 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3715</ol>
Reid Spencerf3a70a62006-11-18 21:50:54 +00003716
3717<h5>Example:</h5>
3718<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3719 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3720 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3721 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3722</pre>
3723</div>
3724
Reid Spencer2fd21e62006-11-08 01:18:52 +00003725<!-- _______________________________________________________________________ -->
Nate Begemanac80ade2008-05-12 19:01:56 +00003726<div class="doc_subsubsection">
3727 <a name="i_vicmp">'<tt>vicmp</tt>' Instruction</a>
3728</div>
3729<div class="doc_text">
3730<h5>Syntax:</h5>
3731<pre> &lt;result&gt; = vicmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
3732</pre>
3733<h5>Overview:</h5>
3734<p>The '<tt>vicmp</tt>' instruction returns an integer vector value based on
3735element-wise comparison of its two integer vector operands.</p>
3736<h5>Arguments:</h5>
3737<p>The '<tt>vicmp</tt>' instruction takes three operands. The first operand is
3738the condition code indicating the kind of comparison to perform. It is not
3739a value, just a keyword. The possible condition code are:
3740<ol>
3741 <li><tt>eq</tt>: equal</li>
3742 <li><tt>ne</tt>: not equal </li>
3743 <li><tt>ugt</tt>: unsigned greater than</li>
3744 <li><tt>uge</tt>: unsigned greater or equal</li>
3745 <li><tt>ult</tt>: unsigned less than</li>
3746 <li><tt>ule</tt>: unsigned less or equal</li>
3747 <li><tt>sgt</tt>: signed greater than</li>
3748 <li><tt>sge</tt>: signed greater or equal</li>
3749 <li><tt>slt</tt>: signed less than</li>
3750 <li><tt>sle</tt>: signed less or equal</li>
3751</ol>
3752<p>The remaining two arguments must be <a href="#t_vector">vector</a> of
3753<a href="#t_integer">integer</a> typed. They must also be identical types.</p>
3754<h5>Semantics:</h5>
3755<p>The '<tt>vicmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt>
3756according to the condition code given as <tt>cond</tt>. The comparison yields a
3757<a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, of
3758identical type as the values being compared. The most significant bit in each
3759element is 1 if the element-wise comparison evaluates to true, and is 0
3760otherwise. All other bits of the result are undefined. The condition codes
3761are evaluated identically to the <a href="#i_icmp">'<tt>icmp</tt>'
3762instruction</a>.
3763
3764<h5>Example:</h5>
3765<pre>
3766 &lt;result&gt; = vicmp eq <2 x i32> < i32 4, i32 0 >, < i32 5, i32 0 > <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i>
3767 &lt;result&gt; = vicmp ult <2 x i8> < i8 1, i8 2 >, < i8 2, i8 2> <i>; yields: result=<2 x i8> < i8 -1, i8 0 ></i>
3768</pre>
3769</div>
3770
3771<!-- _______________________________________________________________________ -->
3772<div class="doc_subsubsection">
3773 <a name="i_vfcmp">'<tt>vfcmp</tt>' Instruction</a>
3774</div>
3775<div class="doc_text">
3776<h5>Syntax:</h5>
3777<pre> &lt;result&gt; = vfcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;</pre>
3778<h5>Overview:</h5>
3779<p>The '<tt>vfcmp</tt>' instruction returns an integer vector value based on
3780element-wise comparison of its two floating point vector operands. The output
3781elements have the same width as the input elements.</p>
3782<h5>Arguments:</h5>
3783<p>The '<tt>vfcmp</tt>' instruction takes three operands. The first operand is
3784the condition code indicating the kind of comparison to perform. It is not
3785a value, just a keyword. The possible condition code are:
3786<ol>
3787 <li><tt>false</tt>: no comparison, always returns false</li>
3788 <li><tt>oeq</tt>: ordered and equal</li>
3789 <li><tt>ogt</tt>: ordered and greater than </li>
3790 <li><tt>oge</tt>: ordered and greater than or equal</li>
3791 <li><tt>olt</tt>: ordered and less than </li>
3792 <li><tt>ole</tt>: ordered and less than or equal</li>
3793 <li><tt>one</tt>: ordered and not equal</li>
3794 <li><tt>ord</tt>: ordered (no nans)</li>
3795 <li><tt>ueq</tt>: unordered or equal</li>
3796 <li><tt>ugt</tt>: unordered or greater than </li>
3797 <li><tt>uge</tt>: unordered or greater than or equal</li>
3798 <li><tt>ult</tt>: unordered or less than </li>
3799 <li><tt>ule</tt>: unordered or less than or equal</li>
3800 <li><tt>une</tt>: unordered or not equal</li>
3801 <li><tt>uno</tt>: unordered (either nans)</li>
3802 <li><tt>true</tt>: no comparison, always returns true</li>
3803</ol>
3804<p>The remaining two arguments must be <a href="#t_vector">vector</a> of
3805<a href="#t_floating">floating point</a> typed. They must also be identical
3806types.</p>
3807<h5>Semantics:</h5>
3808<p>The '<tt>vfcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt>
3809according to the condition code given as <tt>cond</tt>. The comparison yields a
3810<a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, with
3811an identical number of elements as the values being compared, and each element
3812having identical with to the width of the floating point elements. The most
3813significant bit in each element is 1 if the element-wise comparison evaluates to
3814true, and is 0 otherwise. All other bits of the result are undefined. The
3815condition codes are evaluated identically to the
3816<a href="#i_fcmp">'<tt>fcmp</tt>' instruction</a>.
3817
3818<h5>Example:</h5>
3819<pre>
3820 &lt;result&gt; = vfcmp oeq <2 x float> < float 4, float 0 >, < float 5, float 0 > <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i>
3821 &lt;result&gt; = vfcmp ult <2 x double> < double 1, double 2 >, < double 2, double 2> <i>; yields: result=<2 x i64> < i64 -1, i64 0 ></i>
3822</pre>
3823</div>
3824
3825<!-- _______________________________________________________________________ -->
Reid Spencer2fd21e62006-11-08 01:18:52 +00003826<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3827Instruction</a> </div>
3828<div class="doc_text">
3829<h5>Syntax:</h5>
3830<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3831<h5>Overview:</h5>
3832<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3833the SSA graph representing the function.</p>
3834<h5>Arguments:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003835<p>The type of the incoming values is specified with the first type
Reid Spencer2fd21e62006-11-08 01:18:52 +00003836field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3837as arguments, with one pair for each predecessor basic block of the
3838current block. Only values of <a href="#t_firstclass">first class</a>
3839type may be used as the value arguments to the PHI node. Only labels
3840may be used as the label arguments.</p>
3841<p>There must be no non-phi instructions between the start of a basic
3842block and the PHI instructions: i.e. PHI instructions must be first in
3843a basic block.</p>
3844<h5>Semantics:</h5>
Jeff Cohenb627eab2007-04-29 01:07:00 +00003845<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value
3846specified by the pair corresponding to the predecessor basic block that executed
3847just prior to the current block.</p>
Reid Spencer2fd21e62006-11-08 01:18:52 +00003848<h5>Example:</h5>
Reid Spencerca86e162006-12-31 07:07:53 +00003849<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 +00003850</div>
3851
Chris Lattnercc37aae2004-03-12 05:50:16 +00003852<!-- _______________________________________________________________________ -->
3853<div class="doc_subsubsection">
3854 <a name="i_select">'<tt>select</tt>' Instruction</a>
3855</div>
3856
3857<div class="doc_text">
3858
3859<h5>Syntax:</h5>
3860
3861<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003862 &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 +00003863</pre>
3864
3865<h5>Overview:</h5>
3866
3867<p>
3868The '<tt>select</tt>' instruction is used to choose one value based on a
3869condition, without branching.
3870</p>
3871
3872
3873<h5>Arguments:</h5>
3874
3875<p>
3876The '<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.
3877</p>
3878
3879<h5>Semantics:</h5>
3880
3881<p>
3882If the boolean condition evaluates to true, the instruction returns the first
John Criswellfc6b8952005-05-16 16:17:45 +00003883value argument; otherwise, it returns the second value argument.
Chris Lattnercc37aae2004-03-12 05:50:16 +00003884</p>
3885
3886<h5>Example:</h5>
3887
3888<pre>
Reid Spencerc78f3372007-01-12 03:35:51 +00003889 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnercc37aae2004-03-12 05:50:16 +00003890</pre>
3891</div>
3892
Robert Bocchino05ccd702006-01-15 20:48:27 +00003893
3894<!-- _______________________________________________________________________ -->
3895<div class="doc_subsubsection">
Chris Lattner2bff5242005-05-06 05:47:36 +00003896 <a name="i_call">'<tt>call</tt>' Instruction</a>
3897</div>
3898
Misha Brukman9d0919f2003-11-08 01:05:38 +00003899<div class="doc_text">
Chris Lattner2bff5242005-05-06 05:47:36 +00003900
Chris Lattner00950542001-06-06 20:29:01 +00003901<h5>Syntax:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003902<pre>
Nick Lewyckydb7e3c92007-09-08 13:57:50 +00003903 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt; [&lt;fnty&gt;*] &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattner2bff5242005-05-06 05:47:36 +00003904</pre>
3905
Chris Lattner00950542001-06-06 20:29:01 +00003906<h5>Overview:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003907
Misha Brukman9d0919f2003-11-08 01:05:38 +00003908<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003909
Chris Lattner00950542001-06-06 20:29:01 +00003910<h5>Arguments:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003911
Misha Brukman9d0919f2003-11-08 01:05:38 +00003912<p>This instruction requires several arguments:</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003913
Chris Lattner6536cfe2002-05-06 22:08:29 +00003914<ol>
Chris Lattner261efe92003-11-25 01:02:51 +00003915 <li>
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003916 <p>The optional "tail" marker indicates whether the callee function accesses
3917 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattner2bff5242005-05-06 05:47:36 +00003918 function call is eligible for tail call optimization. Note that calls may
3919 be marked "tail" even if they do not occur before a <a
3920 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner261efe92003-11-25 01:02:51 +00003921 </li>
3922 <li>
Duncan Sands8036ca42007-03-30 12:22:09 +00003923 <p>The optional "cconv" marker indicates which <a href="#callingconv">calling
Chris Lattnerbad10ee2005-05-06 22:57:40 +00003924 convention</a> the call should use. If none is specified, the call defaults
3925 to using C calling conventions.
3926 </li>
3927 <li>
Nick Lewyckydb7e3c92007-09-08 13:57:50 +00003928 <p>'<tt>ty</tt>': the type of the call instruction itself which is also
3929 the type of the return value. Functions that return no value are marked
3930 <tt><a href="#t_void">void</a></tt>.</p>
3931 </li>
3932 <li>
3933 <p>'<tt>fnty</tt>': shall be the signature of the pointer to function
3934 value being invoked. The argument types must match the types implied by
3935 this signature. This type can be omitted if the function is not varargs
3936 and if the function type does not return a pointer to a function.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003937 </li>
3938 <li>
3939 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3940 be invoked. In most cases, this is a direct function invocation, but
3941 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswellfc6b8952005-05-16 16:17:45 +00003942 to function value.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003943 </li>
3944 <li>
3945 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencera7e302a2005-05-01 22:22:57 +00003946 function signature argument types. All arguments must be of
3947 <a href="#t_firstclass">first class</a> type. If the function signature
3948 indicates the function accepts a variable number of arguments, the extra
3949 arguments can be specified.</p>
Chris Lattner261efe92003-11-25 01:02:51 +00003950 </li>
Chris Lattner6536cfe2002-05-06 22:08:29 +00003951</ol>
Chris Lattner2bff5242005-05-06 05:47:36 +00003952
Chris Lattner00950542001-06-06 20:29:01 +00003953<h5>Semantics:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003954
Chris Lattner261efe92003-11-25 01:02:51 +00003955<p>The '<tt>call</tt>' instruction is used to cause control flow to
3956transfer to a specified function, with its incoming arguments bound to
3957the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3958instruction in the called function, control flow continues with the
3959instruction after the function call, and the return value of the
Chris Lattner772fccf2008-03-21 17:24:17 +00003960function is bound to the result argument. If the callee returns multiple
3961values then the return values of the function are only accessible through
3962the '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p>
Chris Lattner2bff5242005-05-06 05:47:36 +00003963
Chris Lattner00950542001-06-06 20:29:01 +00003964<h5>Example:</h5>
Chris Lattner2bff5242005-05-06 05:47:36 +00003965
3966<pre>
Nick Lewyckydb7e3c92007-09-08 13:57:50 +00003967 %retval = call i32 @test(i32 %argc)
Chris Lattner772fccf2008-03-21 17:24:17 +00003968 call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i>
3969 %X = tail call i32 @foo() <i>; yields i32</i>
3970 %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i>
3971 call void %foo(i8 97 signext)
Devang Patelc3fc6df2008-03-10 20:49:15 +00003972
3973 %struct.A = type { i32, i8 }
Chris Lattner772fccf2008-03-21 17:24:17 +00003974 %r = call %struct.A @foo() <i>; yields { 32, i8 }</i>
3975 %gr = getresult %struct.A %r, 0 <i>; yields i32</i>
3976 %gr1 = getresult %struct.A %r, 1 <i>; yields i8</i>
Chris Lattner2bff5242005-05-06 05:47:36 +00003977</pre>
3978
Misha Brukman9d0919f2003-11-08 01:05:38 +00003979</div>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003980
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00003981<!-- _______________________________________________________________________ -->
Chris Lattnere19d7a72004-09-27 21:51:25 +00003982<div class="doc_subsubsection">
Chris Lattnerfb6977d2006-01-13 23:26:01 +00003983 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003984</div>
3985
Misha Brukman9d0919f2003-11-08 01:05:38 +00003986<div class="doc_text">
Chris Lattnere19d7a72004-09-27 21:51:25 +00003987
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003988<h5>Syntax:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003989
3990<pre>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003991 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattnere19d7a72004-09-27 21:51:25 +00003992</pre>
3993
Chris Lattner8d1a81d2003-10-18 05:51:36 +00003994<h5>Overview:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00003995
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00003996<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattnere19d7a72004-09-27 21:51:25 +00003997the "variable argument" area of a function call. It is used to implement the
3998<tt>va_arg</tt> macro in C.</p>
3999
Chris Lattner8d1a81d2003-10-18 05:51:36 +00004000<h5>Arguments:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004001
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004002<p>This instruction takes a <tt>va_list*</tt> value and the type of
4003the argument. It returns a value of the specified argument type and
Jeff Cohenb627eab2007-04-29 01:07:00 +00004004increments the <tt>va_list</tt> to point to the next argument. The
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004005actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004006
Chris Lattner8d1a81d2003-10-18 05:51:36 +00004007<h5>Semantics:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004008
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004009<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
4010type from the specified <tt>va_list</tt> and causes the
4011<tt>va_list</tt> to point to the next argument. For more information,
4012see the variable argument handling <a href="#int_varargs">Intrinsic
4013Functions</a>.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004014
4015<p>It is legal for this instruction to be called in a function which does not
4016take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman9d0919f2003-11-08 01:05:38 +00004017function.</p>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004018
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004019<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswellfc6b8952005-05-16 16:17:45 +00004020href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattnere19d7a72004-09-27 21:51:25 +00004021argument.</p>
4022
Chris Lattner8d1a81d2003-10-18 05:51:36 +00004023<h5>Example:</h5>
Chris Lattnere19d7a72004-09-27 21:51:25 +00004024
4025<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
4026
Misha Brukman9d0919f2003-11-08 01:05:38 +00004027</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004028
Devang Patelc3fc6df2008-03-10 20:49:15 +00004029<!-- _______________________________________________________________________ -->
4030<div class="doc_subsubsection">
4031 <a name="i_getresult">'<tt>getresult</tt>' Instruction</a>
4032</div>
4033
4034<div class="doc_text">
4035
4036<h5>Syntax:</h5>
4037<pre>
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004038 &lt;resultval&gt; = getresult &lt;type&gt; &lt;retval&gt;, &lt;index&gt;
Devang Patelc3fc6df2008-03-10 20:49:15 +00004039</pre>
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004040
Devang Patelc3fc6df2008-03-10 20:49:15 +00004041<h5>Overview:</h5>
4042
4043<p> The '<tt>getresult</tt>' instruction is used to extract individual values
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004044from a '<tt><a href="#i_call">call</a></tt>'
4045or '<tt><a href="#i_invoke">invoke</a></tt>' instruction that returns multiple
4046results.</p>
Devang Patelc3fc6df2008-03-10 20:49:15 +00004047
4048<h5>Arguments:</h5>
4049
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004050<p>The '<tt>getresult</tt>' instruction takes a call or invoke value as its
Chris Lattner1c406d72008-04-23 04:06:52 +00004051first argument, or an undef value. The value must have <a
4052href="#t_struct">structure type</a>. The second argument is a constant
4053unsigned index value which must be in range for the number of values returned
4054by the call.</p>
Devang Patelc3fc6df2008-03-10 20:49:15 +00004055
4056<h5>Semantics:</h5>
4057
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004058<p>The '<tt>getresult</tt>' instruction extracts the element identified by
4059'<tt>index</tt>' from the aggregate value.</p>
Devang Patelc3fc6df2008-03-10 20:49:15 +00004060
4061<h5>Example:</h5>
4062
4063<pre>
4064 %struct.A = type { i32, i8 }
4065
4066 %r = call %struct.A @foo()
Chris Lattner45c5e8b2008-03-21 17:20:51 +00004067 %gr = getresult %struct.A %r, 0 <i>; yields i32:%gr</i>
4068 %gr1 = getresult %struct.A %r, 1 <i>; yields i8:%gr1</i>
Devang Patelc3fc6df2008-03-10 20:49:15 +00004069 add i32 %gr, 42
4070 add i8 %gr1, 41
4071</pre>
4072
4073</div>
4074
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004075<!-- *********************************************************************** -->
Chris Lattner261efe92003-11-25 01:02:51 +00004076<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
4077<!-- *********************************************************************** -->
Chris Lattner8ff75902004-01-06 05:31:32 +00004078
Misha Brukman9d0919f2003-11-08 01:05:38 +00004079<div class="doc_text">
Chris Lattner33aec9e2004-02-12 17:01:32 +00004080
4081<p>LLVM supports the notion of an "intrinsic function". These functions have
Reid Spencer409e28f2007-04-01 08:04:23 +00004082well known names and semantics and are required to follow certain restrictions.
4083Overall, these intrinsics represent an extension mechanism for the LLVM
Jeff Cohenb627eab2007-04-29 01:07:00 +00004084language that does not require changing all of the transformations in LLVM when
Gabor Greif04367bf2007-07-06 22:07:22 +00004085adding to the language (or the bitcode reader/writer, the parser, etc...).</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00004086
John Criswellfc6b8952005-05-16 16:17:45 +00004087<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
Jeff Cohenb627eab2007-04-29 01:07:00 +00004088prefix is reserved in LLVM for intrinsic names; thus, function names may not
4089begin with this prefix. Intrinsic functions must always be external functions:
4090you cannot define the body of intrinsic functions. Intrinsic functions may
4091only be used in call or invoke instructions: it is illegal to take the address
4092of an intrinsic function. Additionally, because intrinsic functions are part
4093of the LLVM language, it is required if any are added that they be documented
4094here.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00004095
Chandler Carruth69940402007-08-04 01:51:18 +00004096<p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents
4097a family of functions that perform the same operation but on different data
4098types. Because LLVM can represent over 8 million different integer types,
4099overloading is used commonly to allow an intrinsic function to operate on any
4100integer type. One or more of the argument types or the result type can be
4101overloaded to accept any integer type. Argument types may also be defined as
4102exactly matching a previous argument's type or the result type. This allows an
4103intrinsic function which accepts multiple arguments, but needs all of them to
4104be of the same type, to only be overloaded with respect to a single argument or
4105the result.</p>
Chris Lattner33aec9e2004-02-12 17:01:32 +00004106
Chandler Carruth69940402007-08-04 01:51:18 +00004107<p>Overloaded intrinsics will have the names of its overloaded argument types
4108encoded into its function name, each preceded by a period. Only those types
4109which are overloaded result in a name suffix. Arguments whose type is matched
4110against another type do not. For example, the <tt>llvm.ctpop</tt> function can
4111take an integer of any width and returns an integer of exactly the same integer
4112width. This leads to a family of functions such as
4113<tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>.
4114Only one type, the return type, is overloaded, and only one type suffix is
4115required. Because the argument's type is matched against the return type, it
4116does not require its own name suffix.</p>
Reid Spencer409e28f2007-04-01 08:04:23 +00004117
4118<p>To learn how to add an intrinsic function, please see the
4119<a href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004120</p>
4121
Misha Brukman9d0919f2003-11-08 01:05:38 +00004122</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004123
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004124<!-- ======================================================================= -->
Chris Lattner8ff75902004-01-06 05:31:32 +00004125<div class="doc_subsection">
4126 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
4127</div>
4128
Misha Brukman9d0919f2003-11-08 01:05:38 +00004129<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00004130
Misha Brukman9d0919f2003-11-08 01:05:38 +00004131<p>Variable argument support is defined in LLVM with the <a
Chris Lattnerfb6977d2006-01-13 23:26:01 +00004132 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner261efe92003-11-25 01:02:51 +00004133intrinsic functions. These functions are related to the similarly
4134named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004135
Chris Lattner261efe92003-11-25 01:02:51 +00004136<p>All of these functions operate on arguments that use a
4137target-specific value type "<tt>va_list</tt>". The LLVM assembly
4138language reference manual does not define what this type is, so all
Jeff Cohenb627eab2007-04-29 01:07:00 +00004139transformations should be prepared to handle these functions regardless of
4140the type used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004141
Chris Lattner374ab302006-05-15 17:26:46 +00004142<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner261efe92003-11-25 01:02:51 +00004143instruction and the variable argument handling intrinsic functions are
4144used.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004145
Bill Wendling2f7a8b02007-05-29 09:04:49 +00004146<div class="doc_code">
Chris Lattner33aec9e2004-02-12 17:01:32 +00004147<pre>
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00004148define i32 @test(i32 %X, ...) {
Chris Lattner33aec9e2004-02-12 17:01:32 +00004149 ; Initialize variable argument processing
Jeff Cohenb627eab2007-04-29 01:07:00 +00004150 %ap = alloca i8*
Chris Lattnerb75137d2007-01-08 07:55:15 +00004151 %ap2 = bitcast i8** %ap to i8*
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00004152 call void @llvm.va_start(i8* %ap2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004153
4154 ; Read a single integer argument
Jeff Cohenb627eab2007-04-29 01:07:00 +00004155 %tmp = va_arg i8** %ap, i32
Chris Lattner33aec9e2004-02-12 17:01:32 +00004156
4157 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Jeff Cohenb627eab2007-04-29 01:07:00 +00004158 %aq = alloca i8*
Chris Lattnerb75137d2007-01-08 07:55:15 +00004159 %aq2 = bitcast i8** %aq to i8*
Jeff Cohenb627eab2007-04-29 01:07:00 +00004160 call void @llvm.va_copy(i8* %aq2, i8* %ap2)
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00004161 call void @llvm.va_end(i8* %aq2)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004162
4163 ; Stop processing of arguments.
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00004164 call void @llvm.va_end(i8* %ap2)
Reid Spencerca86e162006-12-31 07:07:53 +00004165 ret i32 %tmp
Chris Lattner33aec9e2004-02-12 17:01:32 +00004166}
Anton Korobeynikov5d522f32007-03-21 23:58:04 +00004167
4168declare void @llvm.va_start(i8*)
4169declare void @llvm.va_copy(i8*, i8*)
4170declare void @llvm.va_end(i8*)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004171</pre>
Misha Brukman9d0919f2003-11-08 01:05:38 +00004172</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004173
Bill Wendling2f7a8b02007-05-29 09:04:49 +00004174</div>
4175
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004176<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00004177<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004178 <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00004179</div>
4180
4181
Misha Brukman9d0919f2003-11-08 01:05:38 +00004182<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004183<h5>Syntax:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004184<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004185<h5>Overview:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004186<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
4187<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
4188href="#i_va_arg">va_arg</a></tt>.</p>
4189
4190<h5>Arguments:</h5>
4191
4192<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
4193
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004194<h5>Semantics:</h5>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004195
4196<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
4197macro available in C. In a target-dependent way, it initializes the
Jeff Cohenb627eab2007-04-29 01:07:00 +00004198<tt>va_list</tt> element to which the argument points, so that the next call to
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004199<tt>va_arg</tt> will produce the first variable argument passed to the function.
4200Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
Jeff Cohenb627eab2007-04-29 01:07:00 +00004201last argument of the function as the compiler can figure that out.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004202
Misha Brukman9d0919f2003-11-08 01:05:38 +00004203</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004204
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004205<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00004206<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004207 <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00004208</div>
4209
Misha Brukman9d0919f2003-11-08 01:05:38 +00004210<div class="doc_text">
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004211<h5>Syntax:</h5>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004212<pre> declare void @llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004213<h5>Overview:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004214
Jeff Cohenb627eab2007-04-29 01:07:00 +00004215<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*&lt;arglist&gt;</tt>,
Reid Spencera3e435f2007-04-04 02:42:35 +00004216which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt>
Chris Lattner261efe92003-11-25 01:02:51 +00004217or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004218
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004219<h5>Arguments:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004220
Jeff Cohenb627eab2007-04-29 01:07:00 +00004221<p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004222
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004223<h5>Semantics:</h5>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004224
Misha Brukman9d0919f2003-11-08 01:05:38 +00004225<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Jeff Cohenb627eab2007-04-29 01:07:00 +00004226macro available in C. In a target-dependent way, it destroys the
4227<tt>va_list</tt> element to which the argument points. Calls to <a
4228href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy">
4229<tt>llvm.va_copy</tt></a> must be matched exactly with calls to
4230<tt>llvm.va_end</tt>.</p>
Chris Lattnerb75137d2007-01-08 07:55:15 +00004231
Misha Brukman9d0919f2003-11-08 01:05:38 +00004232</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004233
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004234<!-- _______________________________________________________________________ -->
Chris Lattner8ff75902004-01-06 05:31:32 +00004235<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004236 <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
Chris Lattner8ff75902004-01-06 05:31:32 +00004237</div>
4238
Misha Brukman9d0919f2003-11-08 01:05:38 +00004239<div class="doc_text">
Chris Lattnerd7923912004-05-23 21:06:01 +00004240
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004241<h5>Syntax:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00004242
4243<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004244 declare void @llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattnerd7923912004-05-23 21:06:01 +00004245</pre>
4246
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004247<h5>Overview:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00004248
Jeff Cohenb627eab2007-04-29 01:07:00 +00004249<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position
4250from the source argument list to the destination argument list.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004251
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004252<h5>Arguments:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00004253
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004254<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharthd0a4c622005-06-22 20:38:11 +00004255The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth8bf607a2005-06-18 18:28:17 +00004256
Chris Lattnerd7923912004-05-23 21:06:01 +00004257
Chris Lattnerd9ad5b32003-05-08 04:57:36 +00004258<h5>Semantics:</h5>
Chris Lattnerd7923912004-05-23 21:06:01 +00004259
Jeff Cohenb627eab2007-04-29 01:07:00 +00004260<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt>
4261macro available in C. In a target-dependent way, it copies the source
4262<tt>va_list</tt> element into the destination <tt>va_list</tt> element. This
4263intrinsic is necessary because the <tt><a href="#int_va_start">
4264llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for
4265example, memory allocation.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004266
Misha Brukman9d0919f2003-11-08 01:05:38 +00004267</div>
Chris Lattner8ff75902004-01-06 05:31:32 +00004268
Chris Lattner33aec9e2004-02-12 17:01:32 +00004269<!-- ======================================================================= -->
4270<div class="doc_subsection">
Chris Lattnerd7923912004-05-23 21:06:01 +00004271 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
4272</div>
4273
4274<div class="doc_text">
4275
4276<p>
4277LLVM support for <a href="GarbageCollection.html">Accurate Garbage
4278Collection</a> requires the implementation and generation of these intrinsics.
Reid Spencera3e435f2007-04-04 02:42:35 +00004279These intrinsics allow identification of <a href="#int_gcroot">GC roots on the
Chris Lattnerd7923912004-05-23 21:06:01 +00004280stack</a>, as well as garbage collector implementations that require <a
Reid Spencera3e435f2007-04-04 02:42:35 +00004281href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers.
Chris Lattnerd7923912004-05-23 21:06:01 +00004282Front-ends for type-safe garbage collected languages should generate these
4283intrinsics to make use of the LLVM garbage collectors. For more details, see <a
4284href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
4285</p>
Christopher Lamb303dae92007-12-17 01:00:21 +00004286
4287<p>The garbage collection intrinsics only operate on objects in the generic
4288 address space (address space zero).</p>
4289
Chris Lattnerd7923912004-05-23 21:06:01 +00004290</div>
4291
4292<!-- _______________________________________________________________________ -->
4293<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004294 <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00004295</div>
4296
4297<div class="doc_text">
4298
4299<h5>Syntax:</h5>
4300
4301<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004302 declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata)
Chris Lattnerd7923912004-05-23 21:06:01 +00004303</pre>
4304
4305<h5>Overview:</h5>
4306
John Criswell9e2485c2004-12-10 15:51:16 +00004307<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattnerd7923912004-05-23 21:06:01 +00004308the code generator, and allows some metadata to be associated with it.</p>
4309
4310<h5>Arguments:</h5>
4311
4312<p>The first argument specifies the address of a stack object that contains the
4313root pointer. The second pointer (which must be either a constant or a global
4314value address) contains the meta-data to be associated with the root.</p>
4315
4316<h5>Semantics:</h5>
4317
Chris Lattner05d67092008-04-24 05:59:56 +00004318<p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc"
Chris Lattnerd7923912004-05-23 21:06:01 +00004319location. At compile-time, the code generator generates information to allow
Gordon Henriksene1433f22007-12-25 02:31:26 +00004320the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>'
4321intrinsic may only be used in a function which <a href="#gc">specifies a GC
4322algorithm</a>.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004323
4324</div>
4325
4326
4327<!-- _______________________________________________________________________ -->
4328<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004329 <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00004330</div>
4331
4332<div class="doc_text">
4333
4334<h5>Syntax:</h5>
4335
4336<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004337 declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr)
Chris Lattnerd7923912004-05-23 21:06:01 +00004338</pre>
4339
4340<h5>Overview:</h5>
4341
4342<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
4343locations, allowing garbage collector implementations that require read
4344barriers.</p>
4345
4346<h5>Arguments:</h5>
4347
Chris Lattner80626e92006-03-14 20:02:51 +00004348<p>The second argument is the address to read from, which should be an address
4349allocated from the garbage collector. The first object is a pointer to the
4350start of the referenced object, if needed by the language runtime (otherwise
4351null).</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004352
4353<h5>Semantics:</h5>
4354
4355<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
4356instruction, but may be replaced with substantially more complex code by the
Gordon Henriksene1433f22007-12-25 02:31:26 +00004357garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic
4358may only be used in a function which <a href="#gc">specifies a GC
4359algorithm</a>.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004360
4361</div>
4362
4363
4364<!-- _______________________________________________________________________ -->
4365<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004366 <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
Chris Lattnerd7923912004-05-23 21:06:01 +00004367</div>
4368
4369<div class="doc_text">
4370
4371<h5>Syntax:</h5>
4372
4373<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004374 declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2)
Chris Lattnerd7923912004-05-23 21:06:01 +00004375</pre>
4376
4377<h5>Overview:</h5>
4378
4379<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
4380locations, allowing garbage collector implementations that require write
4381barriers (such as generational or reference counting collectors).</p>
4382
4383<h5>Arguments:</h5>
4384
Chris Lattner80626e92006-03-14 20:02:51 +00004385<p>The first argument is the reference to store, the second is the start of the
4386object to store it to, and the third is the address of the field of Obj to
4387store to. If the runtime does not require a pointer to the object, Obj may be
4388null.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004389
4390<h5>Semantics:</h5>
4391
4392<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
4393instruction, but may be replaced with substantially more complex code by the
Gordon Henriksene1433f22007-12-25 02:31:26 +00004394garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic
4395may only be used in a function which <a href="#gc">specifies a GC
4396algorithm</a>.</p>
Chris Lattnerd7923912004-05-23 21:06:01 +00004397
4398</div>
4399
4400
4401
4402<!-- ======================================================================= -->
4403<div class="doc_subsection">
Chris Lattner10610642004-02-14 04:08:35 +00004404 <a name="int_codegen">Code Generator Intrinsics</a>
4405</div>
4406
4407<div class="doc_text">
4408<p>
4409These intrinsics are provided by LLVM to expose special features that may only
4410be implemented with code generator support.
4411</p>
4412
4413</div>
4414
4415<!-- _______________________________________________________________________ -->
4416<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004417 <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
Chris Lattner10610642004-02-14 04:08:35 +00004418</div>
4419
4420<div class="doc_text">
4421
4422<h5>Syntax:</h5>
4423<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004424 declare i8 *@llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004425</pre>
4426
4427<h5>Overview:</h5>
4428
4429<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00004430The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
4431target-specific value indicating the return address of the current function
4432or one of its callers.
Chris Lattner10610642004-02-14 04:08:35 +00004433</p>
4434
4435<h5>Arguments:</h5>
4436
4437<p>
4438The argument to this intrinsic indicates which function to return the address
4439for. Zero indicates the calling function, one indicates its caller, etc. The
4440argument is <b>required</b> to be a constant integer value.
4441</p>
4442
4443<h5>Semantics:</h5>
4444
4445<p>
4446The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
4447the return address of the specified call frame, or zero if it cannot be
4448identified. The value returned by this intrinsic is likely to be incorrect or 0
4449for arguments other than zero, so it should only be used for debugging purposes.
4450</p>
4451
4452<p>
4453Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00004454aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00004455source-language caller.
4456</p>
4457</div>
4458
4459
4460<!-- _______________________________________________________________________ -->
4461<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004462 <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
Chris Lattner10610642004-02-14 04:08:35 +00004463</div>
4464
4465<div class="doc_text">
4466
4467<h5>Syntax:</h5>
4468<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004469 declare i8 *@llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004470</pre>
4471
4472<h5>Overview:</h5>
4473
4474<p>
Chris Lattner32b5d712006-10-15 20:05:59 +00004475The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
4476target-specific frame pointer value for the specified stack frame.
Chris Lattner10610642004-02-14 04:08:35 +00004477</p>
4478
4479<h5>Arguments:</h5>
4480
4481<p>
4482The argument to this intrinsic indicates which function to return the frame
4483pointer for. Zero indicates the calling function, one indicates its caller,
4484etc. The argument is <b>required</b> to be a constant integer value.
4485</p>
4486
4487<h5>Semantics:</h5>
4488
4489<p>
4490The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
4491the frame address of the specified call frame, or zero if it cannot be
4492identified. The value returned by this intrinsic is likely to be incorrect or 0
4493for arguments other than zero, so it should only be used for debugging purposes.
4494</p>
4495
4496<p>
4497Note that calling this intrinsic does not prevent function inlining or other
Chris Lattnerb40bb382005-03-07 20:30:51 +00004498aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner10610642004-02-14 04:08:35 +00004499source-language caller.
4500</p>
4501</div>
4502
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004503<!-- _______________________________________________________________________ -->
4504<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004505 <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
Chris Lattner57e1f392006-01-13 02:03:13 +00004506</div>
4507
4508<div class="doc_text">
4509
4510<h5>Syntax:</h5>
4511<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004512 declare i8 *@llvm.stacksave()
Chris Lattner57e1f392006-01-13 02:03:13 +00004513</pre>
4514
4515<h5>Overview:</h5>
4516
4517<p>
4518The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
Reid Spencera3e435f2007-04-04 02:42:35 +00004519the function stack, for use with <a href="#int_stackrestore">
Chris Lattner57e1f392006-01-13 02:03:13 +00004520<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
4521features like scoped automatic variable sized arrays in C99.
4522</p>
4523
4524<h5>Semantics:</h5>
4525
4526<p>
4527This intrinsic returns a opaque pointer value that can be passed to <a
Reid Spencera3e435f2007-04-04 02:42:35 +00004528href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
Chris Lattner57e1f392006-01-13 02:03:13 +00004529<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
4530<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
4531state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
4532practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
4533that were allocated after the <tt>llvm.stacksave</tt> was executed.
4534</p>
4535
4536</div>
4537
4538<!-- _______________________________________________________________________ -->
4539<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004540 <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
Chris Lattner57e1f392006-01-13 02:03:13 +00004541</div>
4542
4543<div class="doc_text">
4544
4545<h5>Syntax:</h5>
4546<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004547 declare void @llvm.stackrestore(i8 * %ptr)
Chris Lattner57e1f392006-01-13 02:03:13 +00004548</pre>
4549
4550<h5>Overview:</h5>
4551
4552<p>
4553The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
4554the function stack to the state it was in when the corresponding <a
Reid Spencera3e435f2007-04-04 02:42:35 +00004555href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
Chris Lattner57e1f392006-01-13 02:03:13 +00004556useful for implementing language features like scoped automatic variable sized
4557arrays in C99.
4558</p>
4559
4560<h5>Semantics:</h5>
4561
4562<p>
Reid Spencera3e435f2007-04-04 02:42:35 +00004563See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>.
Chris Lattner57e1f392006-01-13 02:03:13 +00004564</p>
4565
4566</div>
4567
4568
4569<!-- _______________________________________________________________________ -->
4570<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004571 <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004572</div>
4573
4574<div class="doc_text">
4575
4576<h5>Syntax:</h5>
4577<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004578 declare void @llvm.prefetch(i8* &lt;address&gt;, i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004579</pre>
4580
4581<h5>Overview:</h5>
4582
4583
4584<p>
4585The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswellfc6b8952005-05-16 16:17:45 +00004586a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
4587no
4588effect on the behavior of the program but can change its performance
Chris Lattner2a615362005-02-28 19:47:14 +00004589characteristics.
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004590</p>
4591
4592<h5>Arguments:</h5>
4593
4594<p>
4595<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
4596determining if the fetch should be for a read (0) or write (1), and
4597<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattneraeffb4a2005-03-07 20:31:38 +00004598locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattner9a9d7ac2005-02-28 19:24:19 +00004599<tt>locality</tt> arguments must be constant integers.
4600</p>
4601
4602<h5>Semantics:</h5>
4603
4604<p>
4605This intrinsic does not modify the behavior of the program. In particular,
4606prefetches cannot trap and do not produce a value. On targets that support this
4607intrinsic, the prefetch can provide hints to the processor cache for better
4608performance.
4609</p>
4610
4611</div>
4612
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004613<!-- _______________________________________________________________________ -->
4614<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004615 <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004616</div>
4617
4618<div class="doc_text">
4619
4620<h5>Syntax:</h5>
4621<pre>
Chris Lattner1df4f752007-09-21 17:30:40 +00004622 declare void @llvm.pcmarker(i32 &lt;id&gt;)
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004623</pre>
4624
4625<h5>Overview:</h5>
4626
4627
4628<p>
John Criswellfc6b8952005-05-16 16:17:45 +00004629The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4630(PC) in a region of
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004631code to simulators and other tools. The method is target specific, but it is
4632expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohen25d4f7e2005-11-11 02:15:27 +00004633The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnerd07c3f42005-11-15 06:07:55 +00004634after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb3e7afd2006-03-24 07:16:10 +00004635optimizations. The intended use is to be inserted after optimizations to allow
John Criswellfc6b8952005-05-16 16:17:45 +00004636correlations of simulation runs.
Andrew Lenharth7f4ec3b2005-03-28 20:05:49 +00004637</p>
4638
4639<h5>Arguments:</h5>
4640
4641<p>
4642<tt>id</tt> is a numerical id identifying the marker.
4643</p>
4644
4645<h5>Semantics:</h5>
4646
4647<p>
4648This intrinsic does not modify the behavior of the program. Backends that do not
4649support this intrinisic may ignore it.
4650</p>
4651
4652</div>
4653
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004654<!-- _______________________________________________________________________ -->
4655<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004656 <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004657</div>
4658
4659<div class="doc_text">
4660
4661<h5>Syntax:</h5>
4662<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004663 declare i64 @llvm.readcyclecounter( )
Andrew Lenharth51b8d542005-11-11 16:47:30 +00004664</pre>
4665
4666<h5>Overview:</h5>
4667
4668
4669<p>
4670The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4671counter register (or similar low latency, high accuracy clocks) on those targets
4672that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4673As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4674should only be used for small timings.
4675</p>
4676
4677<h5>Semantics:</h5>
4678
4679<p>
4680When directly supported, reading the cycle counter should not modify any memory.
4681Implementations are allowed to either return a application specific value or a
4682system wide value. On backends without support, this is lowered to a constant 0.
4683</p>
4684
4685</div>
4686
Chris Lattner10610642004-02-14 04:08:35 +00004687<!-- ======================================================================= -->
4688<div class="doc_subsection">
Chris Lattner33aec9e2004-02-12 17:01:32 +00004689 <a name="int_libc">Standard C Library Intrinsics</a>
4690</div>
4691
4692<div class="doc_text">
4693<p>
Chris Lattner10610642004-02-14 04:08:35 +00004694LLVM provides intrinsics for a few important standard C library functions.
4695These intrinsics allow source-language front-ends to pass information about the
4696alignment of the pointer arguments to the code generator, providing opportunity
4697for more efficient code generation.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004698</p>
4699
4700</div>
4701
4702<!-- _______________________________________________________________________ -->
4703<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004704 <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
Chris Lattner33aec9e2004-02-12 17:01:32 +00004705</div>
4706
4707<div class="doc_text">
4708
4709<h5>Syntax:</h5>
4710<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004711 declare void @llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004712 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004713 declare void @llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004714 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner33aec9e2004-02-12 17:01:32 +00004715</pre>
4716
4717<h5>Overview:</h5>
4718
4719<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004720The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004721location to the destination location.
4722</p>
4723
4724<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004725Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4726intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner33aec9e2004-02-12 17:01:32 +00004727</p>
4728
4729<h5>Arguments:</h5>
4730
4731<p>
4732The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004733the source. The third argument is an integer argument
Chris Lattner33aec9e2004-02-12 17:01:32 +00004734specifying the number of bytes to copy, and the fourth argument is the alignment
4735of the source and destination locations.
4736</p>
4737
Chris Lattner3301ced2004-02-12 21:18:15 +00004738<p>
4739If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004740the caller guarantees that both the source and destination pointers are aligned
4741to that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004742</p>
4743
Chris Lattner33aec9e2004-02-12 17:01:32 +00004744<h5>Semantics:</h5>
4745
4746<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004747The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner33aec9e2004-02-12 17:01:32 +00004748location to the destination location, which are not allowed to overlap. It
4749copies "len" bytes of memory over. If the argument is known to be aligned to
4750some boundary, this can be specified as the fourth argument, otherwise it should
4751be set to 0 or 1.
4752</p>
4753</div>
4754
4755
Chris Lattner0eb51b42004-02-12 18:10:10 +00004756<!-- _______________________________________________________________________ -->
4757<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004758 <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
Chris Lattner0eb51b42004-02-12 18:10:10 +00004759</div>
4760
4761<div class="doc_text">
4762
4763<h5>Syntax:</h5>
4764<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004765 declare void @llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004766 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004767 declare void @llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004768 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner0eb51b42004-02-12 18:10:10 +00004769</pre>
4770
4771<h5>Overview:</h5>
4772
4773<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004774The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4775location to the destination location. It is similar to the
Chris Lattner4b2cbcf2008-01-06 19:51:52 +00004776'<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004777</p>
4778
4779<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004780Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4781intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattner0eb51b42004-02-12 18:10:10 +00004782</p>
4783
4784<h5>Arguments:</h5>
4785
4786<p>
4787The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner5b310c32006-03-03 00:07:20 +00004788the source. The third argument is an integer argument
Chris Lattner0eb51b42004-02-12 18:10:10 +00004789specifying the number of bytes to copy, and the fourth argument is the alignment
4790of the source and destination locations.
4791</p>
4792
Chris Lattner3301ced2004-02-12 21:18:15 +00004793<p>
4794If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004795the caller guarantees that the source and destination pointers are aligned to
4796that boundary.
Chris Lattner3301ced2004-02-12 21:18:15 +00004797</p>
4798
Chris Lattner0eb51b42004-02-12 18:10:10 +00004799<h5>Semantics:</h5>
4800
4801<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004802The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattner0eb51b42004-02-12 18:10:10 +00004803location to the destination location, which may overlap. It
4804copies "len" bytes of memory over. If the argument is known to be aligned to
4805some boundary, this can be specified as the fourth argument, otherwise it should
4806be set to 0 or 1.
4807</p>
4808</div>
4809
Chris Lattner8ff75902004-01-06 05:31:32 +00004810
Chris Lattner10610642004-02-14 04:08:35 +00004811<!-- _______________________________________________________________________ -->
4812<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004813 <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner10610642004-02-14 04:08:35 +00004814</div>
4815
4816<div class="doc_text">
4817
4818<h5>Syntax:</h5>
4819<pre>
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004820 declare void @llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004821 i32 &lt;len&gt;, i32 &lt;align&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00004822 declare void @llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
Reid Spencerca86e162006-12-31 07:07:53 +00004823 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner10610642004-02-14 04:08:35 +00004824</pre>
4825
4826<h5>Overview:</h5>
4827
4828<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004829The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner10610642004-02-14 04:08:35 +00004830byte value.
4831</p>
4832
4833<p>
4834Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4835does not return a value, and takes an extra alignment argument.
4836</p>
4837
4838<h5>Arguments:</h5>
4839
4840<p>
4841The first argument is a pointer to the destination to fill, the second is the
Chris Lattner5b310c32006-03-03 00:07:20 +00004842byte value to fill it with, the third argument is an integer
Chris Lattner10610642004-02-14 04:08:35 +00004843argument specifying the number of bytes to fill, and the fourth argument is the
4844known alignment of destination location.
4845</p>
4846
4847<p>
4848If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattnerf0afc2c2006-03-04 00:02:10 +00004849the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner10610642004-02-14 04:08:35 +00004850</p>
4851
4852<h5>Semantics:</h5>
4853
4854<p>
Chris Lattner5b310c32006-03-03 00:07:20 +00004855The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4856the
Chris Lattner10610642004-02-14 04:08:35 +00004857destination location. If the argument is known to be aligned to some boundary,
4858this can be specified as the fourth argument, otherwise it should be set to 0 or
48591.
4860</p>
4861</div>
4862
4863
Chris Lattner32006282004-06-11 02:28:03 +00004864<!-- _______________________________________________________________________ -->
4865<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004866 <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattnera4d74142005-07-21 01:29:16 +00004867</div>
4868
4869<div class="doc_text">
4870
4871<h5>Syntax:</h5>
Dale Johannesen408f9c12007-10-02 17:47:38 +00004872<p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any
Dan Gohman91c284c2007-10-15 20:30:11 +00004873floating point or vector of floating point type. Not all targets support all
4874types however.
Chris Lattnera4d74142005-07-21 01:29:16 +00004875<pre>
Dale Johannesen408f9c12007-10-02 17:47:38 +00004876 declare float @llvm.sqrt.f32(float %Val)
4877 declare double @llvm.sqrt.f64(double %Val)
4878 declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val)
4879 declare fp128 @llvm.sqrt.f128(fp128 %Val)
4880 declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val)
Chris Lattnera4d74142005-07-21 01:29:16 +00004881</pre>
4882
4883<h5>Overview:</h5>
4884
4885<p>
Reid Spencer0b118202006-01-16 21:12:35 +00004886The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Dan Gohman91c284c2007-10-15 20:30:11 +00004887returning the same value as the libm '<tt>sqrt</tt>' functions would. Unlike
Chris Lattnera4d74142005-07-21 01:29:16 +00004888<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
Chris Lattner103e2d72008-01-29 07:00:44 +00004889negative numbers other than -0.0 (which allows for better optimization, because
4890there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is
4891defined to return -0.0 like IEEE sqrt.
Chris Lattnera4d74142005-07-21 01:29:16 +00004892</p>
4893
4894<h5>Arguments:</h5>
4895
4896<p>
4897The argument and return value are floating point numbers of the same type.
4898</p>
4899
4900<h5>Semantics:</h5>
4901
4902<p>
Dan Gohmand6257fe2007-07-16 14:37:41 +00004903This function returns the sqrt of the specified operand if it is a nonnegative
Chris Lattnera4d74142005-07-21 01:29:16 +00004904floating point number.
4905</p>
4906</div>
4907
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004908<!-- _______________________________________________________________________ -->
4909<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00004910 <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004911</div>
4912
4913<div class="doc_text">
4914
4915<h5>Syntax:</h5>
Dale Johannesen408f9c12007-10-02 17:47:38 +00004916<p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any
Dan Gohman91c284c2007-10-15 20:30:11 +00004917floating point or vector of floating point type. Not all targets support all
4918types however.
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004919<pre>
Dale Johannesen408f9c12007-10-02 17:47:38 +00004920 declare float @llvm.powi.f32(float %Val, i32 %power)
4921 declare double @llvm.powi.f64(double %Val, i32 %power)
4922 declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power)
4923 declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power)
4924 declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power)
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004925</pre>
4926
4927<h5>Overview:</h5>
4928
4929<p>
4930The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4931specified (positive or negative) power. The order of evaluation of
Dan Gohman91c284c2007-10-15 20:30:11 +00004932multiplications is not defined. When a vector of floating point type is
4933used, the second argument remains a scalar integer value.
Chris Lattnerf4d252d2006-09-08 06:34:02 +00004934</p>
4935
4936<h5>Arguments:</h5>
4937
4938<p>
4939The second argument is an integer power, and the first is a value to raise to
4940that power.
4941</p>
4942
4943<h5>Semantics:</h5>
4944
4945<p>
4946This function returns the first value raised to the second power with an
4947unspecified sequence of rounding operations.</p>
4948</div>
4949
Dan Gohman91c284c2007-10-15 20:30:11 +00004950<!-- _______________________________________________________________________ -->
4951<div class="doc_subsubsection">
4952 <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a>
4953</div>
4954
4955<div class="doc_text">
4956
4957<h5>Syntax:</h5>
4958<p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any
4959floating point or vector of floating point type. Not all targets support all
4960types however.
4961<pre>
4962 declare float @llvm.sin.f32(float %Val)
4963 declare double @llvm.sin.f64(double %Val)
4964 declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val)
4965 declare fp128 @llvm.sin.f128(fp128 %Val)
4966 declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val)
4967</pre>
4968
4969<h5>Overview:</h5>
4970
4971<p>
4972The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand.
4973</p>
4974
4975<h5>Arguments:</h5>
4976
4977<p>
4978The argument and return value are floating point numbers of the same type.
4979</p>
4980
4981<h5>Semantics:</h5>
4982
4983<p>
4984This function returns the sine of the specified operand, returning the
4985same values as the libm <tt>sin</tt> functions would, and handles error
Dan Gohmanba83b7e2007-10-17 18:05:13 +00004986conditions in the same way.</p>
Dan Gohman91c284c2007-10-15 20:30:11 +00004987</div>
4988
4989<!-- _______________________________________________________________________ -->
4990<div class="doc_subsubsection">
4991 <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a>
4992</div>
4993
4994<div class="doc_text">
4995
4996<h5>Syntax:</h5>
4997<p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any
4998floating point or vector of floating point type. Not all targets support all
4999types however.
5000<pre>
5001 declare float @llvm.cos.f32(float %Val)
5002 declare double @llvm.cos.f64(double %Val)
5003 declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val)
5004 declare fp128 @llvm.cos.f128(fp128 %Val)
5005 declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val)
5006</pre>
5007
5008<h5>Overview:</h5>
5009
5010<p>
5011The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand.
5012</p>
5013
5014<h5>Arguments:</h5>
5015
5016<p>
5017The argument and return value are floating point numbers of the same type.
5018</p>
5019
5020<h5>Semantics:</h5>
5021
5022<p>
5023This function returns the cosine of the specified operand, returning the
5024same values as the libm <tt>cos</tt> functions would, and handles error
Dan Gohmanba83b7e2007-10-17 18:05:13 +00005025conditions in the same way.</p>
Dan Gohman91c284c2007-10-15 20:30:11 +00005026</div>
5027
5028<!-- _______________________________________________________________________ -->
5029<div class="doc_subsubsection">
5030 <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a>
5031</div>
5032
5033<div class="doc_text">
5034
5035<h5>Syntax:</h5>
5036<p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any
5037floating point or vector of floating point type. Not all targets support all
5038types however.
5039<pre>
5040 declare float @llvm.pow.f32(float %Val, float %Power)
5041 declare double @llvm.pow.f64(double %Val, double %Power)
5042 declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power)
5043 declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power)
5044 declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power)
5045</pre>
5046
5047<h5>Overview:</h5>
5048
5049<p>
5050The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the
5051specified (positive or negative) power.
5052</p>
5053
5054<h5>Arguments:</h5>
5055
5056<p>
5057The second argument is a floating point power, and the first is a value to
5058raise to that power.
5059</p>
5060
5061<h5>Semantics:</h5>
5062
5063<p>
5064This function returns the first value raised to the second power,
5065returning the
5066same values as the libm <tt>pow</tt> functions would, and handles error
Dan Gohmanba83b7e2007-10-17 18:05:13 +00005067conditions in the same way.</p>
Dan Gohman91c284c2007-10-15 20:30:11 +00005068</div>
5069
Chris Lattnerf4d252d2006-09-08 06:34:02 +00005070
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005071<!-- ======================================================================= -->
5072<div class="doc_subsection">
Nate Begeman7e36c472006-01-13 23:26:38 +00005073 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005074</div>
5075
5076<div class="doc_text">
5077<p>
Nate Begeman7e36c472006-01-13 23:26:38 +00005078LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005079These allow efficient code generation for some algorithms.
5080</p>
5081
5082</div>
5083
5084<!-- _______________________________________________________________________ -->
5085<div class="doc_subsubsection">
Reid Spencera3e435f2007-04-04 02:42:35 +00005086 <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
Nate Begeman7e36c472006-01-13 23:26:38 +00005087</div>
5088
5089<div class="doc_text">
5090
5091<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00005092<p>This is an overloaded intrinsic function. You can use bswap on any integer
Chandler Carruth69940402007-08-04 01:51:18 +00005093type that is an even number of bytes (i.e. BitWidth % 16 == 0).
Nate Begeman7e36c472006-01-13 23:26:38 +00005094<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005095 declare i16 @llvm.bswap.i16(i16 &lt;id&gt;)
5096 declare i32 @llvm.bswap.i32(i32 &lt;id&gt;)
5097 declare i64 @llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman7e36c472006-01-13 23:26:38 +00005098</pre>
5099
5100<h5>Overview:</h5>
5101
5102<p>
Reid Spencer338ea092007-04-02 02:25:19 +00005103The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer
Reid Spencer409e28f2007-04-01 08:04:23 +00005104values with an even number of bytes (positive multiple of 16 bits). These are
5105useful for performing operations on data that is not in the target's native
5106byte order.
Nate Begeman7e36c472006-01-13 23:26:38 +00005107</p>
5108
5109<h5>Semantics:</h5>
5110
5111<p>
Chandler Carruth69940402007-08-04 01:51:18 +00005112The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high
Reid Spencerca86e162006-12-31 07:07:53 +00005113and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
5114intrinsic returns an i32 value that has the four bytes of the input i32
5115swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
Chandler Carruth69940402007-08-04 01:51:18 +00005116i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>,
5117<tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to
Reid Spencer409e28f2007-04-01 08:04:23 +00005118additional even-byte lengths (6 bytes, 8 bytes and more, respectively).
Nate Begeman7e36c472006-01-13 23:26:38 +00005119</p>
5120
5121</div>
5122
5123<!-- _______________________________________________________________________ -->
5124<div class="doc_subsubsection">
Reid Spencer0b118202006-01-16 21:12:35 +00005125 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005126</div>
5127
5128<div class="doc_text">
5129
5130<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00005131<p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit
5132width. Not all targets support all bit widths however.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005133<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005134 declare i8 @llvm.ctpop.i8 (i8 &lt;src&gt;)
5135 declare i16 @llvm.ctpop.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00005136 declare i32 @llvm.ctpop.i32(i32 &lt;src&gt;)
Chandler Carruth69940402007-08-04 01:51:18 +00005137 declare i64 @llvm.ctpop.i64(i64 &lt;src&gt;)
5138 declare i256 @llvm.ctpop.i256(i256 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005139</pre>
5140
5141<h5>Overview:</h5>
5142
5143<p>
Chris Lattnerec6cb612006-01-16 22:38:59 +00005144The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
5145value.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005146</p>
5147
5148<h5>Arguments:</h5>
5149
5150<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00005151The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00005152integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005153</p>
5154
5155<h5>Semantics:</h5>
5156
5157<p>
5158The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
5159</p>
5160</div>
5161
5162<!-- _______________________________________________________________________ -->
5163<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00005164 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005165</div>
5166
5167<div class="doc_text">
5168
5169<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00005170<p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any
5171integer bit width. Not all targets support all bit widths however.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005172<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005173 declare i8 @llvm.ctlz.i8 (i8 &lt;src&gt;)
5174 declare i16 @llvm.ctlz.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00005175 declare i32 @llvm.ctlz.i32(i32 &lt;src&gt;)
Chandler Carruth69940402007-08-04 01:51:18 +00005176 declare i64 @llvm.ctlz.i64(i64 &lt;src&gt;)
5177 declare i256 @llvm.ctlz.i256(i256 &lt;src&gt;)
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005178</pre>
5179
5180<h5>Overview:</h5>
5181
5182<p>
Reid Spencer0b118202006-01-16 21:12:35 +00005183The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
5184leading zeros in a variable.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005185</p>
5186
5187<h5>Arguments:</h5>
5188
5189<p>
Chris Lattnercfe6b372005-05-07 01:46:40 +00005190The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00005191integer type. The return type must match the argument type.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005192</p>
5193
5194<h5>Semantics:</h5>
5195
5196<p>
Chris Lattnereff29ab2005-05-15 19:39:26 +00005197The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
5198in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerca86e162006-12-31 07:07:53 +00005199of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharthec370fd2005-05-03 18:01:48 +00005200</p>
5201</div>
Chris Lattner32006282004-06-11 02:28:03 +00005202
5203
Chris Lattnereff29ab2005-05-15 19:39:26 +00005204
5205<!-- _______________________________________________________________________ -->
5206<div class="doc_subsubsection">
Chris Lattner8a886be2006-01-16 22:34:14 +00005207 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnereff29ab2005-05-15 19:39:26 +00005208</div>
5209
5210<div class="doc_text">
5211
5212<h5>Syntax:</h5>
Reid Spencer409e28f2007-04-01 08:04:23 +00005213<p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any
5214integer bit width. Not all targets support all bit widths however.
Chris Lattnereff29ab2005-05-15 19:39:26 +00005215<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005216 declare i8 @llvm.cttz.i8 (i8 &lt;src&gt;)
5217 declare i16 @llvm.cttz.i16(i16 &lt;src&gt;)
Anton Korobeynikovec43a062007-03-22 00:02:17 +00005218 declare i32 @llvm.cttz.i32(i32 &lt;src&gt;)
Chandler Carruth69940402007-08-04 01:51:18 +00005219 declare i64 @llvm.cttz.i64(i64 &lt;src&gt;)
5220 declare i256 @llvm.cttz.i256(i256 &lt;src&gt;)
Chris Lattnereff29ab2005-05-15 19:39:26 +00005221</pre>
5222
5223<h5>Overview:</h5>
5224
5225<p>
Reid Spencer0b118202006-01-16 21:12:35 +00005226The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
5227trailing zeros.
Chris Lattnereff29ab2005-05-15 19:39:26 +00005228</p>
5229
5230<h5>Arguments:</h5>
5231
5232<p>
5233The only argument is the value to be counted. The argument may be of any
Reid Spencera5173382007-01-04 16:43:23 +00005234integer type. The return type must match the argument type.
Chris Lattnereff29ab2005-05-15 19:39:26 +00005235</p>
5236
5237<h5>Semantics:</h5>
5238
5239<p>
5240The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
5241in a variable. If the src == 0 then the result is the size in bits of the type
5242of src. For example, <tt>llvm.cttz(2) = 1</tt>.
5243</p>
5244</div>
5245
Reid Spencer497d93e2007-04-01 08:27:01 +00005246<!-- _______________________________________________________________________ -->
5247<div class="doc_subsubsection">
Reid Spencerbeacf662007-04-10 02:51:31 +00005248 <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a>
Reid Spencera13ba7d2007-04-01 19:00:37 +00005249</div>
5250
5251<div class="doc_text">
5252
5253<h5>Syntax:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00005254<p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt>
Reid Spencera13ba7d2007-04-01 19:00:37 +00005255on any integer bit width.
5256<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005257 declare i17 @llvm.part.select.i17 (i17 %val, i32 %loBit, i32 %hiBit)
5258 declare i29 @llvm.part.select.i29 (i29 %val, i32 %loBit, i32 %hiBit)
Reid Spencera13ba7d2007-04-01 19:00:37 +00005259</pre>
5260
5261<h5>Overview:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00005262<p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a
Reid Spencera13ba7d2007-04-01 19:00:37 +00005263range of bits from an integer value and returns them in the same bit width as
5264the original value.</p>
5265
5266<h5>Arguments:</h5>
5267<p>The first argument, <tt>%val</tt> and the result may be integer types of
5268any bit width but they must have the same bit width. The second and third
Reid Spencera3e435f2007-04-04 02:42:35 +00005269arguments must be <tt>i32</tt> type since they specify only a bit index.</p>
Reid Spencera13ba7d2007-04-01 19:00:37 +00005270
5271<h5>Semantics:</h5>
Reid Spencerbeacf662007-04-10 02:51:31 +00005272<p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes
Reid Spencera3e435f2007-04-04 02:42:35 +00005273of operation: forwards and reverse. If <tt>%loBit</tt> is greater than
5274<tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it
5275operates in forward mode.</p>
5276<p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt>
5277right by <tt>%loBit</tt> bits and then ANDing it with a mask with
Reid Spencera13ba7d2007-04-01 19:00:37 +00005278only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p>
5279<ol>
5280 <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified
5281 by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li>
5282 <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value
5283 to determine the number of bits to retain.</li>
5284 <li>A mask of the retained bits is created by shifting a -1 value.</li>
5285 <li>The mask is ANDed with <tt>%val</tt> to produce the result.
5286</ol>
Reid Spencerd6a85b52007-05-14 16:14:57 +00005287<p>In reverse mode, a similar computation is made except that the bits are
5288returned in the reverse order. So, for example, if <tt>X</tt> has the value
5289<tt>i16 0x0ACF (101011001111)</tt> and we apply
5290<tt>part.select(i16 X, 8, 3)</tt> to it, we get back the value
5291<tt>i16 0x0026 (000000100110)</tt>.</p>
Reid Spencera13ba7d2007-04-01 19:00:37 +00005292</div>
5293
Reid Spencerf86037f2007-04-11 23:23:49 +00005294<div class="doc_subsubsection">
5295 <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a>
5296</div>
5297
5298<div class="doc_text">
5299
5300<h5>Syntax:</h5>
5301<p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt>
5302on any integer bit width.
5303<pre>
Chandler Carruth69940402007-08-04 01:51:18 +00005304 declare i17 @llvm.part.set.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi)
5305 declare i29 @llvm.part.set.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi)
Reid Spencerf86037f2007-04-11 23:23:49 +00005306</pre>
5307
5308<h5>Overview:</h5>
5309<p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range
5310of bits in an integer value with another integer value. It returns the integer
5311with the replaced bits.</p>
5312
5313<h5>Arguments:</h5>
5314<p>The first argument, <tt>%val</tt> and the result may be integer types of
5315any bit width but they must have the same bit width. <tt>%val</tt> is the value
5316whose bits will be replaced. The second argument, <tt>%repl</tt> may be an
5317integer of any bit width. The third and fourth arguments must be <tt>i32</tt>
5318type since they specify only a bit index.</p>
5319
5320<h5>Semantics:</h5>
5321<p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes
5322of operation: forwards and reverse. If <tt>%lo</tt> is greater than
5323<tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it
5324operates in forward mode.</p>
5325<p>For both modes, the <tt>%repl</tt> value is prepared for use by either
5326truncating it down to the size of the replacement area or zero extending it
5327up to that size.</p>
5328<p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive)
5329are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit
5330in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up
5331to the <tt>%hi</tt>th bit.
Reid Spencerc6749c42007-05-14 16:50:20 +00005332<p>In reverse mode, a similar computation is made except that the bits are
5333reversed. That is, the <tt>0</tt>th bit in <tt>%repl</tt> replaces the
5334<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 +00005335<h5>Examples:</h5>
5336<pre>
Reid Spencerf0dbf642007-04-12 01:03:03 +00005337 llvm.part.set(0xFFFF, 0, 4, 7) -&gt; 0xFF0F
Reid Spencerc6749c42007-05-14 16:50:20 +00005338 llvm.part.set(0xFFFF, 0, 7, 4) -&gt; 0xFF0F
5339 llvm.part.set(0xFFFF, 1, 7, 4) -&gt; 0xFF8F
5340 llvm.part.set(0xFFFF, F, 8, 3) -&gt; 0xFFE7
Reid Spencerf0dbf642007-04-12 01:03:03 +00005341 llvm.part.set(0xFFFF, 0, 3, 8) -&gt; 0xFE07
Reid Spencerc8910842007-04-11 23:49:50 +00005342</pre>
Reid Spencerf86037f2007-04-11 23:23:49 +00005343</div>
5344
Chris Lattner8ff75902004-01-06 05:31:32 +00005345<!-- ======================================================================= -->
5346<div class="doc_subsection">
5347 <a name="int_debugger">Debugger Intrinsics</a>
5348</div>
5349
5350<div class="doc_text">
5351<p>
5352The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
5353are described in the <a
5354href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
5355Debugging</a> document.
5356</p>
5357</div>
5358
5359
Jim Laskeydd4ef1b2007-03-14 19:31:19 +00005360<!-- ======================================================================= -->
5361<div class="doc_subsection">
5362 <a name="int_eh">Exception Handling Intrinsics</a>
5363</div>
5364
5365<div class="doc_text">
5366<p> The LLVM exception handling intrinsics (which all start with
5367<tt>llvm.eh.</tt> prefix), are described in the <a
5368href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception
5369Handling</a> document. </p>
5370</div>
5371
Tanya Lattner6d806e92007-06-15 20:50:54 +00005372<!-- ======================================================================= -->
5373<div class="doc_subsection">
Duncan Sandsf7331b32007-09-11 14:10:23 +00005374 <a name="int_trampoline">Trampoline Intrinsic</a>
Duncan Sands36397f52007-07-27 12:58:54 +00005375</div>
5376
5377<div class="doc_text">
5378<p>
Duncan Sandsf7331b32007-09-11 14:10:23 +00005379 This intrinsic makes it possible to excise one parameter, marked with
Duncan Sands36397f52007-07-27 12:58:54 +00005380 the <tt>nest</tt> attribute, from a function. The result is a callable
5381 function pointer lacking the nest parameter - the caller does not need
5382 to provide a value for it. Instead, the value to use is stored in
5383 advance in a "trampoline", a block of memory usually allocated
5384 on the stack, which also contains code to splice the nest value into the
5385 argument list. This is used to implement the GCC nested function address
5386 extension.
5387</p>
5388<p>
5389 For example, if the function is
5390 <tt>i32 f(i8* nest %c, i32 %x, i32 %y)</tt> then the resulting function
Bill Wendling03295ca2007-09-22 09:23:55 +00005391 pointer has signature <tt>i32 (i32, i32)*</tt>. It can be created as follows:</p>
Duncan Sands36397f52007-07-27 12:58:54 +00005392<pre>
Duncan Sandsf7331b32007-09-11 14:10:23 +00005393 %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86
5394 %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0
5395 %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval )
5396 %fp = bitcast i8* %p to i32 (i32, i32)*
Duncan Sands36397f52007-07-27 12:58:54 +00005397</pre>
Bill Wendling03295ca2007-09-22 09:23:55 +00005398 <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent
5399 to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p>
Duncan Sands36397f52007-07-27 12:58:54 +00005400</div>
5401
5402<!-- _______________________________________________________________________ -->
5403<div class="doc_subsubsection">
5404 <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a>
5405</div>
5406<div class="doc_text">
5407<h5>Syntax:</h5>
5408<pre>
Duncan Sandsf7331b32007-09-11 14:10:23 +00005409declare i8* @llvm.init.trampoline(i8* &lt;tramp&gt;, i8* &lt;func&gt;, i8* &lt;nval&gt;)
Duncan Sands36397f52007-07-27 12:58:54 +00005410</pre>
5411<h5>Overview:</h5>
5412<p>
Duncan Sandsf7331b32007-09-11 14:10:23 +00005413 This fills the memory pointed to by <tt>tramp</tt> with code
5414 and returns a function pointer suitable for executing it.
Duncan Sands36397f52007-07-27 12:58:54 +00005415</p>
5416<h5>Arguments:</h5>
5417<p>
5418 The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all
5419 pointers. The <tt>tramp</tt> argument must point to a sufficiently large
5420 and sufficiently aligned block of memory; this memory is written to by the
Duncan Sandsc00c2ba2007-08-22 23:39:54 +00005421 intrinsic. Note that the size and the alignment are target-specific - LLVM
5422 currently provides no portable way of determining them, so a front-end that
5423 generates this intrinsic needs to have some target-specific knowledge.
5424 The <tt>func</tt> argument must hold a function bitcast to an <tt>i8*</tt>.
Duncan Sands36397f52007-07-27 12:58:54 +00005425</p>
5426<h5>Semantics:</h5>
5427<p>
5428 The block of memory pointed to by <tt>tramp</tt> is filled with target
Duncan Sandsf7331b32007-09-11 14:10:23 +00005429 dependent code, turning it into a function. A pointer to this function is
5430 returned, but needs to be bitcast to an
Duncan Sands36397f52007-07-27 12:58:54 +00005431 <a href="#int_trampoline">appropriate function pointer type</a>
Duncan Sandsf7331b32007-09-11 14:10:23 +00005432 before being called. The new function's signature is the same as that of
5433 <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute
5434 removed. At most one such <tt>nest</tt> argument is allowed, and it must be
5435 of pointer type. Calling the new function is equivalent to calling
5436 <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the
5437 missing <tt>nest</tt> argument. If, after calling
5438 <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is
5439 modified, then the effect of any later call to the returned function pointer is
5440 undefined.
Duncan Sands36397f52007-07-27 12:58:54 +00005441</p>
5442</div>
5443
5444<!-- ======================================================================= -->
5445<div class="doc_subsection">
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00005446 <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a>
5447</div>
5448
5449<div class="doc_text">
5450<p>
5451 These intrinsic functions expand the "universal IR" of LLVM to represent
5452 hardware constructs for atomic operations and memory synchronization. This
5453 provides an interface to the hardware, not an interface to the programmer. It
5454 is aimed at a low enough level to allow any programming models or APIs which
5455 need atomic behaviors to map cleanly onto it. It is also modeled primarily on
5456 hardware behavior. Just as hardware provides a "universal IR" for source
5457 languages, it also provides a starting point for developing a "universal"
5458 atomic operation and synchronization IR.
5459</p>
5460<p>
5461 These do <em>not</em> form an API such as high-level threading libraries,
5462 software transaction memory systems, atomic primitives, and intrinsic
5463 functions as found in BSD, GNU libc, atomic_ops, APR, and other system and
5464 application libraries. The hardware interface provided by LLVM should allow
5465 a clean implementation of all of these APIs and parallel programming models.
5466 No one model or paradigm should be selected above others unless the hardware
5467 itself ubiquitously does so.
5468
5469</p>
5470</div>
5471
5472<!-- _______________________________________________________________________ -->
5473<div class="doc_subsubsection">
5474 <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a>
5475</div>
5476<div class="doc_text">
5477<h5>Syntax:</h5>
5478<pre>
5479declare void @llvm.memory.barrier( i1 &lt;ll&gt;, i1 &lt;ls&gt;, i1 &lt;sl&gt;, i1 &lt;ss&gt;,
5480i1 &lt;device&gt; )
5481
5482</pre>
5483<h5>Overview:</h5>
5484<p>
5485 The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between
5486 specific pairs of memory access types.
5487</p>
5488<h5>Arguments:</h5>
5489<p>
5490 The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.
5491 The first four arguments enables a specific barrier as listed below. The fith
5492 argument specifies that the barrier applies to io or device or uncached memory.
5493
5494</p>
5495 <ul>
5496 <li><tt>ll</tt>: load-load barrier</li>
5497 <li><tt>ls</tt>: load-store barrier</li>
5498 <li><tt>sl</tt>: store-load barrier</li>
5499 <li><tt>ss</tt>: store-store barrier</li>
5500 <li><tt>device</tt>: barrier applies to device and uncached memory also.
5501 </ul>
5502<h5>Semantics:</h5>
5503<p>
5504 This intrinsic causes the system to enforce some ordering constraints upon
5505 the loads and stores of the program. This barrier does not indicate
5506 <em>when</em> any events will occur, it only enforces an <em>order</em> in
5507 which they occur. For any of the specified pairs of load and store operations
5508 (f.ex. load-load, or store-load), all of the first operations preceding the
5509 barrier will complete before any of the second operations succeeding the
5510 barrier begin. Specifically the semantics for each pairing is as follows:
5511</p>
5512 <ul>
5513 <li><tt>ll</tt>: All loads before the barrier must complete before any load
5514 after the barrier begins.</li>
5515
5516 <li><tt>ls</tt>: All loads before the barrier must complete before any
5517 store after the barrier begins.</li>
5518 <li><tt>ss</tt>: All stores before the barrier must complete before any
5519 store after the barrier begins.</li>
5520 <li><tt>sl</tt>: All stores before the barrier must complete before any
5521 load after the barrier begins.</li>
5522 </ul>
5523<p>
5524 These semantics are applied with a logical "and" behavior when more than one
5525 is enabled in a single memory barrier intrinsic.
5526</p>
5527<p>
5528 Backends may implement stronger barriers than those requested when they do not
5529 support as fine grained a barrier as requested. Some architectures do not
5530 need all types of barriers and on such architectures, these become noops.
5531</p>
5532<h5>Example:</h5>
5533<pre>
5534%ptr = malloc i32
5535 store i32 4, %ptr
5536
5537%result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i>
5538 call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false )
5539 <i>; guarantee the above finishes</i>
5540 store i32 8, %ptr <i>; before this begins</i>
5541</pre>
5542</div>
5543
Andrew Lenharthab0b9492008-02-21 06:45:13 +00005544<!-- _______________________________________________________________________ -->
5545<div class="doc_subsubsection">
5546 <a name="int_atomic_lcs">'<tt>llvm.atomic.lcs.*</tt>' Intrinsic</a>
5547</div>
5548<div class="doc_text">
5549<h5>Syntax:</h5>
5550<p>
5551 This is an overloaded intrinsic. You can use <tt>llvm.atomic.lcs</tt> on any
5552 integer bit width. Not all targets support all bit widths however.</p>
5553
5554<pre>
5555declare i8 @llvm.atomic.lcs.i8( i8* &lt;ptr&gt;, i8 &lt;cmp&gt;, i8 &lt;val&gt; )
5556declare i16 @llvm.atomic.lcs.i16( i16* &lt;ptr&gt;, i16 &lt;cmp&gt;, i16 &lt;val&gt; )
5557declare i32 @llvm.atomic.lcs.i32( i32* &lt;ptr&gt;, i32 &lt;cmp&gt;, i32 &lt;val&gt; )
5558declare i64 @llvm.atomic.lcs.i64( i64* &lt;ptr&gt;, i64 &lt;cmp&gt;, i64 &lt;val&gt; )
5559
5560</pre>
5561<h5>Overview:</h5>
5562<p>
5563 This loads a value in memory and compares it to a given value. If they are
5564 equal, it stores a new value into the memory.
5565</p>
5566<h5>Arguments:</h5>
5567<p>
5568 The <tt>llvm.atomic.lcs</tt> intrinsic takes three arguments. The result as
5569 well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the
5570 same bit width. The <tt>ptr</tt> argument must be a pointer to a value of
5571 this integer type. While any bit width integer may be used, targets may only
5572 lower representations they support in hardware.
5573
5574</p>
5575<h5>Semantics:</h5>
5576<p>
5577 This entire intrinsic must be executed atomically. It first loads the value
5578 in memory pointed to by <tt>ptr</tt> and compares it with the value
5579 <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The
5580 loaded value is yielded in all cases. This provides the equivalent of an
5581 atomic compare-and-swap operation within the SSA framework.
5582</p>
5583<h5>Examples:</h5>
5584
5585<pre>
5586%ptr = malloc i32
5587 store i32 4, %ptr
5588
5589%val1 = add i32 4, 4
5590%result1 = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 4, %val1 )
5591 <i>; yields {i32}:result1 = 4</i>
5592%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
5593%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
5594
5595%val2 = add i32 1, 1
5596%result2 = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 5, %val2 )
5597 <i>; yields {i32}:result2 = 8</i>
5598%stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i>
5599
5600%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i>
5601</pre>
5602</div>
5603
5604<!-- _______________________________________________________________________ -->
5605<div class="doc_subsubsection">
5606 <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a>
5607</div>
5608<div class="doc_text">
5609<h5>Syntax:</h5>
5610
5611<p>
5612 This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any
5613 integer bit width. Not all targets support all bit widths however.</p>
5614<pre>
5615declare i8 @llvm.atomic.swap.i8( i8* &lt;ptr&gt;, i8 &lt;val&gt; )
5616declare i16 @llvm.atomic.swap.i16( i16* &lt;ptr&gt;, i16 &lt;val&gt; )
5617declare i32 @llvm.atomic.swap.i32( i32* &lt;ptr&gt;, i32 &lt;val&gt; )
5618declare i64 @llvm.atomic.swap.i64( i64* &lt;ptr&gt;, i64 &lt;val&gt; )
5619
5620</pre>
5621<h5>Overview:</h5>
5622<p>
5623 This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields
5624 the value from memory. It then stores the value in <tt>val</tt> in the memory
5625 at <tt>ptr</tt>.
5626</p>
5627<h5>Arguments:</h5>
5628
5629<p>
5630 The <tt>llvm.atomic.ls</tt> intrinsic takes two arguments. Both the
5631 <tt>val</tt> argument and the result must be integers of the same bit width.
5632 The first argument, <tt>ptr</tt>, must be a pointer to a value of this
5633 integer type. The targets may only lower integer representations they
5634 support.
5635</p>
5636<h5>Semantics:</h5>
5637<p>
5638 This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and
5639 stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the
5640 equivalent of an atomic swap operation within the SSA framework.
5641
5642</p>
5643<h5>Examples:</h5>
5644<pre>
5645%ptr = malloc i32
5646 store i32 4, %ptr
5647
5648%val1 = add i32 4, 4
5649%result1 = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val1 )
5650 <i>; yields {i32}:result1 = 4</i>
5651%stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i>
5652%memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i>
5653
5654%val2 = add i32 1, 1
5655%result2 = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val2 )
5656 <i>; yields {i32}:result2 = 8</i>
5657
5658%stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i>
5659%memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i>
5660</pre>
5661</div>
5662
5663<!-- _______________________________________________________________________ -->
5664<div class="doc_subsubsection">
5665 <a name="int_atomic_las">'<tt>llvm.atomic.las.*</tt>' Intrinsic</a>
5666
5667</div>
5668<div class="doc_text">
5669<h5>Syntax:</h5>
5670<p>
5671 This is an overloaded intrinsic. You can use <tt>llvm.atomic.las</tt> on any
5672 integer bit width. Not all targets support all bit widths however.</p>
5673<pre>
5674declare i8 @llvm.atomic.las.i8.( i8* &lt;ptr&gt;, i8 &lt;delta&gt; )
5675declare i16 @llvm.atomic.las.i16.( i16* &lt;ptr&gt;, i16 &lt;delta&gt; )
5676declare i32 @llvm.atomic.las.i32.( i32* &lt;ptr&gt;, i32 &lt;delta&gt; )
5677declare i64 @llvm.atomic.las.i64.( i64* &lt;ptr&gt;, i64 &lt;delta&gt; )
5678
5679</pre>
5680<h5>Overview:</h5>
5681<p>
5682 This intrinsic adds <tt>delta</tt> to the value stored in memory at
5683 <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>.
5684</p>
5685<h5>Arguments:</h5>
5686<p>
5687
5688 The intrinsic takes two arguments, the first a pointer to an integer value
5689 and the second an integer value. The result is also an integer value. These
5690 integer types can have any bit width, but they must all have the same bit
5691 width. The targets may only lower integer representations they support.
5692</p>
5693<h5>Semantics:</h5>
5694<p>
5695 This intrinsic does a series of operations atomically. It first loads the
5696 value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result
5697 to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>.
5698</p>
5699
5700<h5>Examples:</h5>
5701<pre>
5702%ptr = malloc i32
5703 store i32 4, %ptr
5704%result1 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 4 )
5705 <i>; yields {i32}:result1 = 4</i>
5706%result2 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 2 )
5707 <i>; yields {i32}:result2 = 8</i>
5708%result3 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 5 )
5709 <i>; yields {i32}:result3 = 10</i>
5710%memval = load i32* %ptr <i>; yields {i32}:memval1 = 15</i>
5711</pre>
5712</div>
5713
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +00005714
5715<!-- ======================================================================= -->
5716<div class="doc_subsection">
Tanya Lattner6d806e92007-06-15 20:50:54 +00005717 <a name="int_general">General Intrinsics</a>
5718</div>
5719
5720<div class="doc_text">
5721<p> This class of intrinsics is designed to be generic and has
5722no specific purpose. </p>
5723</div>
5724
5725<!-- _______________________________________________________________________ -->
5726<div class="doc_subsubsection">
5727 <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a>
5728</div>
5729
5730<div class="doc_text">
5731
5732<h5>Syntax:</h5>
5733<pre>
Tanya Lattnerd2e84422007-06-18 23:42:37 +00005734 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 +00005735</pre>
5736
5737<h5>Overview:</h5>
5738
5739<p>
5740The '<tt>llvm.var.annotation</tt>' intrinsic
5741</p>
5742
5743<h5>Arguments:</h5>
5744
5745<p>
Tanya Lattnerd2e84422007-06-18 23:42:37 +00005746The first argument is a pointer to a value, the second is a pointer to a
5747global string, the third is a pointer to a global string which is the source
5748file name, and the last argument is the line number.
Tanya Lattner6d806e92007-06-15 20:50:54 +00005749</p>
5750
5751<h5>Semantics:</h5>
5752
5753<p>
Anton Korobeynikov4cb86182008-01-15 22:31:34 +00005754This intrinsic allows annotation of local variables with arbitrary strings.
Tanya Lattner6d806e92007-06-15 20:50:54 +00005755This can be useful for special purpose optimizations that want to look for these
Anton Korobeynikov4cb86182008-01-15 22:31:34 +00005756annotations. These have no other defined use, they are ignored by code
5757generation and optimization.
5758</p>
Tanya Lattner6d806e92007-06-15 20:50:54 +00005759</div>
5760
Tanya Lattnerb6367882007-09-21 22:59:12 +00005761<!-- _______________________________________________________________________ -->
5762<div class="doc_subsubsection">
Tanya Lattnere1a8da02007-09-21 23:57:59 +00005763 <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a>
Tanya Lattnerb6367882007-09-21 22:59:12 +00005764</div>
5765
5766<div class="doc_text">
5767
5768<h5>Syntax:</h5>
Tanya Lattner39cfba62007-09-21 23:56:27 +00005769<p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on
5770any integer bit width.
5771</p>
Tanya Lattnerb6367882007-09-21 22:59:12 +00005772<pre>
Tanya Lattnerd3989a82007-09-22 00:03:01 +00005773 declare i8 @llvm.annotation.i8(i8 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5774 declare i16 @llvm.annotation.i16(i16 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5775 declare i32 @llvm.annotation.i32(i32 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5776 declare i64 @llvm.annotation.i64(i64 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
5777 declare i256 @llvm.annotation.i256(i256 &lt;val&gt;, i8* &lt;str&gt;, i8* &lt;str&gt;, i32 &lt;int&gt; )
Tanya Lattnerb6367882007-09-21 22:59:12 +00005778</pre>
5779
5780<h5>Overview:</h5>
Tanya Lattner39cfba62007-09-21 23:56:27 +00005781
5782<p>
5783The '<tt>llvm.annotation</tt>' intrinsic.
Tanya Lattnerb6367882007-09-21 22:59:12 +00005784</p>
5785
5786<h5>Arguments:</h5>
5787
5788<p>
5789The first argument is an integer value (result of some expression),
5790the second is a pointer to a global string, the third is a pointer to a global
5791string which is the source file name, and the last argument is the line number.
Tanya Lattner39cfba62007-09-21 23:56:27 +00005792It returns the value of the first argument.
Tanya Lattnerb6367882007-09-21 22:59:12 +00005793</p>
5794
5795<h5>Semantics:</h5>
5796
5797<p>
5798This intrinsic allows annotations to be put on arbitrary expressions
5799with arbitrary strings. This can be useful for special purpose optimizations
5800that want to look for these annotations. These have no other defined use, they
5801are ignored by code generation and optimization.
5802</div>
Jim Laskeydd4ef1b2007-03-14 19:31:19 +00005803
Anton Korobeynikov4cb86182008-01-15 22:31:34 +00005804<!-- _______________________________________________________________________ -->
5805<div class="doc_subsubsection">
5806 <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a>
5807</div>
5808
5809<div class="doc_text">
5810
5811<h5>Syntax:</h5>
5812<pre>
5813 declare void @llvm.trap()
5814</pre>
5815
5816<h5>Overview:</h5>
5817
5818<p>
5819The '<tt>llvm.trap</tt>' intrinsic
5820</p>
5821
5822<h5>Arguments:</h5>
5823
5824<p>
5825None
5826</p>
5827
5828<h5>Semantics:</h5>
5829
5830<p>
5831This intrinsics is lowered to the target dependent trap instruction. If the
5832target does not have a trap instruction, this intrinsic will be lowered to the
5833call of the abort() function.
5834</p>
5835</div>
5836
Chris Lattner00950542001-06-06 20:29:01 +00005837<!-- *********************************************************************** -->
Chris Lattner00950542001-06-06 20:29:01 +00005838<hr>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00005839<address>
5840 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
5841 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
5842 <a href="http://validator.w3.org/check/referer"><img
Chris Lattnerc7d3ab32008-01-04 04:33:49 +00005843 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00005844
5845 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencer05fe4b02006-03-14 05:39:39 +00005846 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmandaa4cb02004-03-01 17:47:27 +00005847 Last modified: $Date$
5848</address>
Chris Lattnerc7d3ab32008-01-04 04:33:49 +00005849
Misha Brukman9d0919f2003-11-08 01:05:38 +00005850</body>
5851</html>