blob: adf6e7f085fcf3d30d9d966f17cd1688fc8b9b3a [file] [log] [blame]
Misha Brukmanc501f552004-03-01 17:47:27 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
Misha Brukman76307852003-11-08 01:05:38 +00003<html>
4<head>
5 <title>LLVM Assembly Language Reference Manual</title>
Reid Spencercb84e432004-08-26 20:44:00 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="author" content="Chris Lattner">
8 <meta name="description"
9 content="LLVM Assembly Language Reference Manual.">
Misha Brukman76307852003-11-08 01:05:38 +000010 <link rel="stylesheet" href="llvm.css" type="text/css">
11</head>
Chris Lattner757528b0b2004-05-23 21:06:01 +000012
Misha Brukman76307852003-11-08 01:05:38 +000013<body>
Chris Lattner757528b0b2004-05-23 21:06:01 +000014
Chris Lattner48b383b02003-11-25 01:02:51 +000015<div class="doc_title"> LLVM Language Reference Manual </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +000016<ol>
Misha Brukman76307852003-11-08 01:05:38 +000017 <li><a href="#abstract">Abstract</a></li>
18 <li><a href="#introduction">Introduction</a></li>
19 <li><a href="#identifiers">Identifiers</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000020 <li><a href="#highlevel">High Level Structure</a>
21 <ol>
22 <li><a href="#modulestructure">Module Structure</a></li>
Chris Lattnerd79749a2004-12-09 16:36:40 +000023 <li><a href="#linkage">Linkage Types</a></li>
Chris Lattner0132aff2005-05-06 22:57:40 +000024 <li><a href="#callingconv">Calling Conventions</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000025 <li><a href="#globalvars">Global Variables</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000026 <li><a href="#functionstructure">Functions</a></li>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +000027 <li><a href="#paramattrs">Parameter Attributes</a></li>
Chris Lattner91c15c42006-01-23 23:23:47 +000028 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000029 </ol>
30 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000031 <li><a href="#typesystem">Type System</a>
32 <ol>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000033 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000034 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000035 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000036 </ol>
37 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000038 <li><a href="#t_derived">Derived Types</a>
39 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000040 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000041 <li><a href="#t_function">Function Type</a></li>
42 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000043 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth8df88e22006-12-08 17:13:00 +000044 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Reid Spencer404a3252007-02-15 03:07:05 +000045 <li><a href="#t_vector">Vector Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000046 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000047 </ol>
48 </li>
49 </ol>
50 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000051 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000052 <ol>
53 <li><a href="#simpleconstants">Simple Constants</a>
54 <li><a href="#aggregateconstants">Aggregate Constants</a>
55 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
56 <li><a href="#undefvalues">Undefined Values</a>
57 <li><a href="#constantexprs">Constant Expressions</a>
58 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000059 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000060 <li><a href="#othervalues">Other Values</a>
61 <ol>
62 <li><a href="#inlineasm">Inline Assembler Expressions</a>
63 </ol>
64 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000065 <li><a href="#instref">Instruction Reference</a>
66 <ol>
67 <li><a href="#terminators">Terminator Instructions</a>
68 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000069 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
70 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000071 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
72 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000073 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000074 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000075 </ol>
76 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000077 <li><a href="#binaryops">Binary Operations</a>
78 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000079 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
80 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
81 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +000082 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
83 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
84 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +000085 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
86 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
87 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000088 </ol>
89 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000090 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
91 <ol>
Reid Spencer2ab01932007-02-02 13:57:07 +000092 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
93 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
94 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000095 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000096 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000097 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000098 </ol>
99 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000100 <li><a href="#vectorops">Vector Operations</a>
101 <ol>
102 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
103 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
104 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000105 </ol>
106 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000107 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000108 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000109 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
110 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
111 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000112 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
113 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
114 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000115 </ol>
116 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000117 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000118 <ol>
119 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
120 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
121 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
122 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
123 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000124 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
125 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
126 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
127 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000128 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
129 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000130 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000131 </ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000132 <li><a href="#otherops">Other Operations</a>
133 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000134 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
135 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000136 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000137 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000138 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000139 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000140 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000141 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000142 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000143 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000144 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000145 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000146 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
147 <ol>
148 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
149 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
150 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
151 </ol>
152 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000153 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
154 <ol>
155 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
156 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
157 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
158 </ol>
159 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000160 <li><a href="#int_codegen">Code Generator Intrinsics</a>
161 <ol>
162 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
163 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner2f0f0012006-01-13 02:03:13 +0000164 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
165 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattnerc8a2c222005-02-28 19:24:19 +0000166 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharthb4427912005-03-28 20:05:49 +0000167 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth01aa5632005-11-11 16:47:30 +0000168 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000169 </ol>
170 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000171 <li><a href="#int_libc">Standard C Library Intrinsics</a>
172 <ol>
Chris Lattner0c8b2592006-03-03 00:07:20 +0000173 <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
174 <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
175 <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
Chris Lattner069b5bd2006-01-16 22:38:59 +0000176 <li><a href="#i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li>
Chris Lattner33b73f92006-09-08 06:34:02 +0000177 <li><a href="#i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000178 </ol>
179 </li>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000180 <li><a href="#int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000181 <ol>
Nate Begeman0f223bb2006-01-13 23:26:38 +0000182 <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li>
Chris Lattnerb748c672006-01-16 22:34:14 +0000183 <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li>
184 <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li>
185 <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li>
Andrew Lenharth1d463522005-05-03 18:01:48 +0000186 </ol>
187 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000188 <li><a href="#int_debugger">Debugger intrinsics</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000189 </ol>
190 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000191</ol>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000192
193<div class="doc_author">
194 <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a>
195 and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p>
Misha Brukman76307852003-11-08 01:05:38 +0000196</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000197
Chris Lattner2f7c9632001-06-06 20:29:01 +0000198<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000199<div class="doc_section"> <a name="abstract">Abstract </a></div>
200<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000201
Misha Brukman76307852003-11-08 01:05:38 +0000202<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000203<p>This document is a reference manual for the LLVM assembly language.
204LLVM is an SSA based representation that provides type safety,
205low-level operations, flexibility, and the capability of representing
206'all' high-level languages cleanly. It is the common code
207representation used throughout all phases of the LLVM compilation
208strategy.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000209</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000210
Chris Lattner2f7c9632001-06-06 20:29:01 +0000211<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000212<div class="doc_section"> <a name="introduction">Introduction</a> </div>
213<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000214
Misha Brukman76307852003-11-08 01:05:38 +0000215<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000216
Chris Lattner48b383b02003-11-25 01:02:51 +0000217<p>The LLVM code representation is designed to be used in three
218different forms: as an in-memory compiler IR, as an on-disk bytecode
219representation (suitable for fast loading by a Just-In-Time compiler),
220and as a human readable assembly language representation. This allows
221LLVM to provide a powerful intermediate representation for efficient
222compiler transformations and analysis, while providing a natural means
223to debug and visualize the transformations. The three different forms
224of LLVM are all equivalent. This document describes the human readable
225representation and notation.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000226
John Criswell4a3327e2005-05-13 22:25:59 +0000227<p>The LLVM representation aims to be light-weight and low-level
Chris Lattner48b383b02003-11-25 01:02:51 +0000228while being expressive, typed, and extensible at the same time. It
229aims to be a "universal IR" of sorts, by being at a low enough level
230that high-level ideas may be cleanly mapped to it (similar to how
231microprocessors are "universal IR's", allowing many source languages to
232be mapped to them). By providing type information, LLVM can be used as
233the target of optimizations: for example, through pointer analysis, it
234can be proven that a C automatic variable is never accessed outside of
235the current function... allowing it to be promoted to a simple SSA
236value instead of a memory location.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000237
Misha Brukman76307852003-11-08 01:05:38 +0000238</div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000239
Chris Lattner2f7c9632001-06-06 20:29:01 +0000240<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000241<div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000242
Misha Brukman76307852003-11-08 01:05:38 +0000243<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000244
Chris Lattner48b383b02003-11-25 01:02:51 +0000245<p>It is important to note that this document describes 'well formed'
246LLVM assembly language. There is a difference between what the parser
247accepts and what is considered 'well formed'. For example, the
248following instruction is syntactically okay, but not well formed:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000249
250<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000251 %x = <a href="#i_add">add</a> i32 1, %x
Chris Lattner757528b0b2004-05-23 21:06:01 +0000252</pre>
253
Chris Lattner48b383b02003-11-25 01:02:51 +0000254<p>...because the definition of <tt>%x</tt> does not dominate all of
255its uses. The LLVM infrastructure provides a verification pass that may
256be used to verify that an LLVM module is well formed. This pass is
John Criswell4a3327e2005-05-13 22:25:59 +0000257automatically run by the parser after parsing input assembly and by
Chris Lattner48b383b02003-11-25 01:02:51 +0000258the optimizer before it outputs bytecode. The violations pointed out
259by the verifier pass indicate bugs in transformation passes or input to
260the parser.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000261
Chris Lattner48b383b02003-11-25 01:02:51 +0000262<!-- Describe the typesetting conventions here. --> </div>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000263
Chris Lattner2f7c9632001-06-06 20:29:01 +0000264<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000265<div class="doc_section"> <a name="identifiers">Identifiers</a> </div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000266<!-- *********************************************************************** -->
Chris Lattner757528b0b2004-05-23 21:06:01 +0000267
Misha Brukman76307852003-11-08 01:05:38 +0000268<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +0000269
Chris Lattner48b383b02003-11-25 01:02:51 +0000270<p>LLVM uses three different forms of identifiers, for different
271purposes:</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000272
Chris Lattner2f7c9632001-06-06 20:29:01 +0000273<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000274 <li>Named values are represented as a string of characters with a '%' prefix.
275 For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual
276 regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'.
277 Identifiers which require other characters in their names can be surrounded
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000278 with quotes. In this way, anything except a <tt>&quot;</tt> character can be used
Chris Lattnerd79749a2004-12-09 16:36:40 +0000279 in a name.</li>
280
281 <li>Unnamed values are represented as an unsigned numeric value with a '%'
282 prefix. For example, %12, %2, %44.</li>
283
Reid Spencer8f08d802004-12-09 18:02:53 +0000284 <li>Constants, which are described in a <a href="#constants">section about
285 constants</a>, below.</li>
Misha Brukman76307852003-11-08 01:05:38 +0000286</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000287
288<p>LLVM requires that values start with a '%' sign for two reasons: Compilers
289don't need to worry about name clashes with reserved words, and the set of
290reserved words may be expanded in the future without penalty. Additionally,
291unnamed identifiers allow a compiler to quickly come up with a temporary
292variable without having to avoid symbol table conflicts.</p>
293
Chris Lattner48b383b02003-11-25 01:02:51 +0000294<p>Reserved words in LLVM are very similar to reserved words in other
Reid Spencer5b950642006-11-11 23:08:07 +0000295languages. There are keywords for different opcodes
296('<tt><a href="#i_add">add</a></tt>',
297 '<tt><a href="#i_bitcast">bitcast</a></tt>',
298 '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000299href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...),
Chris Lattnerd79749a2004-12-09 16:36:40 +0000300and others. These reserved words cannot conflict with variable names, because
301none of them start with a '%' character.</p>
302
303<p>Here is an example of LLVM code to multiply the integer variable
304'<tt>%X</tt>' by 8:</p>
305
Misha Brukman76307852003-11-08 01:05:38 +0000306<p>The easy way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000307
308<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000309 %result = <a href="#i_mul">mul</a> i32 %X, 8
Chris Lattnerd79749a2004-12-09 16:36:40 +0000310</pre>
311
Misha Brukman76307852003-11-08 01:05:38 +0000312<p>After strength reduction:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000313
314<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000315 %result = <a href="#i_shl">shl</a> i32 %X, i8 3
Chris Lattnerd79749a2004-12-09 16:36:40 +0000316</pre>
317
Misha Brukman76307852003-11-08 01:05:38 +0000318<p>And the hard way:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000319
320<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000321 <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i>
322 <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i>
323 %result = <a href="#i_add">add</a> i32 %1, %1
Chris Lattnerd79749a2004-12-09 16:36:40 +0000324</pre>
325
Chris Lattner48b383b02003-11-25 01:02:51 +0000326<p>This last way of multiplying <tt>%X</tt> by 8 illustrates several
327important lexical features of LLVM:</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000328
Chris Lattner2f7c9632001-06-06 20:29:01 +0000329<ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000330
331 <li>Comments are delimited with a '<tt>;</tt>' and go until the end of
332 line.</li>
333
334 <li>Unnamed temporaries are created when the result of a computation is not
335 assigned to a named value.</li>
336
Misha Brukman76307852003-11-08 01:05:38 +0000337 <li>Unnamed temporaries are numbered sequentially</li>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000338
Misha Brukman76307852003-11-08 01:05:38 +0000339</ol>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000340
John Criswell02fdc6f2005-05-12 16:52:32 +0000341<p>...and it also shows a convention that we follow in this document. When
Chris Lattnerd79749a2004-12-09 16:36:40 +0000342demonstrating instructions, we will follow an instruction with a comment that
343defines the type and name of value produced. Comments are shown in italic
344text.</p>
345
Misha Brukman76307852003-11-08 01:05:38 +0000346</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000347
348<!-- *********************************************************************** -->
349<div class="doc_section"> <a name="highlevel">High Level Structure</a> </div>
350<!-- *********************************************************************** -->
351
352<!-- ======================================================================= -->
353<div class="doc_subsection"> <a name="modulestructure">Module Structure</a>
354</div>
355
356<div class="doc_text">
357
358<p>LLVM programs are composed of "Module"s, each of which is a
359translation unit of the input programs. Each module consists of
360functions, global variables, and symbol table entries. Modules may be
361combined together with the LLVM linker, which merges function (and
362global variable) definitions, resolves forward declarations, and merges
363symbol table entries. Here is an example of the "hello world" module:</p>
364
365<pre><i>; Declare the string constant as a global constant...</i>
366<a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000367 href="#globalvars">constant</a> <a href="#t_array">[13 x i8 ]</a> c"hello world\0A\00" <i>; [13 x i8 ]*</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000368
369<i>; External declaration of the puts function</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000370<a href="#functionstructure">declare</a> i32 %puts(i8 *) <i>; i32(i8 *)* </i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000371
Chris Lattnerd2d29a02006-06-13 03:05:47 +0000372<i>; Global variable / Function body section separator</i>
373implementation
374
Chris Lattner6af02f32004-12-09 16:11:40 +0000375<i>; Definition of main function</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000376define i32 %main() { <i>; i32()* </i>
377 <i>; Convert [13x i8 ]* to i8 *...</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000378 %cast210 = <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000379 href="#i_getelementptr">getelementptr</a> [13 x i8 ]* %.LC0, i64 0, i64 0 <i>; i8 *</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000380
381 <i>; Call puts function to write out the string to stdout...</i>
382 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000383 href="#i_call">call</a> i32 %puts(i8 * %cast210) <i>; i32</i>
Chris Lattner6af02f32004-12-09 16:11:40 +0000384 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000385 href="#i_ret">ret</a> i32 0<br>}<br></pre>
Chris Lattner6af02f32004-12-09 16:11:40 +0000386
387<p>This example is made up of a <a href="#globalvars">global variable</a>
388named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>"
389function, and a <a href="#functionstructure">function definition</a>
390for "<tt>main</tt>".</p>
391
Chris Lattnerd79749a2004-12-09 16:36:40 +0000392<p>In general, a module is made up of a list of global values,
393where both functions and global variables are global values. Global values are
394represented by a pointer to a memory location (in this case, a pointer to an
395array of char, and a pointer to a function), and have one of the following <a
396href="#linkage">linkage types</a>.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000397
Chris Lattnerd2d29a02006-06-13 03:05:47 +0000398<p>Due to a limitation in the current LLVM assembly parser (it is limited by
399one-token lookahead), modules are split into two pieces by the "implementation"
400keyword. Global variable prototypes and definitions must occur before the
401keyword, and function definitions must occur after it. Function prototypes may
402occur either before or after it. In the future, the implementation keyword may
403become a noop, if the parser gets smarter.</p>
404
Chris Lattnerd79749a2004-12-09 16:36:40 +0000405</div>
406
407<!-- ======================================================================= -->
408<div class="doc_subsection">
409 <a name="linkage">Linkage Types</a>
410</div>
411
412<div class="doc_text">
413
414<p>
415All Global Variables and Functions have one of the following types of linkage:
416</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000417
418<dl>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000419
Chris Lattner6af02f32004-12-09 16:11:40 +0000420 <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000421
422 <dd>Global values with internal linkage are only directly accessible by
423 objects in the current module. In particular, linking code into a module with
424 an internal global value may cause the internal to be renamed as necessary to
425 avoid collisions. Because the symbol is internal to the module, all
426 references can be updated. This corresponds to the notion of the
Chris Lattnere20b4702007-01-14 06:51:48 +0000427 '<tt>static</tt>' keyword in C.
Chris Lattner6af02f32004-12-09 16:11:40 +0000428 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000429
Chris Lattner6af02f32004-12-09 16:11:40 +0000430 <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000431
Chris Lattnere20b4702007-01-14 06:51:48 +0000432 <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of
433 the same name when linkage occurs. This is typically used to implement
434 inline functions, templates, or other code which must be generated in each
435 translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are
436 allowed to be discarded.
Chris Lattner6af02f32004-12-09 16:11:40 +0000437 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000438
Chris Lattner6af02f32004-12-09 16:11:40 +0000439 <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000440
441 <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage,
442 except that unreferenced <tt>weak</tt> globals may not be discarded. This is
Chris Lattnere20b4702007-01-14 06:51:48 +0000443 used for globals that may be emitted in multiple translation units, but that
444 are not guaranteed to be emitted into every translation unit that uses them.
445 One example of this are common globals in C, such as "<tt>int X;</tt>" at
446 global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000447 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000448
Chris Lattner6af02f32004-12-09 16:11:40 +0000449 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000450
451 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
452 pointer to array type. When two global variables with appending linkage are
453 linked together, the two global arrays are appended together. This is the
454 LLVM, typesafe, equivalent of having the system linker append together
455 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000456 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000457
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000458 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
459 <dd>The semantics of this linkage follow the ELF model: the symbol is weak
460 until linked, if not linked, the symbol becomes null instead of being an
461 undefined reference.
462 </dd>
463</dl>
464
Chris Lattner6af02f32004-12-09 16:11:40 +0000465 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000466
467 <dd>If none of the above identifiers are used, the global is externally
468 visible, meaning that it participates in linkage and can be used to resolve
469 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000470 </dd>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000471
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000472 <p>
473 The next two types of linkage are targeted for Microsoft Windows platform
474 only. They are designed to support importing (exporting) symbols from (to)
475 DLLs.
476 </p>
477
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000478 <dl>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000479 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
480
481 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
482 or variable via a global pointer to a pointer that is set up by the DLL
483 exporting the symbol. On Microsoft Windows targets, the pointer name is
484 formed by combining <code>_imp__</code> and the function or variable name.
485 </dd>
486
487 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
488
489 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
490 pointer to a pointer in a DLL, so that it can be referenced with the
491 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
492 name is formed by combining <code>_imp__</code> and the function or variable
493 name.
494 </dd>
495
Chris Lattner6af02f32004-12-09 16:11:40 +0000496</dl>
497
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000498<p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>"
Chris Lattner6af02f32004-12-09 16:11:40 +0000499variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
500variable and was linked with this one, one of the two would be renamed,
501preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
502external (i.e., lacking any linkage declarations), they are accessible
Reid Spencer92c671e2007-01-05 00:59:10 +0000503outside of the current module.</p>
504<p>It is illegal for a function <i>declaration</i>
505to have any linkage type other than "externally visible", <tt>dllimport</tt>,
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000506or <tt>extern_weak</tt>.</p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000507
Chris Lattner6af02f32004-12-09 16:11:40 +0000508</div>
509
510<!-- ======================================================================= -->
511<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000512 <a name="callingconv">Calling Conventions</a>
513</div>
514
515<div class="doc_text">
516
517<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
518and <a href="#i_invoke">invokes</a> can all have an optional calling convention
519specified for the call. The calling convention of any pair of dynamic
520caller/callee must match, or the behavior of the program is undefined. The
521following calling conventions are supported by LLVM, and more may be added in
522the future:</p>
523
524<dl>
525 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
526
527 <dd>This calling convention (the default if no other calling convention is
528 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000529 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencer72ba4992006-12-31 21:30:18 +0000530 prototype and implemented declaration of the function (as does normal C).
Chris Lattner0132aff2005-05-06 22:57:40 +0000531 </dd>
532
533 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
534
535 <dd>This calling convention attempts to make calls as fast as possible
536 (e.g. by passing things in registers). This calling convention allows the
537 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000538 without having to conform to an externally specified ABI. Implementations of
539 this convention should allow arbitrary tail call optimization to be supported.
540 This calling convention does not support varargs and requires the prototype of
541 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000542 </dd>
543
544 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
545
546 <dd>This calling convention attempts to make code in the caller as efficient
547 as possible under the assumption that the call is not commonly executed. As
548 such, these calls often preserve all registers so that the call does not break
549 any live ranges in the caller side. This calling convention does not support
550 varargs and requires the prototype of all callees to exactly match the
551 prototype of the function definition.
552 </dd>
553
Chris Lattner573f64e2005-05-07 01:46:40 +0000554 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000555
556 <dd>Any calling convention may be specified by number, allowing
557 target-specific calling conventions to be used. Target specific calling
558 conventions start at 64.
559 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000560</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000561
562<p>More calling conventions can be added/defined on an as-needed basis, to
563support pascal conventions or any other well-known target-independent
564convention.</p>
565
566</div>
567
568<!-- ======================================================================= -->
569<div class="doc_subsection">
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000570 <a name="visibility">Visibility Styles</a>
571</div>
572
573<div class="doc_text">
574
575<p>
576All Global Variables and Functions have one of the following visibility styles:
577</p>
578
579<dl>
580 <dt><b>"<tt>default</tt>" - Default style</b>:</dt>
581
582 <dd>On ELF, default visibility means that the declaration is visible to other
583 modules and, in shared libraries, means that the declared entity may be
584 overridden. On Darwin, default visibility means that the declaration is
585 visible to other modules. Default visibility corresponds to "external
586 linkage" in the language.
587 </dd>
588
589 <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt>
590
591 <dd>Two declarations of an object with hidden visibility refer to the same
592 object if they are in the same shared object. Usually, hidden visibility
593 indicates that the symbol will not be placed into the dynamic symbol table,
594 so no other module (executable or shared library) can reference it
595 directly.
596 </dd>
597
598</dl>
599
600</div>
601
602<!-- ======================================================================= -->
603<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000604 <a name="globalvars">Global Variables</a>
605</div>
606
607<div class="doc_text">
608
Chris Lattner5d5aede2005-02-12 19:30:21 +0000609<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000610instead of run-time. Global variables may optionally be initialized, may have
611an explicit section to be placed in, and may
Chris Lattner54611b42005-11-06 08:02:57 +0000612have an optional explicit alignment specified. A
John Criswell4c0cf7f2005-10-24 16:17:18 +0000613variable may be defined as a global "constant," which indicates that the
Chris Lattner5d5aede2005-02-12 19:30:21 +0000614contents of the variable will <b>never</b> be modified (enabling better
615optimization, allowing the global data to be placed in the read-only section of
616an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000617cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000618
619<p>
620LLVM explicitly allows <em>declarations</em> of global variables to be marked
621constant, even if the final definition of the global is not. This capability
622can be used to enable slightly better optimization of the program, but requires
623the language definition to guarantee that optimizations based on the
624'constantness' are valid for the translation units that do not include the
625definition.
626</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000627
628<p>As SSA values, global variables define pointer values that are in
629scope (i.e. they dominate) all basic blocks in the program. Global
630variables always define a pointer to their "content" type because they
631describe a region of memory, and all memory objects in LLVM are
632accessed through pointers.</p>
633
Chris Lattner662c8722005-11-12 00:45:07 +0000634<p>LLVM allows an explicit section to be specified for globals. If the target
635supports it, it will emit globals to the section specified.</p>
636
Chris Lattner54611b42005-11-06 08:02:57 +0000637<p>An explicit alignment may be specified for a global. If not present, or if
638the alignment is set to zero, the alignment of the global is set by the target
639to whatever it feels convenient. If an explicit alignment is specified, the
640global is forced to have at least that much alignment. All alignments must be
641a power of 2.</p>
642
Chris Lattner5760c502007-01-14 00:27:09 +0000643<p>For example, the following defines a global with an initializer, section,
644 and alignment:</p>
645
646<pre>
647 %G = constant float 1.0, section "foo", align 4
648</pre>
649
Chris Lattner6af02f32004-12-09 16:11:40 +0000650</div>
651
652
653<!-- ======================================================================= -->
654<div class="doc_subsection">
655 <a name="functionstructure">Functions</a>
656</div>
657
658<div class="doc_text">
659
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000660<p>LLVM function definitions consist of the "<tt>define</tt>" keyord,
661an optional <a href="#linkage">linkage type</a>, an optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000662<a href="#visibility">visibility style</a>, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000663<a href="#callingconv">calling convention</a>, a return type, an optional
664<a href="#paramattrs">parameter attribute</a> for the return type, a function
665name, a (possibly empty) argument list (each with optional
Anton Korobeynikovc7f9f3d2007-01-23 12:35:46 +0000666<a href="#paramattrs">parameter attributes</a>), an optional section, an
667optional alignment, an opening curly brace, a list of basic blocks, and a
668closing curly brace.
669
670LLVM function declarations consist of the "<tt>declare</tt>" keyword, an
671optional <a href="#linkage">linkage type</a>, an optional
672<a href="#visibility">visibility style</a>, an optional
673<a href="#callingconv">calling convention</a>, a return type, an optional
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000674<a href="#paramattrs">parameter attribute</a> for the return type, a function
675name, a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000676
677<p>A function definition contains a list of basic blocks, forming the CFG for
678the function. Each basic block may optionally start with a label (giving the
679basic block a symbol table entry), contains a list of instructions, and ends
680with a <a href="#terminators">terminator</a> instruction (such as a branch or
681function return).</p>
682
John Criswell02fdc6f2005-05-12 16:52:32 +0000683<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000684executed on entrance to the function, and it is not allowed to have predecessor
685basic blocks (i.e. there can not be any branches to the entry block of a
686function). Because the block can have no predecessors, it also cannot have any
687<a href="#i_phi">PHI nodes</a>.</p>
688
689<p>LLVM functions are identified by their name and type signature. Hence, two
690functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000691considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000692appropriately.</p>
693
Chris Lattner662c8722005-11-12 00:45:07 +0000694<p>LLVM allows an explicit section to be specified for functions. If the target
695supports it, it will emit functions to the section specified.</p>
696
Chris Lattner54611b42005-11-06 08:02:57 +0000697<p>An explicit alignment may be specified for a function. If not present, or if
698the alignment is set to zero, the alignment of the function is set by the target
699to whatever it feels convenient. If an explicit alignment is specified, the
700function is forced to have at least that much alignment. All alignments must be
701a power of 2.</p>
702
Chris Lattner6af02f32004-12-09 16:11:40 +0000703</div>
704
Chris Lattner91c15c42006-01-23 23:23:47 +0000705<!-- ======================================================================= -->
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000706<div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div>
707<div class="doc_text">
708 <p>The return type and each parameter of a function type may have a set of
709 <i>parameter attributes</i> associated with them. Parameter attributes are
710 used to communicate additional information about the result or parameters of
711 a function. Parameter attributes are considered to be part of the function
712 type so two functions types that differ only by the parameter attributes
713 are different function types.</p>
714
Reid Spencercf7ebf52007-01-15 18:27:39 +0000715 <p>Parameter attributes are simple keywords that follow the type specified. If
716 multiple parameter attributes are needed, they are space separated. For
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000717 example:</p><pre>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000718 %someFunc = i16 (i8 sext %someParam) zext
719 %someFunc = i16 (i8 zext %someParam) zext</pre>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000720 <p>Note that the two function types above are unique because the parameter has
Reid Spencercf7ebf52007-01-15 18:27:39 +0000721 a different attribute (sext in the first one, zext in the second). Also note
722 that the attribute for the function result (zext) comes immediately after the
723 argument list.</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000724
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000725 <p>Currently, only the following parameter attributes are defined:</p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000726 <dl>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000727 <dt><tt>zext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000728 <dd>This indicates that the parameter should be zero extended just before
729 a call to this function.</dd>
Reid Spencercf7ebf52007-01-15 18:27:39 +0000730 <dt><tt>sext</tt></dt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000731 <dd>This indicates that the parameter should be sign extended just before
732 a call to this function.</dd>
Anton Korobeynikove8166852007-01-28 14:30:45 +0000733 <dt><tt>inreg</tt></dt>
734 <dd>This indicates that the parameter should be placed in register (if
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000735 possible) during assembling function call. Support for this attribute is
736 target-specific</dd>
Anton Korobeynikove8166852007-01-28 14:30:45 +0000737 <dt><tt>sret</tt></dt>
Anton Korobeynikove93c6e82007-01-28 15:27:21 +0000738 <dd>This indicates that the parameter specifies the address of a structure
739 that is the return value of the function in the source program.
740 </dd>
Anton Korobeynikova0554d92007-01-12 19:20:47 +0000741 </dl>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000742
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000743</div>
744
745<!-- ======================================================================= -->
Chris Lattner91c15c42006-01-23 23:23:47 +0000746<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +0000747 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +0000748</div>
749
750<div class="doc_text">
751<p>
752Modules may contain "module-level inline asm" blocks, which corresponds to the
753GCC "file scope inline asm" blocks. These blocks are internally concatenated by
754LLVM and treated as a single unit, but may be separated in the .ll file if
755desired. The syntax is very simple:
756</p>
757
758<div class="doc_code"><pre>
Chris Lattnera1280ad2006-01-24 00:37:20 +0000759 module asm "inline asm code goes here"
760 module asm "more can go here"
Chris Lattner91c15c42006-01-23 23:23:47 +0000761</pre></div>
762
763<p>The strings can contain any character by escaping non-printable characters.
764 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
765 for the number.
766</p>
767
768<p>
769 The inline asm code is simply printed to the machine code .s file when
770 assembly code is generated.
771</p>
772</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000773
774
Chris Lattner2f7c9632001-06-06 20:29:01 +0000775<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000776<div class="doc_section"> <a name="typesystem">Type System</a> </div>
777<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000778
Misha Brukman76307852003-11-08 01:05:38 +0000779<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000780
Misha Brukman76307852003-11-08 01:05:38 +0000781<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000782intermediate representation. Being typed enables a number of
783optimizations to be performed on the IR directly, without having to do
784extra analyses on the side before the transformation. A strong type
785system makes it easier to read the generated code and enables novel
786analyses and transformations that are not feasible to perform on normal
787three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000788
789</div>
790
Chris Lattner2f7c9632001-06-06 20:29:01 +0000791<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000792<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000793<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000794<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000795system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000796
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000797<table class="layout">
798 <tr class="layout">
799 <td class="left">
800 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000801 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000802 <tr><th>Type</th><th>Description</th></tr>
803 <tr><td><tt>void</tt></td><td>No value</td></tr>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000804 <tr><td><tt>i8</tt></td><td>8-bit value</td></tr>
805 <tr><td><tt>i32</tt></td><td>32-bit value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000806 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000807 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000808 </tbody>
809 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000810 </td>
811 <td class="right">
812 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000813 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000814 <tr><th>Type</th><th>Description</th></tr>
Reid Spencer36a15422007-01-12 03:35:51 +0000815 <tr><td><tt>i1</tt></td><td>True or False value</td></tr>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000816 <tr><td><tt>i16</tt></td><td>16-bit value</td></tr>
817 <tr><td><tt>i64</tt></td><td>64-bit value</td></tr>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000818 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000819 </tbody>
820 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000821 </td>
822 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000823</table>
Misha Brukman76307852003-11-08 01:05:38 +0000824</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000825
Chris Lattner2f7c9632001-06-06 20:29:01 +0000826<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000827<div class="doc_subsubsection"> <a name="t_classifications">Type
828Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000829<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000830<p>These different primitive types fall into a few useful
831classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000832
833<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000834 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000835 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000836 <tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000837 <td><a name="t_integer">integer</a></td>
Chris Lattnerc0f423a2007-01-15 01:54:13 +0000838 <td><tt>i1, i8, i16, i32, i64</tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000839 </tr>
840 <tr>
841 <td><a name="t_floating">floating point</a></td>
842 <td><tt>float, double</tt></td>
843 </tr>
844 <tr>
845 <td><a name="t_firstclass">first class</a></td>
Reid Spencer36a15422007-01-12 03:35:51 +0000846 <td><tt>i1, i8, i16, i32, i64, float, double, <br/>
Reid Spencer404a3252007-02-15 03:07:05 +0000847 <a href="#t_pointer">pointer</a>,<a href="#t_vector">vector</a></tt>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000848 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000849 </tr>
850 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000851</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000852
Chris Lattner48b383b02003-11-25 01:02:51 +0000853<p>The <a href="#t_firstclass">first class</a> types are perhaps the
854most important. Values of these types are the only ones which can be
855produced by instructions, passed as arguments, or used as operands to
856instructions. This means that all structures and arrays must be
857manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000858</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000859
Chris Lattner2f7c9632001-06-06 20:29:01 +0000860<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000861<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000862
Misha Brukman76307852003-11-08 01:05:38 +0000863<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000864
Chris Lattner48b383b02003-11-25 01:02:51 +0000865<p>The real power in LLVM comes from the derived types in the system.
866This is what allows a programmer to represent arrays, functions,
867pointers, and other useful types. Note that these derived types may be
868recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000869
Misha Brukman76307852003-11-08 01:05:38 +0000870</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000871
Chris Lattner2f7c9632001-06-06 20:29:01 +0000872<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000873<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000874
Misha Brukman76307852003-11-08 01:05:38 +0000875<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000876
Chris Lattner2f7c9632001-06-06 20:29:01 +0000877<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000878
Misha Brukman76307852003-11-08 01:05:38 +0000879<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000880sequentially in memory. The array type requires a size (number of
881elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000882
Chris Lattner590645f2002-04-14 06:13:44 +0000883<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000884
885<pre>
886 [&lt;# elements&gt; x &lt;elementtype&gt;]
887</pre>
888
John Criswell02fdc6f2005-05-12 16:52:32 +0000889<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000890be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000891
Chris Lattner590645f2002-04-14 06:13:44 +0000892<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000893<table class="layout">
894 <tr class="layout">
895 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000896 <tt>[40 x i32 ]</tt><br/>
897 <tt>[41 x i32 ]</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +0000898 <tt>[40 x i8]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000899 </td>
900 <td class="left">
Reid Spencer3e628eb92007-01-04 16:43:23 +0000901 Array of 40 32-bit integer values.<br/>
902 Array of 41 32-bit integer values.<br/>
903 Array of 40 8-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000904 </td>
905 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000906</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000907<p>Here are some examples of multidimensional arrays:</p>
908<table class="layout">
909 <tr class="layout">
910 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000911 <tt>[3 x [4 x i32]]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000912 <tt>[12 x [10 x float]]</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +0000913 <tt>[2 x [3 x [4 x i16]]]</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000914 </td>
915 <td class="left">
Reid Spencer3e628eb92007-01-04 16:43:23 +0000916 3x4 array of 32-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000917 12x10 array of single precision floating point values.<br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +0000918 2x3x4 array of 16-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000919 </td>
920 </tr>
921</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000922
John Criswell4c0cf7f2005-10-24 16:17:18 +0000923<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
924length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000925LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
926As a special case, however, zero length arrays are recognized to be variable
927length. This allows implementation of 'pascal style arrays' with the LLVM
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000928type "{ i32, [0 x float]}", for example.</p>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000929
Misha Brukman76307852003-11-08 01:05:38 +0000930</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000931
Chris Lattner2f7c9632001-06-06 20:29:01 +0000932<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000933<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000934<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000935<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000936<p>The function type can be thought of as a function signature. It
937consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000938Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000939(which are structures of pointers to functions), for indirect function
940calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000941<p>
942The return type of a function type cannot be an aggregate type.
943</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000944<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000945<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +0000946<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +0000947specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000948which indicates that the function takes a variable number of arguments.
949Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000950 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000951<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000952<table class="layout">
953 <tr class="layout">
Reid Spencer58c08712006-12-31 07:18:34 +0000954 <td class="left"><tt>i32 (i32)</tt></td>
955 <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000956 </td>
Reid Spencer58c08712006-12-31 07:18:34 +0000957 </tr><tr class="layout">
Reid Spencere6a338d2007-01-15 18:28:34 +0000958 <td class="left"><tt>float&nbsp;(i16&nbsp;sext,&nbsp;i32&nbsp;*)&nbsp;*
Reid Spencer655dcc62006-12-31 07:20:23 +0000959 </tt></td>
Reid Spencer58c08712006-12-31 07:18:34 +0000960 <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes
961 an <tt>i16</tt> that should be sign extended and a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000962 <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning
Reid Spencer58c08712006-12-31 07:18:34 +0000963 <tt>float</tt>.
964 </td>
965 </tr><tr class="layout">
966 <td class="left"><tt>i32 (i8*, ...)</tt></td>
967 <td class="left">A vararg function that takes at least one
Reid Spencer3e628eb92007-01-04 16:43:23 +0000968 <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),
Reid Spencer58c08712006-12-31 07:18:34 +0000969 which returns an integer. This is the signature for <tt>printf</tt> in
970 LLVM.
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000971 </td>
972 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000973</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000974
Misha Brukman76307852003-11-08 01:05:38 +0000975</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000976<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000977<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000978<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000979<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000980<p>The structure type is used to represent a collection of data members
981together in memory. The packing of the field types is defined to match
982the ABI of the underlying processor. The elements of a structure may
983be any type that has a size.</p>
984<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
985and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
986field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
987instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000988<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000989<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000990<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000991<table class="layout">
992 <tr class="layout">
993 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000994 <tt>{ i32, i32, i32 }</tt><br/>
995 <tt>{ float, i32 (i32) * }</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000996 </td>
997 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +0000998 a triple of three <tt>i32</tt> values<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000999 A pair, where the first element is a <tt>float</tt> and the second element
1000 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001001 that takes an <tt>i32</tt>, returning an <tt>i32</tt>.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001002 </td>
1003 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001004</table>
Misha Brukman76307852003-11-08 01:05:38 +00001005</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001006
Chris Lattner2f7c9632001-06-06 20:29:01 +00001007<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001008<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
1009</div>
1010<div class="doc_text">
1011<h5>Overview:</h5>
1012<p>The packed structure type is used to represent a collection of data members
1013together in memory. There is no padding between fields. Further, the alignment
1014of a packed structure is 1 byte. The elements of a packed structure may
1015be any type that has a size.</p>
1016<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
1017and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
1018field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
1019instruction.</p>
1020<h5>Syntax:</h5>
1021<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
1022<h5>Examples:</h5>
1023<table class="layout">
1024 <tr class="layout">
1025 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001026 <tt> &lt; { i32, i32, i32 } &gt; </tt><br/>
1027 <tt> &lt; { float, i32 (i32) * } &gt; </tt><br/>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001028 </td>
1029 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001030 a triple of three <tt>i32</tt> values<br/>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001031 A pair, where the first element is a <tt>float</tt> and the second element
1032 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001033 that takes an <tt>i32</tt>, returning an <tt>i32</tt>.<br/>
Andrew Lenharth8df88e22006-12-08 17:13:00 +00001034 </td>
1035 </tr>
1036</table>
1037</div>
1038
1039<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001040<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001041<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00001042<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001043<p>As in many languages, the pointer type represents a pointer or
1044reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +00001045<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001046<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001047<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001048<table class="layout">
1049 <tr class="layout">
1050 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001051 <tt>[4x i32]*</tt><br/>
1052 <tt>i32 (i32 *) *</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001053 </td>
1054 <td class="left">
1055 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001056 four <tt>i32</tt> values<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001057 A <a href="#t_pointer">pointer</a> to a <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001058 href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an
1059 <tt>i32</tt>.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001060 </td>
1061 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001062</table>
Misha Brukman76307852003-11-08 01:05:38 +00001063</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001064
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001065<!-- _______________________________________________________________________ -->
Reid Spencer404a3252007-02-15 03:07:05 +00001066<div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001067<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001068
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001069<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001070
Reid Spencer404a3252007-02-15 03:07:05 +00001071<p>A vector type is a simple derived type that represents a vector
1072of elements. Vector types are used when multiple primitive data
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001073are operated in parallel using a single instruction (SIMD).
Reid Spencer404a3252007-02-15 03:07:05 +00001074A vector type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +00001075elements) and an underlying primitive data type. Vectors must have a power
Reid Spencer404a3252007-02-15 03:07:05 +00001076of two length (1, 2, 4, 8, 16 ...). Vector types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001077considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001078
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001079<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001080
1081<pre>
1082 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1083</pre>
1084
John Criswell4a3327e2005-05-13 22:25:59 +00001085<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001086be any integer or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001087
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001088<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001089
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001090<table class="layout">
1091 <tr class="layout">
1092 <td class="left">
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001093 <tt>&lt;4 x i32&gt;</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001094 <tt>&lt;8 x float&gt;</tt><br/>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001095 <tt>&lt;2 x i64&gt;</tt><br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001096 </td>
1097 <td class="left">
Reid Spencer404a3252007-02-15 03:07:05 +00001098 Vector of 4 32-bit integer values.<br/>
1099 Vector of 8 floating-point values.<br/>
1100 Vector of 2 64-bit integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001101 </td>
1102 </tr>
1103</table>
Misha Brukman76307852003-11-08 01:05:38 +00001104</div>
1105
Chris Lattner37b6b092005-04-25 17:34:15 +00001106<!-- _______________________________________________________________________ -->
1107<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1108<div class="doc_text">
1109
1110<h5>Overview:</h5>
1111
1112<p>Opaque types are used to represent unknown types in the system. This
1113corresponds (for example) to the C notion of a foward declared structure type.
1114In LLVM, opaque types can eventually be resolved to any type (not just a
1115structure type).</p>
1116
1117<h5>Syntax:</h5>
1118
1119<pre>
1120 opaque
1121</pre>
1122
1123<h5>Examples:</h5>
1124
1125<table class="layout">
1126 <tr class="layout">
1127 <td class="left">
1128 <tt>opaque</tt>
1129 </td>
1130 <td class="left">
1131 An opaque type.<br/>
1132 </td>
1133 </tr>
1134</table>
1135</div>
1136
1137
Chris Lattner74d3f822004-12-09 17:30:23 +00001138<!-- *********************************************************************** -->
1139<div class="doc_section"> <a name="constants">Constants</a> </div>
1140<!-- *********************************************************************** -->
1141
1142<div class="doc_text">
1143
1144<p>LLVM has several different basic types of constants. This section describes
1145them all and their syntax.</p>
1146
1147</div>
1148
1149<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001150<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001151
1152<div class="doc_text">
1153
1154<dl>
1155 <dt><b>Boolean constants</b></dt>
1156
1157 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
Reid Spencer36a15422007-01-12 03:35:51 +00001158 constants of the <tt><a href="#t_primitive">i1</a></tt> type.
Chris Lattner74d3f822004-12-09 17:30:23 +00001159 </dd>
1160
1161 <dt><b>Integer constants</b></dt>
1162
Reid Spencer8f08d802004-12-09 18:02:53 +00001163 <dd>Standard integers (such as '4') are constants of the <a
Reid Spencer3e628eb92007-01-04 16:43:23 +00001164 href="#t_integer">integer</a> type. Negative numbers may be used with
Chris Lattner74d3f822004-12-09 17:30:23 +00001165 integer types.
1166 </dd>
1167
1168 <dt><b>Floating point constants</b></dt>
1169
1170 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1171 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +00001172 notation (see below). Floating point constants must have a <a
1173 href="#t_floating">floating point</a> type. </dd>
1174
1175 <dt><b>Null pointer constants</b></dt>
1176
John Criswelldfe6a862004-12-10 15:51:16 +00001177 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001178 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1179
1180</dl>
1181
John Criswelldfe6a862004-12-10 15:51:16 +00001182<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001183of floating point constants. For example, the form '<tt>double
11840x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
11854.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001186(and the only time that they are generated by the disassembler) is when a
1187floating point constant must be emitted but it cannot be represented as a
1188decimal floating point number. For example, NaN's, infinities, and other
1189special values are represented in their IEEE hexadecimal format so that
1190assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001191
1192</div>
1193
1194<!-- ======================================================================= -->
1195<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1196</div>
1197
1198<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +00001199<p>Aggregate constants arise from aggregation of simple constants
1200and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001201
1202<dl>
1203 <dt><b>Structure constants</b></dt>
1204
1205 <dd>Structure constants are represented with notation similar to structure
1206 type definitions (a comma separated list of elements, surrounded by braces
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001207 (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* %G }</tt>",
1208 where "<tt>%G</tt>" is declared as "<tt>%G = external global i32</tt>". Structure constants
Chris Lattner455fc8c2005-03-07 22:13:59 +00001209 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001210 types of elements must match those specified by the type.
1211 </dd>
1212
1213 <dt><b>Array constants</b></dt>
1214
1215 <dd>Array constants are represented with notation similar to array type
1216 definitions (a comma separated list of elements, surrounded by square brackets
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001217 (<tt>[]</tt>)). For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001218 constants must have <a href="#t_array">array type</a>, and the number and
1219 types of elements must match those specified by the type.
1220 </dd>
1221
Reid Spencer404a3252007-02-15 03:07:05 +00001222 <dt><b>Vector constants</b></dt>
Chris Lattner74d3f822004-12-09 17:30:23 +00001223
Reid Spencer404a3252007-02-15 03:07:05 +00001224 <dd>Vector constants are represented with notation similar to vector type
Chris Lattner74d3f822004-12-09 17:30:23 +00001225 definitions (a comma separated list of elements, surrounded by
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001226 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; i32 42,
Reid Spencer404a3252007-02-15 03:07:05 +00001227 i32 11, i32 74, i32 100 &gt;</tt>". VEctor constants must have <a
1228 href="#t_vector">vector type</a>, and the number and types of elements must
Chris Lattner74d3f822004-12-09 17:30:23 +00001229 match those specified by the type.
1230 </dd>
1231
1232 <dt><b>Zero initialization</b></dt>
1233
1234 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1235 value to zero of <em>any</em> type, including scalar and aggregate types.
1236 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001237 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001238 initializers.
1239 </dd>
1240</dl>
1241
1242</div>
1243
1244<!-- ======================================================================= -->
1245<div class="doc_subsection">
1246 <a name="globalconstants">Global Variable and Function Addresses</a>
1247</div>
1248
1249<div class="doc_text">
1250
1251<p>The addresses of <a href="#globalvars">global variables</a> and <a
1252href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001253constants. These constants are explicitly referenced when the <a
1254href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001255href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1256file:</p>
1257
1258<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001259 %X = global i32 17
1260 %Y = global i32 42
1261 %Z = global [2 x i32*] [ i32* %X, i32* %Y ]
Chris Lattner74d3f822004-12-09 17:30:23 +00001262</pre>
1263
1264</div>
1265
1266<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001267<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001268<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001269 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001270 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001271 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001272
Reid Spencer641f5c92004-12-09 18:13:12 +00001273 <p>Undefined values indicate to the compiler that the program is well defined
1274 no matter what value is used, giving the compiler more freedom to optimize.
1275 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001276</div>
1277
1278<!-- ======================================================================= -->
1279<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1280</div>
1281
1282<div class="doc_text">
1283
1284<p>Constant expressions are used to allow expressions involving other constants
1285to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001286href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001287that does not have side effects (e.g. load and call are not supported). The
1288following is the syntax for constant expressions:</p>
1289
1290<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001291 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1292 <dd>Truncate a constant to another type. The bit size of CST must be larger
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001293 than the bit size of TYPE. Both types must be integers.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001294
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001295 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1296 <dd>Zero extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001297 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001298
1299 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1300 <dd>Sign extend a constant to another type. The bit size of CST must be
Chris Lattnerc0f423a2007-01-15 01:54:13 +00001301 smaller or equal to the bit size of TYPE. Both types must be integers.</dd>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001302
1303 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1304 <dd>Truncate a floating point constant to another floating point type. The
1305 size of CST must be larger than the size of TYPE. Both types must be
1306 floating point.</dd>
1307
1308 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1309 <dd>Floating point extend a constant to another type. The size of CST must be
1310 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1311
1312 <dt><b><tt>fp2uint ( CST to TYPE )</tt></b></dt>
1313 <dd>Convert a floating point constant to the corresponding unsigned integer
1314 constant. TYPE must be an integer type. CST must be floating point. If the
1315 value won't fit in the integer type, the results are undefined.</dd>
1316
Reid Spencer51b07252006-11-09 23:03:26 +00001317 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001318 <dd>Convert a floating point constant to the corresponding signed integer
1319 constant. TYPE must be an integer type. CST must be floating point. If the
1320 value won't fit in the integer type, the results are undefined.</dd>
1321
Reid Spencer51b07252006-11-09 23:03:26 +00001322 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001323 <dd>Convert an unsigned integer constant to the corresponding floating point
1324 constant. TYPE must be floating point. CST must be of integer type. If the
1325 value won't fit in the floating point type, the results are undefined.</dd>
1326
Reid Spencer51b07252006-11-09 23:03:26 +00001327 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001328 <dd>Convert a signed integer constant to the corresponding floating point
1329 constant. TYPE must be floating point. CST must be of integer type. If the
1330 value won't fit in the floating point type, the results are undefined.</dd>
1331
Reid Spencer5b950642006-11-11 23:08:07 +00001332 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1333 <dd>Convert a pointer typed constant to the corresponding integer constant
1334 TYPE must be an integer type. CST must be of pointer type. The CST value is
1335 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1336
1337 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1338 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1339 pointer type. CST must be of integer type. The CST value is zero extended,
1340 truncated, or unchanged to make it fit in a pointer size. This one is
1341 <i>really</i> dangerous!</dd>
1342
1343 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001344 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1345 identical (same number of bits). The conversion is done as if the CST value
1346 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5b950642006-11-11 23:08:07 +00001347 with this operator, just the type. This can be used for conversion of
Reid Spencer404a3252007-02-15 03:07:05 +00001348 vector types to any other type, as long as they have the same bit width. For
Reid Spencer5b950642006-11-11 23:08:07 +00001349 pointers it is only valid to cast to another pointer type.
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001350 </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001351
1352 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1353
1354 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1355 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1356 instruction, the index list may have zero or more indexes, which are required
1357 to make sense for the type of "CSTPTR".</dd>
1358
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001359 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1360
1361 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer9965ee72006-12-04 19:23:19 +00001362 constants.</dd>
1363
1364 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1365 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1366
1367 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1368 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001369
1370 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1371
1372 <dd>Perform the <a href="#i_extractelement">extractelement
1373 operation</a> on constants.
1374
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001375 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1376
1377 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer9965ee72006-12-04 19:23:19 +00001378 operation</a> on constants.</dd>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001379
Chris Lattner016a0e52006-04-08 00:13:41 +00001380
1381 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1382
1383 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer9965ee72006-12-04 19:23:19 +00001384 operation</a> on constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00001385
Chris Lattner74d3f822004-12-09 17:30:23 +00001386 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1387
Reid Spencer641f5c92004-12-09 18:13:12 +00001388 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1389 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001390 binary</a> operations. The constraints on operands are the same as those for
1391 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001392 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001393</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001394</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001395
Chris Lattner2f7c9632001-06-06 20:29:01 +00001396<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00001397<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1398<!-- *********************************************************************** -->
1399
1400<!-- ======================================================================= -->
1401<div class="doc_subsection">
1402<a name="inlineasm">Inline Assembler Expressions</a>
1403</div>
1404
1405<div class="doc_text">
1406
1407<p>
1408LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1409Module-Level Inline Assembly</a>) through the use of a special value. This
1410value represents the inline assembler as a string (containing the instructions
1411to emit), a list of operand constraints (stored as a string), and a flag that
1412indicates whether or not the inline asm expression has side effects. An example
1413inline assembler expression is:
1414</p>
1415
1416<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001417 i32 (i32) asm "bswap $0", "=r,r"
Chris Lattner98f013c2006-01-25 23:47:57 +00001418</pre>
1419
1420<p>
1421Inline assembler expressions may <b>only</b> be used as the callee operand of
1422a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1423</p>
1424
1425<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001426 %X = call i32 asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(i32 %Y)
Chris Lattner98f013c2006-01-25 23:47:57 +00001427</pre>
1428
1429<p>
1430Inline asms with side effects not visible in the constraint list must be marked
1431as having side effects. This is done through the use of the
1432'<tt>sideeffect</tt>' keyword, like so:
1433</p>
1434
1435<pre>
1436 call void asm sideeffect "eieio", ""()
1437</pre>
1438
1439<p>TODO: The format of the asm and constraints string still need to be
1440documented here. Constraints on what can be done (e.g. duplication, moving, etc
1441need to be documented).
1442</p>
1443
1444</div>
1445
1446<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001447<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1448<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001449
Misha Brukman76307852003-11-08 01:05:38 +00001450<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001451
Chris Lattner48b383b02003-11-25 01:02:51 +00001452<p>The LLVM instruction set consists of several different
1453classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001454instructions</a>, <a href="#binaryops">binary instructions</a>,
1455<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001456 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1457instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001458
Misha Brukman76307852003-11-08 01:05:38 +00001459</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001460
Chris Lattner2f7c9632001-06-06 20:29:01 +00001461<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001462<div class="doc_subsection"> <a name="terminators">Terminator
1463Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001464
Misha Brukman76307852003-11-08 01:05:38 +00001465<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001466
Chris Lattner48b383b02003-11-25 01:02:51 +00001467<p>As mentioned <a href="#functionstructure">previously</a>, every
1468basic block in a program ends with a "Terminator" instruction, which
1469indicates which block should be executed after the current block is
1470finished. These terminator instructions typically yield a '<tt>void</tt>'
1471value: they produce control flow, not values (the one exception being
1472the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001473<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001474 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1475instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001476the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1477 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1478 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001479
Misha Brukman76307852003-11-08 01:05:38 +00001480</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001481
Chris Lattner2f7c9632001-06-06 20:29:01 +00001482<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001483<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1484Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001485<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001486<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001487<pre> ret &lt;type&gt; &lt;value&gt; <i>; Return a value from a non-void function</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001488 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001489</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001490<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001491<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001492value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001493<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001494returns a value and then causes control flow, and one that just causes
1495control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001496<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001497<p>The '<tt>ret</tt>' instruction may return any '<a
1498 href="#t_firstclass">first class</a>' type. Notice that a function is
1499not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1500instruction inside of the function that returns a value that does not
1501match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001502<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001503<p>When the '<tt>ret</tt>' instruction is executed, control flow
1504returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001505 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001506the instruction after the call. If the caller was an "<a
1507 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001508at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001509returns a value, that value shall set the call or invoke instruction's
1510return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001511<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001512<pre> ret i32 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001513 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001514</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001515</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001516<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001517<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001518<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001519<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001520<pre> br i1 &lt;cond&gt;, label &lt;iftrue&gt;, label &lt;iffalse&gt;<br> br label &lt;dest&gt; <i>; Unconditional branch</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001521</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001522<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001523<p>The '<tt>br</tt>' instruction is used to cause control flow to
1524transfer to a different basic block in the current function. There are
1525two forms of this instruction, corresponding to a conditional branch
1526and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001527<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001528<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
Reid Spencer36a15422007-01-12 03:35:51 +00001529single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The
Chris Lattner48b383b02003-11-25 01:02:51 +00001530unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1531value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001532<h5>Semantics:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001533<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001534argument is evaluated. If the value is <tt>true</tt>, control flows
1535to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1536control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001537<h5>Example:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00001538<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq, i32 %a, %b<br> br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001539 href="#i_ret">ret</a> i32 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> i32 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001540</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001541<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001542<div class="doc_subsubsection">
1543 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1544</div>
1545
Misha Brukman76307852003-11-08 01:05:38 +00001546<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001547<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001548
1549<pre>
1550 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1551</pre>
1552
Chris Lattner2f7c9632001-06-06 20:29:01 +00001553<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001554
1555<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1556several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001557instruction, allowing a branch to occur to one of many possible
1558destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001559
1560
Chris Lattner2f7c9632001-06-06 20:29:01 +00001561<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001562
1563<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1564comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1565an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1566table is not allowed to contain duplicate constant entries.</p>
1567
Chris Lattner2f7c9632001-06-06 20:29:01 +00001568<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001569
Chris Lattner48b383b02003-11-25 01:02:51 +00001570<p>The <tt>switch</tt> instruction specifies a table of values and
1571destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001572table is searched for the given value. If the value is found, control flow is
1573transfered to the corresponding destination; otherwise, control flow is
1574transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001575
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001576<h5>Implementation:</h5>
1577
1578<p>Depending on properties of the target machine and the particular
1579<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001580ways. For example, it could be generated as a series of chained conditional
1581branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001582
1583<h5>Example:</h5>
1584
1585<pre>
1586 <i>; Emulate a conditional br instruction</i>
Reid Spencer36a15422007-01-12 03:35:51 +00001587 %Val = <a href="#i_zext">zext</a> i1 %value to i32
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001588 switch i32 %Val, label %truedest [i32 0, label %falsedest ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001589
1590 <i>; Emulate an unconditional br instruction</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001591 switch i32 0, label %dest [ ]
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001592
1593 <i>; Implement a jump table:</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001594 switch i32 %val, label %otherwise [ i32 0, label %onzero
1595 i32 1, label %onone
1596 i32 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001597</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001598</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001599
Chris Lattner2f7c9632001-06-06 20:29:01 +00001600<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001601<div class="doc_subsubsection">
1602 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1603</div>
1604
Misha Brukman76307852003-11-08 01:05:38 +00001605<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001606
Chris Lattner2f7c9632001-06-06 20:29:01 +00001607<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001608
1609<pre>
1610 &lt;result&gt; = invoke [<a href="#callingconv">cconv</a>] &lt;ptr to function ty&gt; %&lt;function ptr val&gt;(&lt;function args&gt;)
Chris Lattner6b7a0082006-05-14 18:23:06 +00001611 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00001612</pre>
1613
Chris Lattnera8292f32002-05-06 22:08:29 +00001614<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001615
1616<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1617function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001618'<tt>normal</tt>' label or the
1619'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001620"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1621"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001622href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1623continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001624
Chris Lattner2f7c9632001-06-06 20:29:01 +00001625<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001626
Misha Brukman76307852003-11-08 01:05:38 +00001627<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001628
Chris Lattner2f7c9632001-06-06 20:29:01 +00001629<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001630 <li>
John Criswell4a3327e2005-05-13 22:25:59 +00001631 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001632 convention</a> the call should use. If none is specified, the call defaults
1633 to using C calling conventions.
1634 </li>
1635 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1636 function value being invoked. In most cases, this is a direct function
1637 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1638 an arbitrary pointer to function value.
1639 </li>
1640
1641 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1642 function to be invoked. </li>
1643
1644 <li>'<tt>function args</tt>': argument list whose types match the function
1645 signature argument types. If the function signature indicates the function
1646 accepts a variable number of arguments, the extra arguments can be
1647 specified. </li>
1648
1649 <li>'<tt>normal label</tt>': the label reached when the called function
1650 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1651
1652 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1653 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1654
Chris Lattner2f7c9632001-06-06 20:29:01 +00001655</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001656
Chris Lattner2f7c9632001-06-06 20:29:01 +00001657<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001658
Misha Brukman76307852003-11-08 01:05:38 +00001659<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001660href="#i_call">call</a></tt>' instruction in most regards. The primary
1661difference is that it establishes an association with a label, which is used by
1662the runtime library to unwind the stack.</p>
1663
1664<p>This instruction is used in languages with destructors to ensure that proper
1665cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1666exception. Additionally, this is important for implementation of
1667'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1668
Chris Lattner2f7c9632001-06-06 20:29:01 +00001669<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001670<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001671 %retval = invoke i32 %Test(i32 15) to label %Continue
1672 unwind label %TestCleanup <i>; {i32}:retval set</i>
1673 %retval = invoke <a href="#callingconv">coldcc</a> i32 %Test(i32 15) to label %Continue
1674 unwind label %TestCleanup <i>; {i32}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001675</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001676</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001677
1678
Chris Lattner5ed60612003-09-03 00:41:47 +00001679<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001680
Chris Lattner48b383b02003-11-25 01:02:51 +00001681<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1682Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001683
Misha Brukman76307852003-11-08 01:05:38 +00001684<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001685
Chris Lattner5ed60612003-09-03 00:41:47 +00001686<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001687<pre>
1688 unwind
1689</pre>
1690
Chris Lattner5ed60612003-09-03 00:41:47 +00001691<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001692
1693<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1694at the first callee in the dynamic call stack which used an <a
1695href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1696primarily used to implement exception handling.</p>
1697
Chris Lattner5ed60612003-09-03 00:41:47 +00001698<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001699
1700<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1701immediately halt. The dynamic call stack is then searched for the first <a
1702href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1703execution continues at the "exceptional" destination block specified by the
1704<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1705dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001706</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001707
1708<!-- _______________________________________________________________________ -->
1709
1710<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1711Instruction</a> </div>
1712
1713<div class="doc_text">
1714
1715<h5>Syntax:</h5>
1716<pre>
1717 unreachable
1718</pre>
1719
1720<h5>Overview:</h5>
1721
1722<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1723instruction is used to inform the optimizer that a particular portion of the
1724code is not reachable. This can be used to indicate that the code after a
1725no-return function cannot be reached, and other facts.</p>
1726
1727<h5>Semantics:</h5>
1728
1729<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1730</div>
1731
1732
1733
Chris Lattner2f7c9632001-06-06 20:29:01 +00001734<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001735<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001736<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001737<p>Binary operators are used to do most of the computation in a
1738program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001739produce a single value. The operands might represent
Reid Spencer404a3252007-02-15 03:07:05 +00001740multiple data, as is the case with the <a href="#t_vector">vector</a> data type.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001741The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001742necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001743<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001744</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001745<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001746<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1747Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001748<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001749<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001750<pre> &lt;result&gt; = add &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001751</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001752<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001753<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001754<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001755<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001756 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
Reid Spencer404a3252007-02-15 03:07:05 +00001757 This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001758Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001759<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001760<p>The value produced is the integer or floating point sum of the two
1761operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001762<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001763<pre> &lt;result&gt; = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001764</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001765</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001766<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001767<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1768Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001769<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001770<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001771<pre> &lt;result&gt; = sub &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001772</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001773<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001774<p>The '<tt>sub</tt>' instruction returns the difference of its two
1775operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001776<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1777instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001778<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001779<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001780 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001781values.
Reid Spencer404a3252007-02-15 03:07:05 +00001782This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001783Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001784<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001785<p>The value produced is the integer or floating point difference of
1786the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001787<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001788<pre> &lt;result&gt; = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i>
1789 &lt;result&gt; = sub i32 0, %val <i>; yields {i32}:result = -%var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001790</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001791</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001792<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001793<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1794Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001795<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001796<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001797<pre> &lt;result&gt; = mul &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001798</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001799<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001800<p>The '<tt>mul</tt>' instruction returns the product of its two
1801operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001802<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001803<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001804 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001805values.
Reid Spencer404a3252007-02-15 03:07:05 +00001806This instruction can also take <a href="#t_vector">vector</a> versions of the values.
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001807Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001808<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001809<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001810two operands.</p>
Reid Spencer3e628eb92007-01-04 16:43:23 +00001811<p>Because the operands are the same width, the result of an integer
1812multiplication is the same whether the operands should be deemed unsigned or
1813signed.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001814<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001815<pre> &lt;result&gt; = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001816</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001817</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001818<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001819<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
1820</a></div>
1821<div class="doc_text">
1822<h5>Syntax:</h5>
1823<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1824</pre>
1825<h5>Overview:</h5>
1826<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
1827operands.</p>
1828<h5>Arguments:</h5>
1829<p>The two arguments to the '<tt>udiv</tt>' instruction must be
1830<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00001831types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001832of the values in which case the elements must be integers.</p>
1833<h5>Semantics:</h5>
1834<p>The value produced is the unsigned integer quotient of the two operands. This
1835instruction always performs an unsigned division operation, regardless of
1836whether the arguments are unsigned or not.</p>
1837<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001838<pre> &lt;result&gt; = udiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001839</pre>
1840</div>
1841<!-- _______________________________________________________________________ -->
1842<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
1843</a> </div>
1844<div class="doc_text">
1845<h5>Syntax:</h5>
1846<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1847</pre>
1848<h5>Overview:</h5>
1849<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
1850operands.</p>
1851<h5>Arguments:</h5>
1852<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
1853<a href="#t_integer">integer</a> values. Both arguments must have identical
Reid Spencer404a3252007-02-15 03:07:05 +00001854types. This instruction can also take <a href="#t_vector">vector</a> versions
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001855of the values in which case the elements must be integers.</p>
1856<h5>Semantics:</h5>
1857<p>The value produced is the signed integer quotient of the two operands. This
1858instruction always performs a signed division operation, regardless of whether
1859the arguments are signed or not.</p>
1860<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001861<pre> &lt;result&gt; = sdiv i32 4, %var <i>; yields {i32}:result = 4 / %var</i>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001862</pre>
1863</div>
1864<!-- _______________________________________________________________________ -->
1865<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001866Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001867<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001868<h5>Syntax:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001869<pre> &lt;result&gt; = fdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001870</pre>
1871<h5>Overview:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001872<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner48b383b02003-11-25 01:02:51 +00001873operands.</p>
1874<h5>Arguments:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001875<p>The two arguments to the '<tt>div</tt>' instruction must be
1876<a href="#t_floating">floating point</a> values. Both arguments must have
Reid Spencer404a3252007-02-15 03:07:05 +00001877identical types. This instruction can also take <a href="#t_vector">vector</a>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001878versions of the values in which case the elements must be floating point.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001879<h5>Semantics:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001880<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001881<h5>Example:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001882<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001883</pre>
1884</div>
1885<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00001886<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
1887</div>
1888<div class="doc_text">
1889<h5>Syntax:</h5>
1890<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1891</pre>
1892<h5>Overview:</h5>
1893<p>The '<tt>urem</tt>' instruction returns the remainder from the
1894unsigned division of its two arguments.</p>
1895<h5>Arguments:</h5>
1896<p>The two arguments to the '<tt>urem</tt>' instruction must be
1897<a href="#t_integer">integer</a> values. Both arguments must have identical
1898types.</p>
1899<h5>Semantics:</h5>
1900<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
1901This instruction always performs an unsigned division to get the remainder,
1902regardless of whether the arguments are unsigned or not.</p>
1903<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001904<pre> &lt;result&gt; = urem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001905</pre>
1906
1907</div>
1908<!-- _______________________________________________________________________ -->
1909<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001910Instruction</a> </div>
1911<div class="doc_text">
1912<h5>Syntax:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001913<pre> &lt;result&gt; = srem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001914</pre>
1915<h5>Overview:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001916<p>The '<tt>srem</tt>' instruction returns the remainder from the
1917signed division of its two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001918<h5>Arguments:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001919<p>The two arguments to the '<tt>srem</tt>' instruction must be
1920<a href="#t_integer">integer</a> values. Both arguments must have identical
1921types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001922<h5>Semantics:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001923<p>This instruction returns the <i>remainder</i> of a division (where the result
Chris Lattner48b383b02003-11-25 01:02:51 +00001924has the same sign as the divisor), not the <i>modulus</i> (where the
1925result has the same sign as the dividend) of a value. For more
John Criswell4c0cf7f2005-10-24 16:17:18 +00001926information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001927 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1928Math Forum</a>.</p>
1929<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00001930<pre> &lt;result&gt; = srem i32 4, %var <i>; yields {i32}:result = 4 % %var</i>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001931</pre>
1932
1933</div>
1934<!-- _______________________________________________________________________ -->
1935<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
1936Instruction</a> </div>
1937<div class="doc_text">
1938<h5>Syntax:</h5>
1939<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1940</pre>
1941<h5>Overview:</h5>
1942<p>The '<tt>frem</tt>' instruction returns the remainder from the
1943division of its two operands.</p>
1944<h5>Arguments:</h5>
1945<p>The two arguments to the '<tt>frem</tt>' instruction must be
1946<a href="#t_floating">floating point</a> values. Both arguments must have
1947identical types.</p>
1948<h5>Semantics:</h5>
1949<p>This instruction returns the <i>remainder</i> of a division.</p>
1950<h5>Example:</h5>
1951<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001952</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001953</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00001954
Reid Spencer2ab01932007-02-02 13:57:07 +00001955<!-- ======================================================================= -->
1956<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1957Operations</a> </div>
1958<div class="doc_text">
1959<p>Bitwise binary operators are used to do various forms of
1960bit-twiddling in a program. They are generally very efficient
1961instructions and can commonly be strength reduced from other
1962instructions. They require two operands, execute an operation on them,
1963and produce a single value. The resulting value of the bitwise binary
1964operators is always the same type as its first operand.</p>
1965</div>
1966
Reid Spencer04e259b2007-01-31 21:39:12 +00001967<!-- _______________________________________________________________________ -->
1968<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
1969Instruction</a> </div>
1970<div class="doc_text">
1971<h5>Syntax:</h5>
1972<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1973</pre>
1974<h5>Overview:</h5>
1975<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
1976the left a specified number of bits.</p>
1977<h5>Arguments:</h5>
1978<p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a
1979 href="#t_integer">integer</a> type.</p>
1980<h5>Semantics:</h5>
1981<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
1982<h5>Example:</h5><pre>
1983 &lt;result&gt; = shl i32 4, %var <i>; yields {i32}: 4 &lt;&lt; %var</i>
1984 &lt;result&gt; = shl i32 4, 2 <i>; yields {i32}: 16</i>
1985 &lt;result&gt; = shl i32 1, 10 <i>; yields {i32}: 1024</i>
1986</pre>
1987</div>
1988<!-- _______________________________________________________________________ -->
1989<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
1990Instruction</a> </div>
1991<div class="doc_text">
1992<h5>Syntax:</h5>
1993<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1994</pre>
1995
1996<h5>Overview:</h5>
1997<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
1998operand shifted to the right a specified number of bits.</p>
1999
2000<h5>Arguments:</h5>
2001<p>Both arguments to the '<tt>lshr</tt>' instruction must be the same
2002<a href="#t_integer">integer</a> type.</p>
2003
2004<h5>Semantics:</h5>
2005<p>This instruction always performs a logical shift right operation. The most
2006significant bits of the result will be filled with zero bits after the
2007shift.</p>
2008
2009<h5>Example:</h5>
2010<pre>
2011 &lt;result&gt; = lshr i32 4, 1 <i>; yields {i32}:result = 2</i>
2012 &lt;result&gt; = lshr i32 4, 2 <i>; yields {i32}:result = 1</i>
2013 &lt;result&gt; = lshr i8 4, 3 <i>; yields {i8}:result = 0</i>
2014 &lt;result&gt; = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i>
2015</pre>
2016</div>
2017
Reid Spencer2ab01932007-02-02 13:57:07 +00002018<!-- _______________________________________________________________________ -->
Reid Spencer04e259b2007-01-31 21:39:12 +00002019<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2020Instruction</a> </div>
2021<div class="doc_text">
2022
2023<h5>Syntax:</h5>
2024<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
2025</pre>
2026
2027<h5>Overview:</h5>
2028<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
2029operand shifted to the right a specified number of bits.</p>
2030
2031<h5>Arguments:</h5>
2032<p>Both arguments to the '<tt>ashr</tt>' instruction must be the same
2033<a href="#t_integer">integer</a> type.</p>
2034
2035<h5>Semantics:</h5>
2036<p>This instruction always performs an arithmetic shift right operation,
2037The most significant bits of the result will be filled with the sign bit
2038of <tt>var1</tt>.</p>
2039
2040<h5>Example:</h5>
2041<pre>
2042 &lt;result&gt; = ashr i32 4, 1 <i>; yields {i32}:result = 2</i>
2043 &lt;result&gt; = ashr i32 4, 2 <i>; yields {i32}:result = 1</i>
2044 &lt;result&gt; = ashr i8 4, 3 <i>; yields {i8}:result = 0</i>
2045 &lt;result&gt; = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i>
2046</pre>
2047</div>
2048
Chris Lattner2f7c9632001-06-06 20:29:01 +00002049<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002050<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
2051Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002052<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002053<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002054<pre> &lt;result&gt; = and &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002055</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002056<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002057<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
2058its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002059<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002060<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002061 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002062identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002063<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002064<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002065<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002066<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00002067<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00002068 <tbody>
2069 <tr>
2070 <td>In0</td>
2071 <td>In1</td>
2072 <td>Out</td>
2073 </tr>
2074 <tr>
2075 <td>0</td>
2076 <td>0</td>
2077 <td>0</td>
2078 </tr>
2079 <tr>
2080 <td>0</td>
2081 <td>1</td>
2082 <td>0</td>
2083 </tr>
2084 <tr>
2085 <td>1</td>
2086 <td>0</td>
2087 <td>0</td>
2088 </tr>
2089 <tr>
2090 <td>1</td>
2091 <td>1</td>
2092 <td>1</td>
2093 </tr>
2094 </tbody>
2095</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002096</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002097<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002098<pre> &lt;result&gt; = and i32 4, %var <i>; yields {i32}:result = 4 &amp; %var</i>
2099 &lt;result&gt; = and i32 15, 40 <i>; yields {i32}:result = 8</i>
2100 &lt;result&gt; = and i32 4, 8 <i>; yields {i32}:result = 0</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002101</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002102</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002103<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002104<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002105<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002106<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002107<pre> &lt;result&gt; = or &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002108</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00002109<h5>Overview:</h5>
2110<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
2111or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002112<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002113<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002114 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002115identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002116<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002117<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002118<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002119<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002120<table border="1" cellspacing="0" cellpadding="4">
2121 <tbody>
2122 <tr>
2123 <td>In0</td>
2124 <td>In1</td>
2125 <td>Out</td>
2126 </tr>
2127 <tr>
2128 <td>0</td>
2129 <td>0</td>
2130 <td>0</td>
2131 </tr>
2132 <tr>
2133 <td>0</td>
2134 <td>1</td>
2135 <td>1</td>
2136 </tr>
2137 <tr>
2138 <td>1</td>
2139 <td>0</td>
2140 <td>1</td>
2141 </tr>
2142 <tr>
2143 <td>1</td>
2144 <td>1</td>
2145 <td>1</td>
2146 </tr>
2147 </tbody>
2148</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002149</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002150<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002151<pre> &lt;result&gt; = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i>
2152 &lt;result&gt; = or i32 15, 40 <i>; yields {i32}:result = 47</i>
2153 &lt;result&gt; = or i32 4, 8 <i>; yields {i32}:result = 12</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002154</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002155</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002156<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002157<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2158Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002159<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002160<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002161<pre> &lt;result&gt; = xor &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002162</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002163<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002164<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2165or of its two operands. The <tt>xor</tt> is used to implement the
2166"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002167<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002168<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002169 href="#t_integer">integer</a> values. Both arguments must have
Chris Lattner48b383b02003-11-25 01:02:51 +00002170identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002171<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002172<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002173<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002174<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002175<table border="1" cellspacing="0" cellpadding="4">
2176 <tbody>
2177 <tr>
2178 <td>In0</td>
2179 <td>In1</td>
2180 <td>Out</td>
2181 </tr>
2182 <tr>
2183 <td>0</td>
2184 <td>0</td>
2185 <td>0</td>
2186 </tr>
2187 <tr>
2188 <td>0</td>
2189 <td>1</td>
2190 <td>1</td>
2191 </tr>
2192 <tr>
2193 <td>1</td>
2194 <td>0</td>
2195 <td>1</td>
2196 </tr>
2197 <tr>
2198 <td>1</td>
2199 <td>1</td>
2200 <td>0</td>
2201 </tr>
2202 </tbody>
2203</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002204</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00002205<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002206<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002207<pre> &lt;result&gt; = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i>
2208 &lt;result&gt; = xor i32 15, 40 <i>; yields {i32}:result = 39</i>
2209 &lt;result&gt; = xor i32 4, 8 <i>; yields {i32}:result = 12</i>
2210 &lt;result&gt; = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002211</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002212</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002213
Chris Lattner2f7c9632001-06-06 20:29:01 +00002214<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00002215<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00002216 <a name="vectorops">Vector Operations</a>
2217</div>
2218
2219<div class="doc_text">
2220
2221<p>LLVM supports several instructions to represent vector operations in a
2222target-independent manner. This instructions cover the element-access and
2223vector-specific operations needed to process vectors effectively. While LLVM
2224does directly support these vector operations, many sophisticated algorithms
2225will want to use target-specific intrinsics to take full advantage of a specific
2226target.</p>
2227
2228</div>
2229
2230<!-- _______________________________________________________________________ -->
2231<div class="doc_subsubsection">
2232 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2233</div>
2234
2235<div class="doc_text">
2236
2237<h5>Syntax:</h5>
2238
2239<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002240 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, i32 &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002241</pre>
2242
2243<h5>Overview:</h5>
2244
2245<p>
2246The '<tt>extractelement</tt>' instruction extracts a single scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002247element from a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002248</p>
2249
2250
2251<h5>Arguments:</h5>
2252
2253<p>
2254The first operand of an '<tt>extractelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002255value of <a href="#t_vector">vector</a> type. The second operand is
Chris Lattnerce83bff2006-04-08 23:07:04 +00002256an index indicating the position from which to extract the element.
2257The index may be a variable.</p>
2258
2259<h5>Semantics:</h5>
2260
2261<p>
2262The result is a scalar of the same type as the element type of
2263<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2264<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2265results are undefined.
2266</p>
2267
2268<h5>Example:</h5>
2269
2270<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002271 %result = extractelement &lt;4 x i32&gt; %vec, i32 0 <i>; yields i32</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002272</pre>
2273</div>
2274
2275
2276<!-- _______________________________________________________________________ -->
2277<div class="doc_subsubsection">
2278 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2279</div>
2280
2281<div class="doc_text">
2282
2283<h5>Syntax:</h5>
2284
2285<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002286 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, i32 &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002287</pre>
2288
2289<h5>Overview:</h5>
2290
2291<p>
2292The '<tt>insertelement</tt>' instruction inserts a scalar
Reid Spencer404a3252007-02-15 03:07:05 +00002293element into a vector at a specified index.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002294</p>
2295
2296
2297<h5>Arguments:</h5>
2298
2299<p>
2300The first operand of an '<tt>insertelement</tt>' instruction is a
Reid Spencer404a3252007-02-15 03:07:05 +00002301value of <a href="#t_vector">vector</a> type. The second operand is a
Chris Lattnerce83bff2006-04-08 23:07:04 +00002302scalar value whose type must equal the element type of the first
2303operand. The third operand is an index indicating the position at
2304which to insert the value. The index may be a variable.</p>
2305
2306<h5>Semantics:</h5>
2307
2308<p>
Reid Spencer404a3252007-02-15 03:07:05 +00002309The result is a vector of the same type as <tt>val</tt>. Its
Chris Lattnerce83bff2006-04-08 23:07:04 +00002310element values are those of <tt>val</tt> except at position
2311<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2312exceeds the length of <tt>val</tt>, the results are undefined.
2313</p>
2314
2315<h5>Example:</h5>
2316
2317<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002318 %result = insertelement &lt;4 x i32&gt; %vec, i32 1, i32 0 <i>; yields &lt;4 x i32&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002319</pre>
2320</div>
2321
2322<!-- _______________________________________________________________________ -->
2323<div class="doc_subsubsection">
2324 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2325</div>
2326
2327<div class="doc_text">
2328
2329<h5>Syntax:</h5>
2330
2331<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002332 &lt;result&gt; = shufflevector &lt;n x &lt;ty&gt;&gt; &lt;v1&gt;, &lt;n x &lt;ty&gt;&gt; &lt;v2&gt;, &lt;n x i32&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
Chris Lattnerce83bff2006-04-08 23:07:04 +00002333</pre>
2334
2335<h5>Overview:</h5>
2336
2337<p>
2338The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2339from two input vectors, returning a vector of the same type.
2340</p>
2341
2342<h5>Arguments:</h5>
2343
2344<p>
2345The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2346with types that match each other and types that match the result of the
2347instruction. The third argument is a shuffle mask, which has the same number
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002348of elements as the other vector type, but whose element type is always 'i32'.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002349</p>
2350
2351<p>
2352The shuffle mask operand is required to be a constant vector with either
2353constant integer or undef values.
2354</p>
2355
2356<h5>Semantics:</h5>
2357
2358<p>
2359The elements of the two input vectors are numbered from left to right across
2360both of the vectors. The shuffle mask operand specifies, for each element of
2361the result vector, which element of the two input registers the result element
2362gets. The element selector may be undef (meaning "don't care") and the second
2363operand may be undef if performing a shuffle from only one vector.
2364</p>
2365
2366<h5>Example:</h5>
2367
2368<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002369 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; %v2,
2370 &lt;4 x i32&gt; &lt;i32 0, i32 4, i32 1, i32 5&gt; <i>; yields &lt;4 x i32&gt;</i>
2371 %result = shufflevector &lt;4 x i32&gt; %v1, &lt;4 x i32&gt; undef,
2372 &lt;4 x i32&gt; &lt;i32 0, i32 1, i32 2, i32 3&gt; <i>; yields &lt;4 x i32&gt;</i> - Identity shuffle.
Chris Lattnerce83bff2006-04-08 23:07:04 +00002373</pre>
2374</div>
2375
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00002376
Chris Lattnerce83bff2006-04-08 23:07:04 +00002377<!-- ======================================================================= -->
2378<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00002379 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00002380</div>
2381
Misha Brukman76307852003-11-08 01:05:38 +00002382<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002383
Chris Lattner48b383b02003-11-25 01:02:51 +00002384<p>A key design point of an SSA-based representation is how it
2385represents memory. In LLVM, no memory locations are in SSA form, which
2386makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00002387allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002388
Misha Brukman76307852003-11-08 01:05:38 +00002389</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002390
Chris Lattner2f7c9632001-06-06 20:29:01 +00002391<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002392<div class="doc_subsubsection">
2393 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2394</div>
2395
Misha Brukman76307852003-11-08 01:05:38 +00002396<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002397
Chris Lattner2f7c9632001-06-06 20:29:01 +00002398<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002399
2400<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002401 &lt;result&gt; = malloc &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002402</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002403
Chris Lattner2f7c9632001-06-06 20:29:01 +00002404<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002405
Chris Lattner48b383b02003-11-25 01:02:51 +00002406<p>The '<tt>malloc</tt>' instruction allocates memory from the system
2407heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002408
Chris Lattner2f7c9632001-06-06 20:29:01 +00002409<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002410
2411<p>The '<tt>malloc</tt>' instruction allocates
2412<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00002413bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002414appropriate type to the program. If "NumElements" is specified, it is the
2415number of elements allocated. If an alignment is specified, the value result
2416of the allocation is guaranteed to be aligned to at least that boundary. If
2417not specified, or if zero, the target can choose to align the allocation on any
2418convenient boundary.</p>
2419
Misha Brukman76307852003-11-08 01:05:38 +00002420<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002421
Chris Lattner2f7c9632001-06-06 20:29:01 +00002422<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002423
Chris Lattner48b383b02003-11-25 01:02:51 +00002424<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2425a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002426
Chris Lattner54611b42005-11-06 08:02:57 +00002427<h5>Example:</h5>
2428
2429<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002430 %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002431
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002432 %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i>
2433 %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i>
2434 %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i>
2435 %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i>
2436 %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002437</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002438</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002439
Chris Lattner2f7c9632001-06-06 20:29:01 +00002440<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002441<div class="doc_subsubsection">
2442 <a name="i_free">'<tt>free</tt>' Instruction</a>
2443</div>
2444
Misha Brukman76307852003-11-08 01:05:38 +00002445<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002446
Chris Lattner2f7c9632001-06-06 20:29:01 +00002447<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002448
2449<pre>
2450 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002451</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002452
Chris Lattner2f7c9632001-06-06 20:29:01 +00002453<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002454
Chris Lattner48b383b02003-11-25 01:02:51 +00002455<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00002456memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002457
Chris Lattner2f7c9632001-06-06 20:29:01 +00002458<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002459
Chris Lattner48b383b02003-11-25 01:02:51 +00002460<p>'<tt>value</tt>' shall be a pointer value that points to a value
2461that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2462instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002463
Chris Lattner2f7c9632001-06-06 20:29:01 +00002464<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002465
John Criswelldfe6a862004-12-10 15:51:16 +00002466<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00002467after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002468
Chris Lattner2f7c9632001-06-06 20:29:01 +00002469<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002470
2471<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002472 %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i>
2473 free [4 x i8]* %array
Chris Lattner2f7c9632001-06-06 20:29:01 +00002474</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002475</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002476
Chris Lattner2f7c9632001-06-06 20:29:01 +00002477<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002478<div class="doc_subsubsection">
2479 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2480</div>
2481
Misha Brukman76307852003-11-08 01:05:38 +00002482<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002483
Chris Lattner2f7c9632001-06-06 20:29:01 +00002484<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002485
2486<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002487 &lt;result&gt; = alloca &lt;type&gt;[, i32 &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002488</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002489
Chris Lattner2f7c9632001-06-06 20:29:01 +00002490<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002491
Chris Lattner48b383b02003-11-25 01:02:51 +00002492<p>The '<tt>alloca</tt>' instruction allocates memory on the current
2493stack frame of the procedure that is live until the current function
2494returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002495
Chris Lattner2f7c9632001-06-06 20:29:01 +00002496<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002497
John Criswelldfe6a862004-12-10 15:51:16 +00002498<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002499bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002500appropriate type to the program. If "NumElements" is specified, it is the
2501number of elements allocated. If an alignment is specified, the value result
2502of the allocation is guaranteed to be aligned to at least that boundary. If
2503not specified, or if zero, the target can choose to align the allocation on any
2504convenient boundary.</p>
2505
Misha Brukman76307852003-11-08 01:05:38 +00002506<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002507
Chris Lattner2f7c9632001-06-06 20:29:01 +00002508<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002509
John Criswell4a3327e2005-05-13 22:25:59 +00002510<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00002511memory is automatically released when the function returns. The '<tt>alloca</tt>'
2512instruction is commonly used to represent automatic variables that must
2513have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00002514 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00002515instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002516
Chris Lattner2f7c9632001-06-06 20:29:01 +00002517<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002518
2519<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002520 %ptr = alloca i32 <i>; yields {i32*}:ptr</i>
2521 %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i>
2522 %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i>
2523 %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002524</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002525</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002526
Chris Lattner2f7c9632001-06-06 20:29:01 +00002527<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002528<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2529Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002530<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002531<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002532<pre> &lt;result&gt; = load &lt;ty&gt;* &lt;pointer&gt;<br> &lt;result&gt; = volatile load &lt;ty&gt;* &lt;pointer&gt;<br></pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002533<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002534<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002535<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002536<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00002537address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00002538 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00002539marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00002540the number or order of execution of this <tt>load</tt> with other
2541volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2542instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00002543<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002544<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002545<h5>Examples:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002546<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002547 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002548 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2549 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002550</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002551</div>
Chris Lattner095735d2002-05-06 03:03:22 +00002552<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002553<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2554Instruction</a> </div>
Reid Spencera89fb182006-11-09 21:18:01 +00002555<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002556<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002557<pre> store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner12d456c2003-09-08 18:27:49 +00002558 volatile store &lt;ty&gt; &lt;value&gt;, &lt;ty&gt;* &lt;pointer&gt; <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002559</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002560<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002561<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002562<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002563<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell4c0cf7f2005-10-24 16:17:18 +00002564to store and an address in which to store it. The type of the '<tt>&lt;pointer&gt;</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002565operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00002566operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00002567optimizer is not allowed to modify the number or order of execution of
2568this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2569 href="#i_store">store</a></tt> instructions.</p>
2570<h5>Semantics:</h5>
2571<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2572at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002573<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002574<pre> %ptr = <a href="#i_alloca">alloca</a> i32 <i>; yields {i32*}:ptr</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00002575 <a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002576 href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i>
2577 %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002578</pre>
Reid Spencer443460a2006-11-09 21:15:49 +00002579</div>
2580
Chris Lattner095735d2002-05-06 03:03:22 +00002581<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00002582<div class="doc_subsubsection">
2583 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2584</div>
2585
Misha Brukman76307852003-11-08 01:05:38 +00002586<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00002587<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002588<pre>
2589 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2590</pre>
2591
Chris Lattner590645f2002-04-14 06:13:44 +00002592<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002593
2594<p>
2595The '<tt>getelementptr</tt>' instruction is used to get the address of a
2596subelement of an aggregate data structure.</p>
2597
Chris Lattner590645f2002-04-14 06:13:44 +00002598<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002599
Reid Spencercee005c2006-12-04 21:29:24 +00002600<p>This instruction takes a list of integer operands that indicate what
Chris Lattner33fd7022004-04-05 01:30:49 +00002601elements of the aggregate object to index to. The actual types of the arguments
2602provided depend on the type of the first pointer argument. The
2603'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002604levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002605structure, only <tt>i32</tt> integer constants are allowed. When indexing
Reid Spencercee005c2006-12-04 21:29:24 +00002606into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2607be sign extended to 64-bit values.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002608
Chris Lattner48b383b02003-11-25 01:02:51 +00002609<p>For example, let's consider a C code fragment and how it gets
2610compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002611
2612<pre>
2613 struct RT {
2614 char A;
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002615 i32 B[10][20];
Chris Lattner33fd7022004-04-05 01:30:49 +00002616 char C;
2617 };
2618 struct ST {
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002619 i32 X;
Chris Lattner33fd7022004-04-05 01:30:49 +00002620 double Y;
2621 struct RT Z;
2622 };
2623
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002624 define i32 *foo(struct ST *s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002625 return &amp;s[1].Z.B[5][13];
2626 }
2627</pre>
2628
Misha Brukman76307852003-11-08 01:05:38 +00002629<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002630
2631<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002632 %RT = type { i8 , [10 x [20 x i32]], i8 }
2633 %ST = type { i32, double, %RT }
Chris Lattner33fd7022004-04-05 01:30:49 +00002634
Brian Gaeke317ef962004-07-02 21:08:14 +00002635 implementation
2636
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002637 define i32* %foo(%ST* %s) {
Brian Gaeke317ef962004-07-02 21:08:14 +00002638 entry:
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002639 %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13
2640 ret i32* %reg
Chris Lattner33fd7022004-04-05 01:30:49 +00002641 }
2642</pre>
2643
Chris Lattner590645f2002-04-14 06:13:44 +00002644<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002645
2646<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002647on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencercee005c2006-12-04 21:29:24 +00002648and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencerc0312692006-12-03 16:53:48 +00002649<a href="#t_integer">integer</a> type but the value will always be sign extended
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002650to 64-bits. <a href="#t_struct">Structure</a> types, require <tt>i32</tt>
Reid Spencerc0312692006-12-03 16:53:48 +00002651<b>constants</b>.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002652
Misha Brukman76307852003-11-08 01:05:38 +00002653<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002654type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT
Chris Lattner33fd7022004-04-05 01:30:49 +00002655}</tt>' type, a structure. The second index indexes into the third element of
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002656the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]],
2657i8 }</tt>' type, another structure. The third index indexes into the second
2658element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an
Chris Lattner33fd7022004-04-05 01:30:49 +00002659array. The two dimensions of the array are subscripted into, yielding an
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002660'<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
2661to this element, thus computing a value of '<tt>i32*</tt>' type.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002662
Chris Lattner48b383b02003-11-25 01:02:51 +00002663<p>Note that it is perfectly legal to index partially through a
2664structure, returning a pointer to an inner element. Because of this,
2665the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002666
2667<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002668 define i32* %foo(%ST* %s) {
2669 %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i>
2670 %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i>
2671 %t3 = getelementptr %RT* %t2, i32 0, i32 1 <i>; yields [10 x [20 x i32]]*:%t3</i>
2672 %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i>
2673 %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i>
2674 ret i32* %t5
Chris Lattner33fd7022004-04-05 01:30:49 +00002675 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002676</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002677
2678<p>Note that it is undefined to access an array out of bounds: array and
2679pointer indexes must always be within the defined bounds of the array type.
2680The one exception for this rules is zero length arrays. These arrays are
2681defined to be accessible as variable length arrays, which requires access
2682beyond the zero'th element.</p>
2683
Chris Lattner6ab66722006-08-15 00:45:58 +00002684<p>The getelementptr instruction is often confusing. For some more insight
2685into how it works, see <a href="GetElementPtr.html">the getelementptr
2686FAQ</a>.</p>
2687
Chris Lattner590645f2002-04-14 06:13:44 +00002688<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002689
Chris Lattner33fd7022004-04-05 01:30:49 +00002690<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002691 <i>; yields [12 x i8]*:aptr</i>
2692 %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1
Chris Lattner33fd7022004-04-05 01:30:49 +00002693</pre>
Chris Lattner33fd7022004-04-05 01:30:49 +00002694</div>
Reid Spencer443460a2006-11-09 21:15:49 +00002695
Chris Lattner2f7c9632001-06-06 20:29:01 +00002696<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00002697<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00002698</div>
Misha Brukman76307852003-11-08 01:05:38 +00002699<div class="doc_text">
Reid Spencer97c5fa42006-11-08 01:18:52 +00002700<p>The instructions in this category are the conversion instructions (casting)
2701which all take a single operand and a type. They perform various bit conversions
2702on the operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002703</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002704
Chris Lattnera8292f32002-05-06 22:08:29 +00002705<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002706<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002707 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
2708</div>
2709<div class="doc_text">
2710
2711<h5>Syntax:</h5>
2712<pre>
2713 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2714</pre>
2715
2716<h5>Overview:</h5>
2717<p>
2718The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
2719</p>
2720
2721<h5>Arguments:</h5>
2722<p>
2723The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
2724be an <a href="#t_integer">integer</a> type, and a type that specifies the size
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002725and type of the result, which must be an <a href="#t_integer">integer</a>
Reid Spencer51b07252006-11-09 23:03:26 +00002726type. The bit size of <tt>value</tt> must be larger than the bit size of
2727<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002728
2729<h5>Semantics:</h5>
2730<p>
2731The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencer51b07252006-11-09 23:03:26 +00002732and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
2733larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
2734It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002735
2736<h5>Example:</h5>
2737<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002738 %X = trunc i32 257 to i8 <i>; yields i8:1</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002739 %Y = trunc i32 123 to i1 <i>; yields i1:true</i>
2740 %Y = trunc i32 122 to i1 <i>; yields i1:false</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002741</pre>
2742</div>
2743
2744<!-- _______________________________________________________________________ -->
2745<div class="doc_subsubsection">
2746 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
2747</div>
2748<div class="doc_text">
2749
2750<h5>Syntax:</h5>
2751<pre>
2752 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2753</pre>
2754
2755<h5>Overview:</h5>
2756<p>The '<tt>zext</tt>' instruction zero extends its operand to type
2757<tt>ty2</tt>.</p>
2758
2759
2760<h5>Arguments:</h5>
2761<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002762<a href="#t_integer">integer</a> type, and a type to cast it to, which must
2763also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00002764<tt>value</tt> must be smaller than the bit size of the destination type,
2765<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002766
2767<h5>Semantics:</h5>
2768<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
2769bits until it reaches the size of the destination type, <tt>ty2</tt>. When the
2770the operand and the type are the same size, no bit filling is done and the
2771cast is considered a <i>no-op cast</i> because no bits change (only the type
2772changes).</p>
2773
Reid Spencer07c9c682007-01-12 15:46:11 +00002774<p>When zero extending from i1, the result will always be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002775
2776<h5>Example:</h5>
2777<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002778 %X = zext i32 257 to i64 <i>; yields i64:257</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002779 %Y = zext i1 true to i32 <i>; yields i32:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002780</pre>
2781</div>
2782
2783<!-- _______________________________________________________________________ -->
2784<div class="doc_subsubsection">
2785 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
2786</div>
2787<div class="doc_text">
2788
2789<h5>Syntax:</h5>
2790<pre>
2791 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2792</pre>
2793
2794<h5>Overview:</h5>
2795<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
2796
2797<h5>Arguments:</h5>
2798<p>
2799The '<tt>sext</tt>' instruction takes a value to cast, which must be of
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002800<a href="#t_integer">integer</a> type, and a type to cast it to, which must
2801also be of <a href="#t_integer">integer</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00002802<tt>value</tt> must be smaller than the bit size of the destination type,
2803<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002804
2805<h5>Semantics:</h5>
2806<p>
2807The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
2808bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
2809the type <tt>ty2</tt>. When the the operand and the type are the same size,
2810no bit filling is done and the cast is considered a <i>no-op cast</i> because
2811no bits change (only the type changes).</p>
2812
Reid Spencer36a15422007-01-12 03:35:51 +00002813<p>When sign extending from i1, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002814
2815<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002816<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002817 %X = sext i8 -1 to i16 <i>; yields i16 :65535</i>
Reid Spencer36a15422007-01-12 03:35:51 +00002818 %Y = sext i1 true to i32 <i>; yields i32:-1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002819</pre>
2820</div>
2821
2822<!-- _______________________________________________________________________ -->
2823<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00002824 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
2825</div>
2826
2827<div class="doc_text">
2828
2829<h5>Syntax:</h5>
2830
2831<pre>
2832 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2833</pre>
2834
2835<h5>Overview:</h5>
2836<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
2837<tt>ty2</tt>.</p>
2838
2839
2840<h5>Arguments:</h5>
2841<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
2842 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
2843cast it to. The size of <tt>value</tt> must be larger than the size of
2844<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
2845<i>no-op cast</i>.</p>
2846
2847<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002848<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
2849<a href="#t_floating">floating point</a> type to a smaller
2850<a href="#t_floating">floating point</a> type. If the value cannot fit within
2851the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00002852
2853<h5>Example:</h5>
2854<pre>
2855 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
2856 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
2857</pre>
2858</div>
2859
2860<!-- _______________________________________________________________________ -->
2861<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002862 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
2863</div>
2864<div class="doc_text">
2865
2866<h5>Syntax:</h5>
2867<pre>
2868 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2869</pre>
2870
2871<h5>Overview:</h5>
2872<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
2873floating point value.</p>
2874
2875<h5>Arguments:</h5>
2876<p>The '<tt>fpext</tt>' instruction takes a
2877<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencer51b07252006-11-09 23:03:26 +00002878and a <a href="#t_floating">floating point</a> type to cast it to. The source
2879type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002880
2881<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002882<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
2883<a href="t_floating">floating point</a> type to a larger
2884<a href="t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
2885used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5b950642006-11-11 23:08:07 +00002886<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002887
2888<h5>Example:</h5>
2889<pre>
2890 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
2891 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
2892</pre>
2893</div>
2894
2895<!-- _______________________________________________________________________ -->
2896<div class="doc_subsubsection">
Reid Spencer2eadb532007-01-21 00:29:26 +00002897 <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002898</div>
2899<div class="doc_text">
2900
2901<h5>Syntax:</h5>
2902<pre>
2903 &lt;result&gt; = fp2uint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2904</pre>
2905
2906<h5>Overview:</h5>
2907<p>The '<tt>fp2uint</tt>' converts a floating point <tt>value</tt> to its
2908unsigned integer equivalent of type <tt>ty2</tt>.
2909</p>
2910
2911<h5>Arguments:</h5>
2912<p>The '<tt>fp2uint</tt>' instruction takes a value to cast, which must be a
2913<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002914must be an <a href="#t_integer">integer</a> type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002915
2916<h5>Semantics:</h5>
2917<p> The '<tt>fp2uint</tt>' instruction converts its
2918<a href="#t_floating">floating point</a> operand into the nearest (rounding
2919towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
2920the results are undefined.</p>
2921
Reid Spencer36a15422007-01-12 03:35:51 +00002922<p>When converting to i1, the conversion is done as a comparison against
2923zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
2924If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002925
2926<h5>Example:</h5>
2927<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00002928 %X = fp2uint double 123.0 to i32 <i>; yields i32:123</i>
2929 %Y = fp2uint float 1.0E+300 to i1 <i>; yields i1:true</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002930 %X = fp2uint float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002931</pre>
2932</div>
2933
2934<!-- _______________________________________________________________________ -->
2935<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002936 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002937</div>
2938<div class="doc_text">
2939
2940<h5>Syntax:</h5>
2941<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002942 &lt;result&gt; = fptosi &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002943</pre>
2944
2945<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002946<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002947<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002948</p>
2949
2950
Chris Lattnera8292f32002-05-06 22:08:29 +00002951<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002952<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002953<a href="#t_floating">floating point</a> value, and a type to cast it to, which
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002954must also be an <a href="#t_integer">integer</a> type.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002955
Chris Lattnera8292f32002-05-06 22:08:29 +00002956<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002957<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002958<a href="#t_floating">floating point</a> operand into the nearest (rounding
2959towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
2960the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002961
Reid Spencer36a15422007-01-12 03:35:51 +00002962<p>When converting to i1, the conversion is done as a comparison against
2963zero. If the <tt>value</tt> was zero, the i1 result will be <tt>false</tt>.
2964If the <tt>value</tt> was non-zero, the i1 result will be <tt>true</tt>.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002965
Chris Lattner70de6632001-07-09 00:26:23 +00002966<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002967<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00002968 %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i>
2969 %Y = fptosi float 1.0E-247 to i1 <i>; yields i1:true</i>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00002970 %X = fptosi float 1.04E+17 to i8 <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002971</pre>
2972</div>
2973
2974<!-- _______________________________________________________________________ -->
2975<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002976 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002977</div>
2978<div class="doc_text">
2979
2980<h5>Syntax:</h5>
2981<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002982 &lt;result&gt; = uitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002983</pre>
2984
2985<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002986<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002987integer and converts that value to the <tt>ty2</tt> type.</p>
2988
2989
2990<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002991<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattnerc0f423a2007-01-15 01:54:13 +00002992<a href="#t_integer">integer</a> value, and a type to cast it to, which must
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002993be a <a href="#t_floating">floating point</a> type.</p>
2994
2995<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002996<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002997integer quantity and converts it to the corresponding floating point value. If
2998the value cannot fit in the floating point value, the results are undefined.</p>
2999
3000
3001<h5>Example:</h5>
3002<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003003 %X = uitofp i32 257 to float <i>; yields float:257.0</i>
3004 %Y = uitofp i8 -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003005</pre>
3006</div>
3007
3008<!-- _______________________________________________________________________ -->
3009<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00003010 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003011</div>
3012<div class="doc_text">
3013
3014<h5>Syntax:</h5>
3015<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00003016 &lt;result&gt; = sitofp &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003017</pre>
3018
3019<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003020<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003021integer and converts that value to the <tt>ty2</tt> type.</p>
3022
3023<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003024<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be an
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003025<a href="#t_integer">integer</a> value, and a type to cast it to, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003026a <a href="#t_floating">floating point</a> type.</p>
3027
3028<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00003029<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003030integer quantity and converts it to the corresponding floating point value. If
3031the value cannot fit in the floating point value, the results are undefined.</p>
3032
3033<h5>Example:</h5>
3034<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003035 %X = sitofp i32 257 to float <i>; yields float:257.0</i>
3036 %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003037</pre>
3038</div>
3039
3040<!-- _______________________________________________________________________ -->
3041<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00003042 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
3043</div>
3044<div class="doc_text">
3045
3046<h5>Syntax:</h5>
3047<pre>
3048 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3049</pre>
3050
3051<h5>Overview:</h5>
3052<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3053the integer type <tt>ty2</tt>.</p>
3054
3055<h5>Arguments:</h5>
3056<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
3057must be a <a href="t_pointer">pointer</a> value, and a type to cast it to
3058<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3059
3060<h5>Semantics:</h5>
3061<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3062<tt>ty2</tt> by interpreting the pointer value as an integer and either
3063truncating or zero extending that value to the size of the integer type. If
3064<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3065<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
3066are the same size, then nothing is done (<i>no-op cast</i>).</p>
3067
3068<h5>Example:</h5>
3069<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003070 %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit</i>
3071 %Y = ptrtoint i32* %x to i64 <i>; yields zero extend on 32-bit</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003072</pre>
3073</div>
3074
3075<!-- _______________________________________________________________________ -->
3076<div class="doc_subsubsection">
3077 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3078</div>
3079<div class="doc_text">
3080
3081<h5>Syntax:</h5>
3082<pre>
3083 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3084</pre>
3085
3086<h5>Overview:</h5>
3087<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3088a pointer type, <tt>ty2</tt>.</p>
3089
3090<h5>Arguments:</h5>
3091<p>The '<tt>inttoptr</tt>' instruction takes an <a href="i_integer">integer</a>
3092value to cast, and a type to cast it to, which must be a
Anton Korobeynikova0554d92007-01-12 19:20:47 +00003093<a href="#t_pointer">pointer</a> type.
Reid Spencerb7344ff2006-11-11 21:00:47 +00003094
3095<h5>Semantics:</h5>
3096<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3097<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3098the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3099size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3100the size of a pointer then a zero extension is done. If they are the same size,
3101nothing is done (<i>no-op cast</i>).</p>
3102
3103<h5>Example:</h5>
3104<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003105 %X = inttoptr i32 255 to i32* <i>; yields zero extend on 64-bit</i>
3106 %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit </i>
3107 %Y = inttoptr i16 0 to i32* <i>; yields zero extend on 32-bit</i>
Reid Spencerb7344ff2006-11-11 21:00:47 +00003108</pre>
3109</div>
3110
3111<!-- _______________________________________________________________________ -->
3112<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00003113 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003114</div>
3115<div class="doc_text">
3116
3117<h5>Syntax:</h5>
3118<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00003119 &lt;result&gt; = bitcast &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003120</pre>
3121
3122<h5>Overview:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003123<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003124<tt>ty2</tt> without changing any bits.</p>
3125
3126<h5>Arguments:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003127<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003128a first class value, and a type to cast it to, which must also be a <a
3129 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
Reid Spencere3db84c2007-01-09 20:08:58 +00003130and the destination type, <tt>ty2</tt>, must be identical. If the source
3131type is a pointer, the destination type must also be a pointer.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003132
3133<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003134<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencerb7344ff2006-11-11 21:00:47 +00003135<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3136this conversion. The conversion is done as if the <tt>value</tt> had been
3137stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3138converted to other pointer types with this instruction. To convert pointers to
3139other types, use the <a href="#i_inttoptr">inttoptr</a> or
3140<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003141
3142<h5>Example:</h5>
3143<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003144 %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i>
3145 %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i>
3146 %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00003147</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003148</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003149
Reid Spencer97c5fa42006-11-08 01:18:52 +00003150<!-- ======================================================================= -->
3151<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3152<div class="doc_text">
3153<p>The instructions in this category are the "miscellaneous"
3154instructions, which defy better classification.</p>
3155</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003156
3157<!-- _______________________________________________________________________ -->
3158<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3159</div>
3160<div class="doc_text">
3161<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00003162<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3163<i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003164</pre>
3165<h5>Overview:</h5>
3166<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3167of its two integer operands.</p>
3168<h5>Arguments:</h5>
3169<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
3170the condition code which indicates the kind of comparison to perform. It is not
3171a value, just a keyword. The possibilities for the condition code are:
3172<ol>
3173 <li><tt>eq</tt>: equal</li>
3174 <li><tt>ne</tt>: not equal </li>
3175 <li><tt>ugt</tt>: unsigned greater than</li>
3176 <li><tt>uge</tt>: unsigned greater or equal</li>
3177 <li><tt>ult</tt>: unsigned less than</li>
3178 <li><tt>ule</tt>: unsigned less or equal</li>
3179 <li><tt>sgt</tt>: signed greater than</li>
3180 <li><tt>sge</tt>: signed greater or equal</li>
3181 <li><tt>slt</tt>: signed less than</li>
3182 <li><tt>sle</tt>: signed less or equal</li>
3183</ol>
Chris Lattnerc0f423a2007-01-15 01:54:13 +00003184<p>The remaining two arguments must be <a href="#t_integer">integer</a> or
Reid Spencer784ef792007-01-04 05:19:58 +00003185<a href="#t_pointer">pointer</a> typed. They must also be identical types.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003186<h5>Semantics:</h5>
3187<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3188the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003189yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003190<ol>
3191 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3192 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3193 </li>
3194 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3195 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3196 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3197 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3198 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3199 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3200 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3201 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3202 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3203 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3204 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3205 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3206 <li><tt>sge</tt>: interprets the operands as signed values and yields
3207 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3208 <li><tt>slt</tt>: interprets the operands as signed values and yields
3209 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3210 <li><tt>sle</tt>: interprets the operands as signed values and yields
3211 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003212</ol>
3213<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
3214values are treated as integers and then compared.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003215
3216<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003217<pre> &lt;result&gt; = icmp eq i32 4, 5 <i>; yields: result=false</i>
3218 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3219 &lt;result&gt; = icmp ult i16 4, 5 <i>; yields: result=true</i>
3220 &lt;result&gt; = icmp sgt i16 4, 5 <i>; yields: result=false</i>
3221 &lt;result&gt; = icmp ule i16 -4, 5 <i>; yields: result=false</i>
3222 &lt;result&gt; = icmp sge i16 4, 5 <i>; yields: result=false</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003223</pre>
3224</div>
3225
3226<!-- _______________________________________________________________________ -->
3227<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3228</div>
3229<div class="doc_text">
3230<h5>Syntax:</h5>
Reid Spencer36a15422007-01-12 03:35:51 +00003231<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt;
3232<i>; yields {i1}:result</i>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003233</pre>
3234<h5>Overview:</h5>
3235<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3236of its floating point operands.</p>
3237<h5>Arguments:</h5>
3238<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
3239the condition code which indicates the kind of comparison to perform. It is not
3240a value, just a keyword. The possibilities for the condition code are:
3241<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00003242 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003243 <li><tt>oeq</tt>: ordered and equal</li>
3244 <li><tt>ogt</tt>: ordered and greater than </li>
3245 <li><tt>oge</tt>: ordered and greater than or equal</li>
3246 <li><tt>olt</tt>: ordered and less than </li>
3247 <li><tt>ole</tt>: ordered and less than or equal</li>
3248 <li><tt>one</tt>: ordered and not equal</li>
3249 <li><tt>ord</tt>: ordered (no nans)</li>
3250 <li><tt>ueq</tt>: unordered or equal</li>
3251 <li><tt>ugt</tt>: unordered or greater than </li>
3252 <li><tt>uge</tt>: unordered or greater than or equal</li>
3253 <li><tt>ult</tt>: unordered or less than </li>
3254 <li><tt>ule</tt>: unordered or less than or equal</li>
3255 <li><tt>une</tt>: unordered or not equal</li>
3256 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003257 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003258</ol>
Reid Spencer02e0d1d2006-12-06 07:08:07 +00003259<p>In the preceding, <i>ordered</i> means that neither operand is a QNAN while
3260<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencer784ef792007-01-04 05:19:58 +00003261<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be
3262<a href="#t_floating">floating point</a> typed. They must have identical
3263types.</p>
Reid Spencerf69acf32006-11-19 03:00:14 +00003264<p>In the foregoing, <i>ordered</i> means that neither operand is a QNAN and
3265<i>unordered</i> means that either operand is a QNAN.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003266<h5>Semantics:</h5>
3267<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3268the condition code given as <tt>cond</tt>. The comparison performed always
Reid Spencer36a15422007-01-12 03:35:51 +00003269yields a <a href="#t_primitive">i1</a> result, as follows:
Reid Spencerc828a0e2006-11-18 21:50:54 +00003270<ol>
3271 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003272 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003273 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003274 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003275 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003276 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003277 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003278 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003279 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003280 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003281 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003282 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003283 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003284 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3285 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003286 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003287 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003288 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003289 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003290 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003291 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003292 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003293 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003294 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003295 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003296 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003297 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003298 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3299</ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003300
3301<h5>Example:</h5>
3302<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3303 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3304 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3305 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3306</pre>
3307</div>
3308
Reid Spencer97c5fa42006-11-08 01:18:52 +00003309<!-- _______________________________________________________________________ -->
3310<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3311Instruction</a> </div>
3312<div class="doc_text">
3313<h5>Syntax:</h5>
3314<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3315<h5>Overview:</h5>
3316<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3317the SSA graph representing the function.</p>
3318<h5>Arguments:</h5>
3319<p>The type of the incoming values are specified with the first type
3320field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3321as arguments, with one pair for each predecessor basic block of the
3322current block. Only values of <a href="#t_firstclass">first class</a>
3323type may be used as the value arguments to the PHI node. Only labels
3324may be used as the label arguments.</p>
3325<p>There must be no non-phi instructions between the start of a basic
3326block and the PHI instructions: i.e. PHI instructions must be first in
3327a basic block.</p>
3328<h5>Semantics:</h5>
3329<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
3330value specified by the parameter, depending on which basic block we
3331came from in the last <a href="#terminators">terminator</a> instruction.</p>
3332<h5>Example:</h5>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003333<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add i32 %indvar, 1<br> br label %Loop<br></pre>
Reid Spencer97c5fa42006-11-08 01:18:52 +00003334</div>
3335
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003336<!-- _______________________________________________________________________ -->
3337<div class="doc_subsubsection">
3338 <a name="i_select">'<tt>select</tt>' Instruction</a>
3339</div>
3340
3341<div class="doc_text">
3342
3343<h5>Syntax:</h5>
3344
3345<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003346 &lt;result&gt; = select i1 &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003347</pre>
3348
3349<h5>Overview:</h5>
3350
3351<p>
3352The '<tt>select</tt>' instruction is used to choose one value based on a
3353condition, without branching.
3354</p>
3355
3356
3357<h5>Arguments:</h5>
3358
3359<p>
3360The '<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.
3361</p>
3362
3363<h5>Semantics:</h5>
3364
3365<p>
3366If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00003367value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003368</p>
3369
3370<h5>Example:</h5>
3371
3372<pre>
Reid Spencer36a15422007-01-12 03:35:51 +00003373 %X = select i1 true, i8 17, i8 42 <i>; yields i8:17</i>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003374</pre>
3375</div>
3376
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00003377
3378<!-- _______________________________________________________________________ -->
3379<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00003380 <a name="i_call">'<tt>call</tt>' Instruction</a>
3381</div>
3382
Misha Brukman76307852003-11-08 01:05:38 +00003383<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00003384
Chris Lattner2f7c9632001-06-06 20:29:01 +00003385<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003386<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00003387 &lt;result&gt; = [tail] call [<a href="#callingconv">cconv</a>] &lt;ty&gt;* &lt;fnptrval&gt;(&lt;param list&gt;)
Chris Lattnere23c1392005-05-06 05:47:36 +00003388</pre>
3389
Chris Lattner2f7c9632001-06-06 20:29:01 +00003390<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003391
Misha Brukman76307852003-11-08 01:05:38 +00003392<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003393
Chris Lattner2f7c9632001-06-06 20:29:01 +00003394<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003395
Misha Brukman76307852003-11-08 01:05:38 +00003396<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003397
Chris Lattnera8292f32002-05-06 22:08:29 +00003398<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00003399 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003400 <p>The optional "tail" marker indicates whether the callee function accesses
3401 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00003402 function call is eligible for tail call optimization. Note that calls may
3403 be marked "tail" even if they do not occur before a <a
3404 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00003405 </li>
3406 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003407 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
3408 convention</a> the call should use. If none is specified, the call defaults
3409 to using C calling conventions.
3410 </li>
3411 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00003412 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
3413 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00003414 signature. This type can be omitted if the function is not varargs and
3415 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003416 </li>
3417 <li>
3418 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3419 be invoked. In most cases, this is a direct function invocation, but
3420 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00003421 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003422 </li>
3423 <li>
3424 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00003425 function signature argument types. All arguments must be of
3426 <a href="#t_firstclass">first class</a> type. If the function signature
3427 indicates the function accepts a variable number of arguments, the extra
3428 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003429 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00003430</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00003431
Chris Lattner2f7c9632001-06-06 20:29:01 +00003432<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003433
Chris Lattner48b383b02003-11-25 01:02:51 +00003434<p>The '<tt>call</tt>' instruction is used to cause control flow to
3435transfer to a specified function, with its incoming arguments bound to
3436the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3437instruction in the called function, control flow continues with the
3438instruction after the function call, and the return value of the
3439function is bound to the result argument. This is a simpler case of
3440the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003441
Chris Lattner2f7c9632001-06-06 20:29:01 +00003442<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003443
3444<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003445 %retval = call i32 %test(i32 %argc)
3446 call i32(i8 *, ...) *%printf(i8 * %msg, i32 12, i8 42);
3447 %X = tail call i32 %foo()
3448 %Y = tail call <a href="#callingconv">fastcc</a> i32 %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00003449</pre>
3450
Misha Brukman76307852003-11-08 01:05:38 +00003451</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003452
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003453<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00003454<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00003455 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003456</div>
3457
Misha Brukman76307852003-11-08 01:05:38 +00003458<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00003459
Chris Lattner26ca62e2003-10-18 05:51:36 +00003460<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003461
3462<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003463 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00003464</pre>
3465
Chris Lattner26ca62e2003-10-18 05:51:36 +00003466<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003467
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003468<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00003469the "variable argument" area of a function call. It is used to implement the
3470<tt>va_arg</tt> macro in C.</p>
3471
Chris Lattner26ca62e2003-10-18 05:51:36 +00003472<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003473
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003474<p>This instruction takes a <tt>va_list*</tt> value and the type of
3475the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00003476increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003477actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003478
Chris Lattner26ca62e2003-10-18 05:51:36 +00003479<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003480
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003481<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3482type from the specified <tt>va_list</tt> and causes the
3483<tt>va_list</tt> to point to the next argument. For more information,
3484see the variable argument handling <a href="#int_varargs">Intrinsic
3485Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003486
3487<p>It is legal for this instruction to be called in a function which does not
3488take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00003489function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003490
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003491<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00003492href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00003493argument.</p>
3494
Chris Lattner26ca62e2003-10-18 05:51:36 +00003495<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003496
3497<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3498
Misha Brukman76307852003-11-08 01:05:38 +00003499</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003500
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003501<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003502<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3503<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00003504
Misha Brukman76307852003-11-08 01:05:38 +00003505<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00003506
3507<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswell88190562005-05-16 16:17:45 +00003508well known names and semantics and are required to follow certain
Chris Lattnerfee11462004-02-12 17:01:32 +00003509restrictions. Overall, these instructions represent an extension mechanism for
3510the LLVM language that does not require changing all of the transformations in
3511LLVM to add to the language (or the bytecode reader/writer, the parser,
3512etc...).</p>
3513
John Criswell88190562005-05-16 16:17:45 +00003514<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
3515prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00003516this. Intrinsic functions must always be external functions: you cannot define
3517the body of intrinsic functions. Intrinsic functions may only be used in call
3518or invoke instructions: it is illegal to take the address of an intrinsic
3519function. Additionally, because intrinsic functions are part of the LLVM
3520language, it is required that they all be documented here if any are added.</p>
3521
3522
John Criswell88190562005-05-16 16:17:45 +00003523<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner90391c12005-05-11 03:35:57 +00003524href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00003525</p>
3526
Misha Brukman76307852003-11-08 01:05:38 +00003527</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003528
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003529<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00003530<div class="doc_subsection">
3531 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3532</div>
3533
Misha Brukman76307852003-11-08 01:05:38 +00003534<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003535
Misha Brukman76307852003-11-08 01:05:38 +00003536<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00003537 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00003538intrinsic functions. These functions are related to the similarly
3539named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003540
Chris Lattner48b383b02003-11-25 01:02:51 +00003541<p>All of these functions operate on arguments that use a
3542target-specific value type "<tt>va_list</tt>". The LLVM assembly
3543language reference manual does not define what this type is, so all
3544transformations should be prepared to handle intrinsics with any type
3545used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003546
Chris Lattner30b868d2006-05-15 17:26:46 +00003547<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00003548instruction and the variable argument handling intrinsic functions are
3549used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003550
Chris Lattnerfee11462004-02-12 17:01:32 +00003551<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003552define i32 %test(i32 %X, ...) {
Chris Lattnerfee11462004-02-12 17:01:32 +00003553 ; Initialize variable argument processing
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003554 %ap = alloca i8 *
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003555 %ap2 = bitcast i8** %ap to i8*
3556 call void %<a href="#i_va_start">llvm.va_start</a>(i8* %ap2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003557
3558 ; Read a single integer argument
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003559 %tmp = va_arg i8 ** %ap, i32
Chris Lattnerfee11462004-02-12 17:01:32 +00003560
3561 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003562 %aq = alloca i8 *
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003563 %aq2 = bitcast i8** %aq to i8*
3564 call void %<a href="#i_va_copy">llvm.va_copy</a>(i8 *%aq2, i8* %ap2)
3565 call void %<a href="#i_va_end">llvm.va_end</a>(i8* %aq2)
Chris Lattnerfee11462004-02-12 17:01:32 +00003566
3567 ; Stop processing of arguments.
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003568 call void %<a href="#i_va_end">llvm.va_end</a>(i8* %ap2)
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003569 ret i32 %tmp
Chris Lattnerfee11462004-02-12 17:01:32 +00003570}
3571</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003572</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003573
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003574<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003575<div class="doc_subsubsection">
3576 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
3577</div>
3578
3579
Misha Brukman76307852003-11-08 01:05:38 +00003580<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003581<h5>Syntax:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003582<pre> declare void %llvm.va_start(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003583<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003584<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3585<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3586href="#i_va_arg">va_arg</a></tt>.</p>
3587
3588<h5>Arguments:</h5>
3589
3590<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3591
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003592<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003593
3594<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3595macro available in C. In a target-dependent way, it initializes the
3596<tt>va_list</tt> element the argument points to, so that the next call to
3597<tt>va_arg</tt> will produce the first variable argument passed to the function.
3598Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
3599last argument of the function, the compiler can figure that out.</p>
3600
Misha Brukman76307852003-11-08 01:05:38 +00003601</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003602
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003603<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003604<div class="doc_subsubsection">
3605 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
3606</div>
3607
Misha Brukman76307852003-11-08 01:05:38 +00003608<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003609<h5>Syntax:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003610<pre> declare void %llvm.va_end(i8* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003611<h5>Overview:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003612
Chris Lattner48b383b02003-11-25 01:02:51 +00003613<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
3614which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
3615or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003616
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003617<h5>Arguments:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003618
Misha Brukman76307852003-11-08 01:05:38 +00003619<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003620
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003621<h5>Semantics:</h5>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003622
Misha Brukman76307852003-11-08 01:05:38 +00003623<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00003624macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
3625Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
3626 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
3627with calls to <tt>llvm.va_end</tt>.</p>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003628
Misha Brukman76307852003-11-08 01:05:38 +00003629</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003630
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003631<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003632<div class="doc_subsubsection">
3633 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
3634</div>
3635
Misha Brukman76307852003-11-08 01:05:38 +00003636<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003637
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003638<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003639
3640<pre>
Chris Lattnerdb0790c2007-01-08 07:55:15 +00003641 declare void %llvm.va_copy(i8* &lt;destarglist&gt;, i8* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003642</pre>
3643
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003644<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003645
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003646<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
3647the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003648
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003649<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003650
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003651<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00003652The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003653
Chris Lattner757528b0b2004-05-23 21:06:01 +00003654
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003655<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003656
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003657<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
3658available in C. In a target-dependent way, it copies the source
3659<tt>va_list</tt> element into the destination list. This intrinsic is necessary
3660because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00003661arbitrarily complex and require memory allocation, for example.</p>
3662
Misha Brukman76307852003-11-08 01:05:38 +00003663</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003664
Chris Lattnerfee11462004-02-12 17:01:32 +00003665<!-- ======================================================================= -->
3666<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003667 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
3668</div>
3669
3670<div class="doc_text">
3671
3672<p>
3673LLVM support for <a href="GarbageCollection.html">Accurate Garbage
3674Collection</a> requires the implementation and generation of these intrinsics.
3675These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
3676stack</a>, as well as garbage collector implementations that require <a
3677href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
3678Front-ends for type-safe garbage collected languages should generate these
3679intrinsics to make use of the LLVM garbage collectors. For more details, see <a
3680href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
3681</p>
3682</div>
3683
3684<!-- _______________________________________________________________________ -->
3685<div class="doc_subsubsection">
3686 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
3687</div>
3688
3689<div class="doc_text">
3690
3691<h5>Syntax:</h5>
3692
3693<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003694 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003695</pre>
3696
3697<h5>Overview:</h5>
3698
John Criswelldfe6a862004-12-10 15:51:16 +00003699<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00003700the code generator, and allows some metadata to be associated with it.</p>
3701
3702<h5>Arguments:</h5>
3703
3704<p>The first argument specifies the address of a stack object that contains the
3705root pointer. The second pointer (which must be either a constant or a global
3706value address) contains the meta-data to be associated with the root.</p>
3707
3708<h5>Semantics:</h5>
3709
3710<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
3711location. At compile-time, the code generator generates information to allow
3712the runtime to find the pointer at GC safe points.
3713</p>
3714
3715</div>
3716
3717
3718<!-- _______________________________________________________________________ -->
3719<div class="doc_subsubsection">
3720 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
3721</div>
3722
3723<div class="doc_text">
3724
3725<h5>Syntax:</h5>
3726
3727<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003728 declare i8 * %llvm.gcread(i8 * %ObjPtr, i8 ** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003729</pre>
3730
3731<h5>Overview:</h5>
3732
3733<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3734locations, allowing garbage collector implementations that require read
3735barriers.</p>
3736
3737<h5>Arguments:</h5>
3738
Chris Lattnerf9228072006-03-14 20:02:51 +00003739<p>The second argument is the address to read from, which should be an address
3740allocated from the garbage collector. The first object is a pointer to the
3741start of the referenced object, if needed by the language runtime (otherwise
3742null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003743
3744<h5>Semantics:</h5>
3745
3746<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3747instruction, but may be replaced with substantially more complex code by the
3748garbage collector runtime, as needed.</p>
3749
3750</div>
3751
3752
3753<!-- _______________________________________________________________________ -->
3754<div class="doc_subsubsection">
3755 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
3756</div>
3757
3758<div class="doc_text">
3759
3760<h5>Syntax:</h5>
3761
3762<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003763 declare void %llvm.gcwrite(i8 * %P1, i8 * %Obj, i8 ** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003764</pre>
3765
3766<h5>Overview:</h5>
3767
3768<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3769locations, allowing garbage collector implementations that require write
3770barriers (such as generational or reference counting collectors).</p>
3771
3772<h5>Arguments:</h5>
3773
Chris Lattnerf9228072006-03-14 20:02:51 +00003774<p>The first argument is the reference to store, the second is the start of the
3775object to store it to, and the third is the address of the field of Obj to
3776store to. If the runtime does not require a pointer to the object, Obj may be
3777null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003778
3779<h5>Semantics:</h5>
3780
3781<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3782instruction, but may be replaced with substantially more complex code by the
3783garbage collector runtime, as needed.</p>
3784
3785</div>
3786
3787
3788
3789<!-- ======================================================================= -->
3790<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00003791 <a name="int_codegen">Code Generator Intrinsics</a>
3792</div>
3793
3794<div class="doc_text">
3795<p>
3796These intrinsics are provided by LLVM to expose special features that may only
3797be implemented with code generator support.
3798</p>
3799
3800</div>
3801
3802<!-- _______________________________________________________________________ -->
3803<div class="doc_subsubsection">
3804 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
3805</div>
3806
3807<div class="doc_text">
3808
3809<h5>Syntax:</h5>
3810<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003811 declare i8 *%llvm.returnaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003812</pre>
3813
3814<h5>Overview:</h5>
3815
3816<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003817The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
3818target-specific value indicating the return address of the current function
3819or one of its callers.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003820</p>
3821
3822<h5>Arguments:</h5>
3823
3824<p>
3825The argument to this intrinsic indicates which function to return the address
3826for. Zero indicates the calling function, one indicates its caller, etc. The
3827argument is <b>required</b> to be a constant integer value.
3828</p>
3829
3830<h5>Semantics:</h5>
3831
3832<p>
3833The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3834the return address of the specified call frame, or zero if it cannot be
3835identified. The value returned by this intrinsic is likely to be incorrect or 0
3836for arguments other than zero, so it should only be used for debugging purposes.
3837</p>
3838
3839<p>
3840Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003841aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003842source-language caller.
3843</p>
3844</div>
3845
3846
3847<!-- _______________________________________________________________________ -->
3848<div class="doc_subsubsection">
3849 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
3850</div>
3851
3852<div class="doc_text">
3853
3854<h5>Syntax:</h5>
3855<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003856 declare i8 *%llvm.frameaddress(i32 &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003857</pre>
3858
3859<h5>Overview:</h5>
3860
3861<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003862The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
3863target-specific frame pointer value for the specified stack frame.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003864</p>
3865
3866<h5>Arguments:</h5>
3867
3868<p>
3869The argument to this intrinsic indicates which function to return the frame
3870pointer for. Zero indicates the calling function, one indicates its caller,
3871etc. The argument is <b>required</b> to be a constant integer value.
3872</p>
3873
3874<h5>Semantics:</h5>
3875
3876<p>
3877The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3878the frame address of the specified call frame, or zero if it cannot be
3879identified. The value returned by this intrinsic is likely to be incorrect or 0
3880for arguments other than zero, so it should only be used for debugging purposes.
3881</p>
3882
3883<p>
3884Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003885aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003886source-language caller.
3887</p>
3888</div>
3889
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003890<!-- _______________________________________________________________________ -->
3891<div class="doc_subsubsection">
Chris Lattner2f0f0012006-01-13 02:03:13 +00003892 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
3893</div>
3894
3895<div class="doc_text">
3896
3897<h5>Syntax:</h5>
3898<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003899 declare i8 *%llvm.stacksave()
Chris Lattner2f0f0012006-01-13 02:03:13 +00003900</pre>
3901
3902<h5>Overview:</h5>
3903
3904<p>
3905The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
3906the function stack, for use with <a href="#i_stackrestore">
3907<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
3908features like scoped automatic variable sized arrays in C99.
3909</p>
3910
3911<h5>Semantics:</h5>
3912
3913<p>
3914This intrinsic returns a opaque pointer value that can be passed to <a
3915href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
3916<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
3917<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
3918state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
3919practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
3920that were allocated after the <tt>llvm.stacksave</tt> was executed.
3921</p>
3922
3923</div>
3924
3925<!-- _______________________________________________________________________ -->
3926<div class="doc_subsubsection">
3927 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
3928</div>
3929
3930<div class="doc_text">
3931
3932<h5>Syntax:</h5>
3933<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003934 declare void %llvm.stackrestore(i8 * %ptr)
Chris Lattner2f0f0012006-01-13 02:03:13 +00003935</pre>
3936
3937<h5>Overview:</h5>
3938
3939<p>
3940The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
3941the function stack to the state it was in when the corresponding <a
3942href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
3943useful for implementing language features like scoped automatic variable sized
3944arrays in C99.
3945</p>
3946
3947<h5>Semantics:</h5>
3948
3949<p>
3950See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
3951</p>
3952
3953</div>
3954
3955
3956<!-- _______________________________________________________________________ -->
3957<div class="doc_subsubsection">
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003958 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
3959</div>
3960
3961<div class="doc_text">
3962
3963<h5>Syntax:</h5>
3964<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00003965 declare void %llvm.prefetch(i8 * &lt;address&gt;,
3966 i32 &lt;rw&gt;, i32 &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003967</pre>
3968
3969<h5>Overview:</h5>
3970
3971
3972<p>
3973The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00003974a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
3975no
3976effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00003977characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003978</p>
3979
3980<h5>Arguments:</h5>
3981
3982<p>
3983<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
3984determining if the fetch should be for a read (0) or write (1), and
3985<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00003986locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003987<tt>locality</tt> arguments must be constant integers.
3988</p>
3989
3990<h5>Semantics:</h5>
3991
3992<p>
3993This intrinsic does not modify the behavior of the program. In particular,
3994prefetches cannot trap and do not produce a value. On targets that support this
3995intrinsic, the prefetch can provide hints to the processor cache for better
3996performance.
3997</p>
3998
3999</div>
4000
Andrew Lenharthb4427912005-03-28 20:05:49 +00004001<!-- _______________________________________________________________________ -->
4002<div class="doc_subsubsection">
4003 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
4004</div>
4005
4006<div class="doc_text">
4007
4008<h5>Syntax:</h5>
4009<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004010 declare void %llvm.pcmarker( i32 &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00004011</pre>
4012
4013<h5>Overview:</h5>
4014
4015
4016<p>
John Criswell88190562005-05-16 16:17:45 +00004017The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
4018(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00004019code to simulators and other tools. The method is target specific, but it is
4020expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00004021The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnere64d41d2005-11-15 06:07:55 +00004022after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb40261e2006-03-24 07:16:10 +00004023optimizations. The intended use is to be inserted after optimizations to allow
John Criswell88190562005-05-16 16:17:45 +00004024correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00004025</p>
4026
4027<h5>Arguments:</h5>
4028
4029<p>
4030<tt>id</tt> is a numerical id identifying the marker.
4031</p>
4032
4033<h5>Semantics:</h5>
4034
4035<p>
4036This intrinsic does not modify the behavior of the program. Backends that do not
4037support this intrinisic may ignore it.
4038</p>
4039
4040</div>
4041
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004042<!-- _______________________________________________________________________ -->
4043<div class="doc_subsubsection">
4044 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
4045</div>
4046
4047<div class="doc_text">
4048
4049<h5>Syntax:</h5>
4050<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004051 declare i64 %llvm.readcyclecounter( )
Andrew Lenharth01aa5632005-11-11 16:47:30 +00004052</pre>
4053
4054<h5>Overview:</h5>
4055
4056
4057<p>
4058The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4059counter register (or similar low latency, high accuracy clocks) on those targets
4060that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4061As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4062should only be used for small timings.
4063</p>
4064
4065<h5>Semantics:</h5>
4066
4067<p>
4068When directly supported, reading the cycle counter should not modify any memory.
4069Implementations are allowed to either return a application specific value or a
4070system wide value. On backends without support, this is lowered to a constant 0.
4071</p>
4072
4073</div>
4074
Chris Lattner3649c3a2004-02-14 04:08:35 +00004075<!-- ======================================================================= -->
4076<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00004077 <a name="int_libc">Standard C Library Intrinsics</a>
4078</div>
4079
4080<div class="doc_text">
4081<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004082LLVM provides intrinsics for a few important standard C library functions.
4083These intrinsics allow source-language front-ends to pass information about the
4084alignment of the pointer arguments to the code generator, providing opportunity
4085for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00004086</p>
4087
4088</div>
4089
4090<!-- _______________________________________________________________________ -->
4091<div class="doc_subsubsection">
4092 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
4093</div>
4094
4095<div class="doc_text">
4096
4097<h5>Syntax:</h5>
4098<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004099 declare void %llvm.memcpy.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4100 i32 &lt;len&gt;, i32 &lt;align&gt;)
4101 declare void %llvm.memcpy.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4102 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00004103</pre>
4104
4105<h5>Overview:</h5>
4106
4107<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004108The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004109location to the destination location.
4110</p>
4111
4112<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004113Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4114intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00004115</p>
4116
4117<h5>Arguments:</h5>
4118
4119<p>
4120The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004121the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00004122specifying the number of bytes to copy, and the fourth argument is the alignment
4123of the source and destination locations.
4124</p>
4125
Chris Lattner4c67c482004-02-12 21:18:15 +00004126<p>
4127If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004128the caller guarantees that both the source and destination pointers are aligned
4129to that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004130</p>
4131
Chris Lattnerfee11462004-02-12 17:01:32 +00004132<h5>Semantics:</h5>
4133
4134<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004135The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004136location to the destination location, which are not allowed to overlap. It
4137copies "len" bytes of memory over. If the argument is known to be aligned to
4138some boundary, this can be specified as the fourth argument, otherwise it should
4139be set to 0 or 1.
4140</p>
4141</div>
4142
4143
Chris Lattnerf30152e2004-02-12 18:10:10 +00004144<!-- _______________________________________________________________________ -->
4145<div class="doc_subsubsection">
4146 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
4147</div>
4148
4149<div class="doc_text">
4150
4151<h5>Syntax:</h5>
4152<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004153 declare void %llvm.memmove.i32(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4154 i32 &lt;len&gt;, i32 &lt;align&gt;)
4155 declare void %llvm.memmove.i64(i8 * &lt;dest&gt;, i8 * &lt;src&gt;,
4156 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00004157</pre>
4158
4159<h5>Overview:</h5>
4160
4161<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004162The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4163location to the destination location. It is similar to the
4164'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004165</p>
4166
4167<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004168Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4169intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004170</p>
4171
4172<h5>Arguments:</h5>
4173
4174<p>
4175The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004176the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00004177specifying the number of bytes to copy, and the fourth argument is the alignment
4178of the source and destination locations.
4179</p>
4180
Chris Lattner4c67c482004-02-12 21:18:15 +00004181<p>
4182If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004183the caller guarantees that the source and destination pointers are aligned to
4184that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004185</p>
4186
Chris Lattnerf30152e2004-02-12 18:10:10 +00004187<h5>Semantics:</h5>
4188
4189<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004190The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00004191location to the destination location, which may overlap. It
4192copies "len" bytes of memory over. If the argument is known to be aligned to
4193some boundary, this can be specified as the fourth argument, otherwise it should
4194be set to 0 or 1.
4195</p>
4196</div>
4197
Chris Lattner941515c2004-01-06 05:31:32 +00004198
Chris Lattner3649c3a2004-02-14 04:08:35 +00004199<!-- _______________________________________________________________________ -->
4200<div class="doc_subsubsection">
Chris Lattner0c8b2592006-03-03 00:07:20 +00004201 <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004202</div>
4203
4204<div class="doc_text">
4205
4206<h5>Syntax:</h5>
4207<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004208 declare void %llvm.memset.i32(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
4209 i32 &lt;len&gt;, i32 &lt;align&gt;)
4210 declare void %llvm.memset.i64(i8 * &lt;dest&gt;, i8 &lt;val&gt;,
4211 i64 &lt;len&gt;, i32 &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004212</pre>
4213
4214<h5>Overview:</h5>
4215
4216<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004217The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00004218byte value.
4219</p>
4220
4221<p>
4222Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4223does not return a value, and takes an extra alignment argument.
4224</p>
4225
4226<h5>Arguments:</h5>
4227
4228<p>
4229The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00004230byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00004231argument specifying the number of bytes to fill, and the fourth argument is the
4232known alignment of destination location.
4233</p>
4234
4235<p>
4236If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004237the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004238</p>
4239
4240<h5>Semantics:</h5>
4241
4242<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004243The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4244the
Chris Lattner3649c3a2004-02-14 04:08:35 +00004245destination location. If the argument is known to be aligned to some boundary,
4246this can be specified as the fourth argument, otherwise it should be set to 0 or
42471.
4248</p>
4249</div>
4250
4251
Chris Lattner3b4f4372004-06-11 02:28:03 +00004252<!-- _______________________________________________________________________ -->
4253<div class="doc_subsubsection">
Chris Lattner069b5bd2006-01-16 22:38:59 +00004254 <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004255</div>
4256
4257<div class="doc_text">
4258
4259<h5>Syntax:</h5>
4260<pre>
Chris Lattner33b73f92006-09-08 06:34:02 +00004261 declare float %llvm.sqrt.f32(float %Val)
4262 declare double %llvm.sqrt.f64(double %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004263</pre>
4264
4265<h5>Overview:</h5>
4266
4267<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004268The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004269returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
4270<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
4271negative numbers (which allows for better optimization).
4272</p>
4273
4274<h5>Arguments:</h5>
4275
4276<p>
4277The argument and return value are floating point numbers of the same type.
4278</p>
4279
4280<h5>Semantics:</h5>
4281
4282<p>
4283This function returns the sqrt of the specified operand if it is a positive
4284floating point number.
4285</p>
4286</div>
4287
Chris Lattner33b73f92006-09-08 06:34:02 +00004288<!-- _______________________________________________________________________ -->
4289<div class="doc_subsubsection">
4290 <a name="i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
4291</div>
4292
4293<div class="doc_text">
4294
4295<h5>Syntax:</h5>
4296<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004297 declare float %llvm.powi.f32(float %Val, i32 %power)
4298 declare double %llvm.powi.f64(double %Val, i32 %power)
Chris Lattner33b73f92006-09-08 06:34:02 +00004299</pre>
4300
4301<h5>Overview:</h5>
4302
4303<p>
4304The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4305specified (positive or negative) power. The order of evaluation of
4306multiplications is not defined.
4307</p>
4308
4309<h5>Arguments:</h5>
4310
4311<p>
4312The second argument is an integer power, and the first is a value to raise to
4313that power.
4314</p>
4315
4316<h5>Semantics:</h5>
4317
4318<p>
4319This function returns the first value raised to the second power with an
4320unspecified sequence of rounding operations.</p>
4321</div>
4322
4323
Andrew Lenharth1d463522005-05-03 18:01:48 +00004324<!-- ======================================================================= -->
4325<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004326 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004327</div>
4328
4329<div class="doc_text">
4330<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004331LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004332These allow efficient code generation for some algorithms.
4333</p>
4334
4335</div>
4336
4337<!-- _______________________________________________________________________ -->
4338<div class="doc_subsubsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004339 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
4340</div>
4341
4342<div class="doc_text">
4343
4344<h5>Syntax:</h5>
4345<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004346 declare i16 %llvm.bswap.i16(i16 &lt;id&gt;)
4347 declare i32 %llvm.bswap.i32(i32 &lt;id&gt;)
4348 declare i64 %llvm.bswap.i64(i64 &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00004349</pre>
4350
4351<h5>Overview:</h5>
4352
4353<p>
4354The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
435564 bit quantity. These are useful for performing operations on data that is not
4356in the target's native byte order.
4357</p>
4358
4359<h5>Semantics:</h5>
4360
4361<p>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004362The <tt>llvm.bswap.16</tt> intrinsic returns an i16 value that has the high
4363and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt>
4364intrinsic returns an i32 value that has the four bytes of the input i32
4365swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned
4366i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt>
4367intrinsic extends this concept to 64 bits.
Nate Begeman0f223bb2006-01-13 23:26:38 +00004368</p>
4369
4370</div>
4371
4372<!-- _______________________________________________________________________ -->
4373<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004374 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004375</div>
4376
4377<div class="doc_text">
4378
4379<h5>Syntax:</h5>
4380<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004381 declare i8 %llvm.ctpop.i8 (i8 &lt;src&gt;)
4382 declare i16 %llvm.ctpop.i16(i16 &lt;src&gt;)
4383 declare i32 %llvm.ctpop.i32(i32 &lt;src&gt;)
4384 declare i64 %llvm.ctpop.i64(i64 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004385</pre>
4386
4387<h5>Overview:</h5>
4388
4389<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004390The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4391value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004392</p>
4393
4394<h5>Arguments:</h5>
4395
4396<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004397The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004398integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004399</p>
4400
4401<h5>Semantics:</h5>
4402
4403<p>
4404The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4405</p>
4406</div>
4407
4408<!-- _______________________________________________________________________ -->
4409<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004410 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004411</div>
4412
4413<div class="doc_text">
4414
4415<h5>Syntax:</h5>
4416<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004417 declare i8 %llvm.ctlz.i8 (i8 &lt;src&gt;)
4418 declare i16 %llvm.ctlz.i16(i16 &lt;src&gt;)
4419 declare i32 %llvm.ctlz.i32(i32 &lt;src&gt;)
4420 declare i64 %llvm.ctlz.i64(i64 &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004421</pre>
4422
4423<h5>Overview:</h5>
4424
4425<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004426The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4427leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004428</p>
4429
4430<h5>Arguments:</h5>
4431
4432<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004433The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004434integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004435</p>
4436
4437<h5>Semantics:</h5>
4438
4439<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004440The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4441in a variable. If the src == 0 then the result is the size in bits of the type
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004442of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004443</p>
4444</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00004445
4446
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004447
4448<!-- _______________________________________________________________________ -->
4449<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004450 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004451</div>
4452
4453<div class="doc_text">
4454
4455<h5>Syntax:</h5>
4456<pre>
Reid Spencerb5ebf3d2006-12-31 07:07:53 +00004457 declare i8 %llvm.cttz.i8 (i8 &lt;src&gt;)
4458 declare i16 %llvm.cttz.i16(i16 &lt;src&gt;)
4459 declare i32 %llvm.cttz.i32(i32 &lt;src&gt;)
4460 declare i64 %llvm.cttz.i64(i64 &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004461</pre>
4462
4463<h5>Overview:</h5>
4464
4465<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004466The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
4467trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004468</p>
4469
4470<h5>Arguments:</h5>
4471
4472<p>
4473The only argument is the value to be counted. The argument may be of any
Reid Spencer3e628eb92007-01-04 16:43:23 +00004474integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004475</p>
4476
4477<h5>Semantics:</h5>
4478
4479<p>
4480The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
4481in a variable. If the src == 0 then the result is the size in bits of the type
4482of src. For example, <tt>llvm.cttz(2) = 1</tt>.
4483</p>
4484</div>
4485
Chris Lattner941515c2004-01-06 05:31:32 +00004486<!-- ======================================================================= -->
4487<div class="doc_subsection">
4488 <a name="int_debugger">Debugger Intrinsics</a>
4489</div>
4490
4491<div class="doc_text">
4492<p>
4493The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
4494are described in the <a
4495href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
4496Debugging</a> document.
4497</p>
4498</div>
4499
4500
Chris Lattner2f7c9632001-06-06 20:29:01 +00004501<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00004502<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00004503<address>
4504 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
4505 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
4506 <a href="http://validator.w3.org/check/referer"><img
4507 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
4508
4509 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00004510 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00004511 Last modified: $Date$
4512</address>
Misha Brukman76307852003-11-08 01:05:38 +00004513</body>
4514</html>