blob: 3af8b68a228ad65c877c7b0df0e7a6dc6fa64922 [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>
27 <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
Chris Lattner6af02f32004-12-09 16:11:40 +000028 </ol>
29 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000030 <li><a href="#typesystem">Type System</a>
31 <ol>
Robert Bocchino820bc75b2006-02-17 21:18:08 +000032 <li><a href="#t_primitive">Primitive Types</a>
Chris Lattner48b383b02003-11-25 01:02:51 +000033 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000034 <li><a href="#t_classifications">Type Classifications</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000035 </ol>
36 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000037 <li><a href="#t_derived">Derived Types</a>
38 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000039 <li><a href="#t_array">Array Type</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000040 <li><a href="#t_function">Function Type</a></li>
41 <li><a href="#t_pointer">Pointer Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000042 <li><a href="#t_struct">Structure Type</a></li>
Andrew Lenharth8df88e22006-12-08 17:13:00 +000043 <li><a href="#t_pstruct">Packed Structure Type</a></li>
Chris Lattnerc8cb6952004-08-12 19:12:28 +000044 <li><a href="#t_packed">Packed Type</a></li>
Chris Lattner37b6b092005-04-25 17:34:15 +000045 <li><a href="#t_opaque">Opaque Type</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000046 </ol>
47 </li>
48 </ol>
49 </li>
Chris Lattner6af02f32004-12-09 16:11:40 +000050 <li><a href="#constants">Constants</a>
Chris Lattner74d3f822004-12-09 17:30:23 +000051 <ol>
52 <li><a href="#simpleconstants">Simple Constants</a>
53 <li><a href="#aggregateconstants">Aggregate Constants</a>
54 <li><a href="#globalconstants">Global Variable and Function Addresses</a>
55 <li><a href="#undefvalues">Undefined Values</a>
56 <li><a href="#constantexprs">Constant Expressions</a>
57 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000058 </li>
Chris Lattner98f013c2006-01-25 23:47:57 +000059 <li><a href="#othervalues">Other Values</a>
60 <ol>
61 <li><a href="#inlineasm">Inline Assembler Expressions</a>
62 </ol>
63 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000064 <li><a href="#instref">Instruction Reference</a>
65 <ol>
66 <li><a href="#terminators">Terminator Instructions</a>
67 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000068 <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li>
69 <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000070 <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li>
71 <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000072 <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li>
Chris Lattner08b7d5b2004-10-16 18:04:13 +000073 <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000074 </ol>
75 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000076 <li><a href="#binaryops">Binary Operations</a>
77 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +000078 <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li>
79 <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li>
80 <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li>
Reid Spencer7e80b0b2006-10-26 06:15:43 +000081 <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li>
82 <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li>
83 <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li>
Reid Spencer7eb55b32006-11-02 01:53:59 +000084 <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li>
85 <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li>
86 <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000087 </ol>
88 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +000089 <li><a href="#bitwiseops">Bitwise Binary Operations</a>
90 <ol>
Misha Brukman76307852003-11-08 01:05:38 +000091 <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000092 <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li>
Misha Brukman76307852003-11-08 01:05:38 +000093 <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li>
94 <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li>
Reid Spencerfdff9382006-11-08 06:47:33 +000095 <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li>
96 <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +000097 </ol>
98 </li>
Chris Lattnerce83bff2006-04-08 23:07:04 +000099 <li><a href="#vectorops">Vector Operations</a>
100 <ol>
101 <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li>
102 <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li>
103 <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li>
Chris Lattnerce83bff2006-04-08 23:07:04 +0000104 </ol>
105 </li>
Chris Lattner6ab66722006-08-15 00:45:58 +0000106 <li><a href="#memoryops">Memory Access and Addressing Operations</a>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000107 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000108 <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li>
109 <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li>
110 <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li>
Robert Bocchino820bc75b2006-02-17 21:18:08 +0000111 <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li>
112 <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li>
113 <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000114 </ol>
115 </li>
Reid Spencer97c5fa42006-11-08 01:18:52 +0000116 <li><a href="#convertops">Conversion Operations</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000117 <ol>
118 <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li>
119 <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li>
120 <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li>
121 <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li>
122 <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li>
Reid Spencer51b07252006-11-09 23:03:26 +0000123 <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li>
124 <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li>
125 <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li>
126 <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li>
Reid Spencerb7344ff2006-11-11 21:00:47 +0000127 <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li>
128 <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li>
Reid Spencer5b950642006-11-11 23:08:07 +0000129 <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li>
Reid Spencer59b6b7d2006-11-08 01:11:31 +0000130 </ol>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000131 <li><a href="#otherops">Other Operations</a>
132 <ol>
Reid Spencerc828a0e2006-11-18 21:50:54 +0000133 <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li>
134 <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000135 <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li>
Chris Lattnerb53c28d2004-03-12 05:50:16 +0000136 <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li>
Chris Lattner48b383b02003-11-25 01:02:51 +0000137 <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li>
Chris Lattner33337472006-01-13 23:26:01 +0000138 <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000139 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000140 </li>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000141 </ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000142 </li>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000143 <li><a href="#intrinsics">Intrinsic Functions</a>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +0000144 <ol>
Chris Lattner48b383b02003-11-25 01:02:51 +0000145 <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a>
146 <ol>
147 <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li>
148 <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li>
149 <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li>
150 </ol>
151 </li>
Chris Lattner757528b0b2004-05-23 21:06:01 +0000152 <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a>
153 <ol>
154 <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li>
155 <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li>
156 <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li>
157 </ol>
158 </li>
Chris Lattner3649c3a2004-02-14 04:08:35 +0000159 <li><a href="#int_codegen">Code Generator Intrinsics</a>
160 <ol>
161 <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li>
162 <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li>
Chris Lattner2f0f0012006-01-13 02:03:13 +0000163 <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li>
164 <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li>
Chris Lattnerc8a2c222005-02-28 19:24:19 +0000165 <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li>
Andrew Lenharthb4427912005-03-28 20:05:49 +0000166 <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li>
Andrew Lenharth01aa5632005-11-11 16:47:30 +0000167 <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li>
John Criswellaa1c3c12004-04-09 16:43:20 +0000168 </ol>
169 </li>
Chris Lattnerfee11462004-02-12 17:01:32 +0000170 <li><a href="#int_libc">Standard C Library Intrinsics</a>
171 <ol>
Chris Lattner0c8b2592006-03-03 00:07:20 +0000172 <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li>
173 <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li>
174 <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li>
Chris Lattner069b5bd2006-01-16 22:38:59 +0000175 <li><a href="#i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a></li>
176 <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>
251 %x = <a href="#i_add">add</a> int 1, %x
252</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
278 with quotes. In this way, anything except a <tt>"</tt> character can be used
279 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
Chris Lattnerd79749a2004-12-09 16:36:40 +0000299href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...),
300and 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>
309 %result = <a href="#i_mul">mul</a> uint %X, 8
310</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>
315 %result = <a href="#i_shl">shl</a> uint %X, ubyte 3
316</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>
321 <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i>
322 <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i>
323 %result = <a href="#i_add">add</a> uint %1, %1
324</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
367 href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i>
368
369<i>; External declaration of the puts function</i>
370<a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i>
371
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>
376int %main() { <i>; int()* </i>
377 <i>; Convert [13x sbyte]* to sbyte *...</i>
378 %cast210 = <a
379 href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i>
380
381 <i>; Call puts function to write out the string to stdout...</i>
382 <a
383 href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i>
384 <a
385 href="#i_ret">ret</a> int 0<br>}<br></pre>
386
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
427 '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" 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
432 <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with
433 the twist that linking together two modules defining the same
434 <tt>linkonce</tt> globals will cause one of the globals to be discarded. This
435 is typically used to implement inline functions. Unreferenced
436 <tt>linkonce</tt> globals are 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
443 used to implement constructs in C such as "<tt>int X;</tt>" at global scope.
Chris Lattner6af02f32004-12-09 16:11:40 +0000444 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000445
Chris Lattner6af02f32004-12-09 16:11:40 +0000446 <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000447
448 <dd>"<tt>appending</tt>" linkage may only be applied to global variables of
449 pointer to array type. When two global variables with appending linkage are
450 linked together, the two global arrays are appended together. This is the
451 LLVM, typesafe, equivalent of having the system linker append together
452 "sections" with identical names when .o files are linked.
Chris Lattner6af02f32004-12-09 16:11:40 +0000453 </dd>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000454
Chris Lattner6af02f32004-12-09 16:11:40 +0000455 <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000456
457 <dd>If none of the above identifiers are used, the global is externally
458 visible, meaning that it participates in linkage and can be used to resolve
459 external symbol references.
Chris Lattner6af02f32004-12-09 16:11:40 +0000460 </dd>
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000461
462 <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt>
463
464 <dd>"<tt>extern_weak</tt>" TBD
465 </dd>
466
467 <p>
468 The next two types of linkage are targeted for Microsoft Windows platform
469 only. They are designed to support importing (exporting) symbols from (to)
470 DLLs.
471 </p>
472
473 <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt>
474
475 <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function
476 or variable via a global pointer to a pointer that is set up by the DLL
477 exporting the symbol. On Microsoft Windows targets, the pointer name is
478 formed by combining <code>_imp__</code> and the function or variable name.
479 </dd>
480
481 <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt>
482
483 <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global
484 pointer to a pointer in a DLL, so that it can be referenced with the
485 <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer
486 name is formed by combining <code>_imp__</code> and the function or variable
487 name.
488 </dd>
489
Chris Lattner6af02f32004-12-09 16:11:40 +0000490</dl>
491
Chris Lattner6af02f32004-12-09 16:11:40 +0000492<p><a name="linkage_external">For example, since the "<tt>.LC0</tt>"
493variable is defined to be internal, if another module defined a "<tt>.LC0</tt>"
494variable and was linked with this one, one of the two would be renamed,
495preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are
496external (i.e., lacking any linkage declarations), they are accessible
497outside of the current module. It is illegal for a function <i>declaration</i>
498to have any linkage type other than "externally visible".</a></p>
Chris Lattnerd79749a2004-12-09 16:36:40 +0000499
Chris Lattner6af02f32004-12-09 16:11:40 +0000500</div>
501
502<!-- ======================================================================= -->
503<div class="doc_subsection">
Chris Lattner0132aff2005-05-06 22:57:40 +0000504 <a name="callingconv">Calling Conventions</a>
505</div>
506
507<div class="doc_text">
508
509<p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a>
510and <a href="#i_invoke">invokes</a> can all have an optional calling convention
511specified for the call. The calling convention of any pair of dynamic
512caller/callee must match, or the behavior of the program is undefined. The
513following calling conventions are supported by LLVM, and more may be added in
514the future:</p>
515
516<dl>
517 <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt>
518
519 <dd>This calling convention (the default if no other calling convention is
520 specified) matches the target C calling conventions. This calling convention
John Criswell02fdc6f2005-05-12 16:52:32 +0000521 supports varargs function calls and tolerates some mismatch in the declared
Reid Spencerc329a4e2006-12-28 16:55:55 +0000522 prototype and implemented declaration of the function (as does normal C). For
523 integer arguments less than 32-bits, the value will be sign-extended to
524 32-bits before the call is made. If zero-extension is required, use the
525 <tt>cextcc</tt> calling convention.
Chris Lattner0132aff2005-05-06 22:57:40 +0000526 </dd>
527
Reid Spencerc329a4e2006-12-28 16:55:55 +0000528 <dt><b>"<tt>cextcc(bitmask)</tt>" - The C with explicit extend calling
529 convention </b>:</dt>
530 <dd>This calling convention is exactly like the C calling convention except
531 that it is parameterized to provide a <tt>bitmask</tt> that indicates how
532 integer arguments of less than 32-bits should be extended. A zero bit
533 indicates zero-extension while a 1-bit indicates sign-extension. The least
534 significant bit always corresponds to the return type of the function. The
535 bits in the <tt>bitmask</tt> are assigned to the integer parameters of the
536 function that are smaller than 32-bits. For example, a bitmask of value
537 5 (0b0101) indicates that the return value is to be sign extended, the first
538 small integer argument is to be zero extended and the second small integer
539 argument is to be sign extended.</dd>
540
541
Chris Lattner95ff1952006-05-19 21:15:36 +0000542 <dt><b>"<tt>csretcc</tt>" - The C struct return calling convention</b>:</dt>
543
544 <dd>This calling convention matches the target C calling conventions, except
545 that functions with this convention are required to take a pointer as their
546 first argument, and the return type of the function must be void. This is
547 used for C functions that return aggregates by-value. In this case, the
548 function has been transformed to take a pointer to the struct as the first
549 argument to the function. For targets where the ABI specifies specific
550 behavior for structure-return calls, the calling convention can be used to
551 distinguish between struct return functions and other functions that take a
552 pointer to a struct as the first argument.
553 </dd>
554
Reid Spencerc329a4e2006-12-28 16:55:55 +0000555 <dt><b>"<tt>csretextcc(bitmask)</tt>" - The C struct return with explicit
556 extend calling convention</b>:</dt>
557 <dd>This calling convention is exactly like the <tt>csret</tt> calling
558 convention except that it is parameterized to provide a <tt>bitmask</tt>
559 that indicates how integer arguments of less than 32-bits should be extended.
560 A zero bit indicates zero-extension while a 1-bit indicates sign-extension.
561 </dd>
562
Chris Lattner0132aff2005-05-06 22:57:40 +0000563 <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt>
564
565 <dd>This calling convention attempts to make calls as fast as possible
566 (e.g. by passing things in registers). This calling convention allows the
567 target to use whatever tricks it wants to produce fast code for the target,
Chris Lattnerc792eb32005-05-06 23:08:23 +0000568 without having to conform to an externally specified ABI. Implementations of
569 this convention should allow arbitrary tail call optimization to be supported.
570 This calling convention does not support varargs and requires the prototype of
571 all callees to exactly match the prototype of the function definition.
Chris Lattner0132aff2005-05-06 22:57:40 +0000572 </dd>
573
574 <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt>
575
576 <dd>This calling convention attempts to make code in the caller as efficient
577 as possible under the assumption that the call is not commonly executed. As
578 such, these calls often preserve all registers so that the call does not break
579 any live ranges in the caller side. This calling convention does not support
580 varargs and requires the prototype of all callees to exactly match the
581 prototype of the function definition.
582 </dd>
583
Chris Lattner573f64e2005-05-07 01:46:40 +0000584 <dt><b>"<tt>cc &lt;<em>n</em>&gt;</tt>" - Numbered convention</b>:</dt>
Chris Lattner0132aff2005-05-06 22:57:40 +0000585
586 <dd>Any calling convention may be specified by number, allowing
587 target-specific calling conventions to be used. Target specific calling
588 conventions start at 64.
589 </dd>
Chris Lattner573f64e2005-05-07 01:46:40 +0000590</dl>
Chris Lattner0132aff2005-05-06 22:57:40 +0000591
592<p>More calling conventions can be added/defined on an as-needed basis, to
593support pascal conventions or any other well-known target-independent
594convention.</p>
595
596</div>
597
598<!-- ======================================================================= -->
599<div class="doc_subsection">
Chris Lattner6af02f32004-12-09 16:11:40 +0000600 <a name="globalvars">Global Variables</a>
601</div>
602
603<div class="doc_text">
604
Chris Lattner5d5aede2005-02-12 19:30:21 +0000605<p>Global variables define regions of memory allocated at compilation time
Chris Lattner662c8722005-11-12 00:45:07 +0000606instead of run-time. Global variables may optionally be initialized, may have
607an explicit section to be placed in, and may
Chris Lattner54611b42005-11-06 08:02:57 +0000608have an optional explicit alignment specified. A
John Criswell4c0cf7f2005-10-24 16:17:18 +0000609variable may be defined as a global "constant," which indicates that the
Chris Lattner5d5aede2005-02-12 19:30:21 +0000610contents of the variable will <b>never</b> be modified (enabling better
611optimization, allowing the global data to be placed in the read-only section of
612an executable, etc). Note that variables that need runtime initialization
John Criswell4c0cf7f2005-10-24 16:17:18 +0000613cannot be marked "constant" as there is a store to the variable.</p>
Chris Lattner5d5aede2005-02-12 19:30:21 +0000614
615<p>
616LLVM explicitly allows <em>declarations</em> of global variables to be marked
617constant, even if the final definition of the global is not. This capability
618can be used to enable slightly better optimization of the program, but requires
619the language definition to guarantee that optimizations based on the
620'constantness' are valid for the translation units that do not include the
621definition.
622</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000623
624<p>As SSA values, global variables define pointer values that are in
625scope (i.e. they dominate) all basic blocks in the program. Global
626variables always define a pointer to their "content" type because they
627describe a region of memory, and all memory objects in LLVM are
628accessed through pointers.</p>
629
Chris Lattner662c8722005-11-12 00:45:07 +0000630<p>LLVM allows an explicit section to be specified for globals. If the target
631supports it, it will emit globals to the section specified.</p>
632
Chris Lattner54611b42005-11-06 08:02:57 +0000633<p>An explicit alignment may be specified for a global. If not present, or if
634the alignment is set to zero, the alignment of the global is set by the target
635to whatever it feels convenient. If an explicit alignment is specified, the
636global is forced to have at least that much alignment. All alignments must be
637a power of 2.</p>
638
Chris Lattner6af02f32004-12-09 16:11:40 +0000639</div>
640
641
642<!-- ======================================================================= -->
643<div class="doc_subsection">
644 <a name="functionstructure">Functions</a>
645</div>
646
647<div class="doc_text">
648
Chris Lattner0132aff2005-05-06 22:57:40 +0000649<p>LLVM function definitions consist of an optional <a href="#linkage">linkage
650type</a>, an optional <a href="#callingconv">calling convention</a>, a return
Chris Lattner662c8722005-11-12 00:45:07 +0000651type, a function name, a (possibly empty) argument list, an optional section,
652an optional alignment, an opening curly brace,
Chris Lattner0132aff2005-05-06 22:57:40 +0000653a list of basic blocks, and a closing curly brace. LLVM function declarations
654are defined with the "<tt>declare</tt>" keyword, an optional <a
Chris Lattner54611b42005-11-06 08:02:57 +0000655href="#callingconv">calling convention</a>, a return type, a function name,
656a possibly empty list of arguments, and an optional alignment.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000657
658<p>A function definition contains a list of basic blocks, forming the CFG for
659the function. Each basic block may optionally start with a label (giving the
660basic block a symbol table entry), contains a list of instructions, and ends
661with a <a href="#terminators">terminator</a> instruction (such as a branch or
662function return).</p>
663
John Criswell02fdc6f2005-05-12 16:52:32 +0000664<p>The first basic block in a program is special in two ways: it is immediately
Chris Lattner6af02f32004-12-09 16:11:40 +0000665executed on entrance to the function, and it is not allowed to have predecessor
666basic blocks (i.e. there can not be any branches to the entry block of a
667function). Because the block can have no predecessors, it also cannot have any
668<a href="#i_phi">PHI nodes</a>.</p>
669
670<p>LLVM functions are identified by their name and type signature. Hence, two
671functions with the same name but different parameter lists or return values are
Chris Lattner455fc8c2005-03-07 22:13:59 +0000672considered different functions, and LLVM will resolve references to each
Chris Lattner6af02f32004-12-09 16:11:40 +0000673appropriately.</p>
674
Chris Lattner662c8722005-11-12 00:45:07 +0000675<p>LLVM allows an explicit section to be specified for functions. If the target
676supports it, it will emit functions to the section specified.</p>
677
Chris Lattner54611b42005-11-06 08:02:57 +0000678<p>An explicit alignment may be specified for a function. If not present, or if
679the alignment is set to zero, the alignment of the function is set by the target
680to whatever it feels convenient. If an explicit alignment is specified, the
681function is forced to have at least that much alignment. All alignments must be
682a power of 2.</p>
683
Chris Lattner6af02f32004-12-09 16:11:40 +0000684</div>
685
Chris Lattner91c15c42006-01-23 23:23:47 +0000686<!-- ======================================================================= -->
687<div class="doc_subsection">
Chris Lattner93564892006-04-08 04:40:53 +0000688 <a name="moduleasm">Module-Level Inline Assembly</a>
Chris Lattner91c15c42006-01-23 23:23:47 +0000689</div>
690
691<div class="doc_text">
692<p>
693Modules may contain "module-level inline asm" blocks, which corresponds to the
694GCC "file scope inline asm" blocks. These blocks are internally concatenated by
695LLVM and treated as a single unit, but may be separated in the .ll file if
696desired. The syntax is very simple:
697</p>
698
699<div class="doc_code"><pre>
Chris Lattnera1280ad2006-01-24 00:37:20 +0000700 module asm "inline asm code goes here"
701 module asm "more can go here"
Chris Lattner91c15c42006-01-23 23:23:47 +0000702</pre></div>
703
704<p>The strings can contain any character by escaping non-printable characters.
705 The escape sequence used is simply "\xx" where "xx" is the two digit hex code
706 for the number.
707</p>
708
709<p>
710 The inline asm code is simply printed to the machine code .s file when
711 assembly code is generated.
712</p>
713</div>
Chris Lattner6af02f32004-12-09 16:11:40 +0000714
715
Chris Lattner2f7c9632001-06-06 20:29:01 +0000716<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000717<div class="doc_section"> <a name="typesystem">Type System</a> </div>
718<!-- *********************************************************************** -->
Chris Lattner6af02f32004-12-09 16:11:40 +0000719
Misha Brukman76307852003-11-08 01:05:38 +0000720<div class="doc_text">
Chris Lattner6af02f32004-12-09 16:11:40 +0000721
Misha Brukman76307852003-11-08 01:05:38 +0000722<p>The LLVM type system is one of the most important features of the
Chris Lattner48b383b02003-11-25 01:02:51 +0000723intermediate representation. Being typed enables a number of
724optimizations to be performed on the IR directly, without having to do
725extra analyses on the side before the transformation. A strong type
726system makes it easier to read the generated code and enables novel
727analyses and transformations that are not feasible to perform on normal
728three address code representations.</p>
Chris Lattner6af02f32004-12-09 16:11:40 +0000729
730</div>
731
Chris Lattner2f7c9632001-06-06 20:29:01 +0000732<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000733<div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000734<div class="doc_text">
John Criswell417228d2004-04-09 16:48:45 +0000735<p>The primitive types are the fundamental building blocks of the LLVM
Chris Lattner455fc8c2005-03-07 22:13:59 +0000736system. The current set of primitive types is as follows:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000737
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000738<table class="layout">
739 <tr class="layout">
740 <td class="left">
741 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000742 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000743 <tr><th>Type</th><th>Description</th></tr>
744 <tr><td><tt>void</tt></td><td>No value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000745 <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr>
746 <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr>
747 <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr>
748 <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr>
749 <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000750 <tr><td><tt>label</tt></td><td>Branch destination</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000751 </tbody>
752 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000753 </td>
754 <td class="right">
755 <table>
Chris Lattner48b383b02003-11-25 01:02:51 +0000756 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000757 <tr><th>Type</th><th>Description</th></tr>
758 <tr><td><tt>bool</tt></td><td>True or False value</td></tr>
Misha Brukman36c6bc12005-04-22 18:02:52 +0000759 <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr>
760 <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr>
761 <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr>
762 <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr>
763 <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000764 </tbody>
765 </table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000766 </td>
767 </tr>
Misha Brukman76307852003-11-08 01:05:38 +0000768</table>
Misha Brukman76307852003-11-08 01:05:38 +0000769</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000770
Chris Lattner2f7c9632001-06-06 20:29:01 +0000771<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000772<div class="doc_subsubsection"> <a name="t_classifications">Type
773Classifications</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000774<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +0000775<p>These different primitive types fall into a few useful
776classifications:</p>
Misha Brukmanc501f552004-03-01 17:47:27 +0000777
778<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +0000779 <tbody>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000780 <tr><th>Classification</th><th>Types</th></tr>
Chris Lattner48b383b02003-11-25 01:02:51 +0000781 <tr>
782 <td><a name="t_signed">signed</a></td>
783 <td><tt>sbyte, short, int, long, float, double</tt></td>
784 </tr>
785 <tr>
786 <td><a name="t_unsigned">unsigned</a></td>
787 <td><tt>ubyte, ushort, uint, ulong</tt></td>
788 </tr>
789 <tr>
790 <td><a name="t_integer">integer</a></td>
791 <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td>
792 </tr>
793 <tr>
794 <td><a name="t_integral">integral</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000795 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt>
796 </td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000797 </tr>
798 <tr>
799 <td><a name="t_floating">floating point</a></td>
800 <td><tt>float, double</tt></td>
801 </tr>
802 <tr>
803 <td><a name="t_firstclass">first class</a></td>
Misha Brukman20f9a622004-08-12 20:16:08 +0000804 <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br>
805 float, double, <a href="#t_pointer">pointer</a>,
806 <a href="#t_packed">packed</a></tt></td>
Chris Lattner48b383b02003-11-25 01:02:51 +0000807 </tr>
808 </tbody>
Misha Brukman76307852003-11-08 01:05:38 +0000809</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000810
Chris Lattner48b383b02003-11-25 01:02:51 +0000811<p>The <a href="#t_firstclass">first class</a> types are perhaps the
812most important. Values of these types are the only ones which can be
813produced by instructions, passed as arguments, or used as operands to
814instructions. This means that all structures and arrays must be
815manipulated either by pointer or by component.</p>
Misha Brukman76307852003-11-08 01:05:38 +0000816</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000817
Chris Lattner2f7c9632001-06-06 20:29:01 +0000818<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000819<div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000820
Misha Brukman76307852003-11-08 01:05:38 +0000821<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000822
Chris Lattner48b383b02003-11-25 01:02:51 +0000823<p>The real power in LLVM comes from the derived types in the system.
824This is what allows a programmer to represent arrays, functions,
825pointers, and other useful types. Note that these derived types may be
826recursive: For example, it is possible to have a two dimensional array.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000827
Misha Brukman76307852003-11-08 01:05:38 +0000828</div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000829
Chris Lattner2f7c9632001-06-06 20:29:01 +0000830<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000831<div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +0000832
Misha Brukman76307852003-11-08 01:05:38 +0000833<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +0000834
Chris Lattner2f7c9632001-06-06 20:29:01 +0000835<h5>Overview:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000836
Misha Brukman76307852003-11-08 01:05:38 +0000837<p>The array type is a very simple derived type that arranges elements
Chris Lattner48b383b02003-11-25 01:02:51 +0000838sequentially in memory. The array type requires a size (number of
839elements) and an underlying data type.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000840
Chris Lattner590645f2002-04-14 06:13:44 +0000841<h5>Syntax:</h5>
Chris Lattner74d3f822004-12-09 17:30:23 +0000842
843<pre>
844 [&lt;# elements&gt; x &lt;elementtype&gt;]
845</pre>
846
John Criswell02fdc6f2005-05-12 16:52:32 +0000847<p>The number of elements is a constant integer value; elementtype may
Chris Lattner48b383b02003-11-25 01:02:51 +0000848be any type with a size.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +0000849
Chris Lattner590645f2002-04-14 06:13:44 +0000850<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000851<table class="layout">
852 <tr class="layout">
853 <td class="left">
854 <tt>[40 x int ]</tt><br/>
855 <tt>[41 x int ]</tt><br/>
856 <tt>[40 x uint]</tt><br/>
857 </td>
858 <td class="left">
859 Array of 40 integer values.<br/>
860 Array of 41 integer values.<br/>
861 Array of 40 unsigned integer values.<br/>
862 </td>
863 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000864</table>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000865<p>Here are some examples of multidimensional arrays:</p>
866<table class="layout">
867 <tr class="layout">
868 <td class="left">
869 <tt>[3 x [4 x int]]</tt><br/>
870 <tt>[12 x [10 x float]]</tt><br/>
871 <tt>[2 x [3 x [4 x uint]]]</tt><br/>
872 </td>
873 <td class="left">
John Criswell4a3327e2005-05-13 22:25:59 +0000874 3x4 array of integer values.<br/>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000875 12x10 array of single precision floating point values.<br/>
876 2x3x4 array of unsigned integer values.<br/>
877 </td>
878 </tr>
879</table>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000880
John Criswell4c0cf7f2005-10-24 16:17:18 +0000881<p>Note that 'variable sized arrays' can be implemented in LLVM with a zero
882length array. Normally, accesses past the end of an array are undefined in
Chris Lattnerc0ad71e2005-06-24 17:22:57 +0000883LLVM (e.g. it is illegal to access the 5th element of a 3 element array).
884As a special case, however, zero length arrays are recognized to be variable
885length. This allows implementation of 'pascal style arrays' with the LLVM
886type "{ int, [0 x float]}", for example.</p>
887
Misha Brukman76307852003-11-08 01:05:38 +0000888</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000889
Chris Lattner2f7c9632001-06-06 20:29:01 +0000890<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000891<div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000892<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000893<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000894<p>The function type can be thought of as a function signature. It
895consists of a return type and a list of formal parameter types.
John Criswella0d50d22003-11-25 21:45:46 +0000896Function types are usually used to build virtual function tables
Chris Lattner48b383b02003-11-25 01:02:51 +0000897(which are structures of pointers to functions), for indirect function
898calls, and when defining a function.</p>
John Criswella0d50d22003-11-25 21:45:46 +0000899<p>
900The return type of a function type cannot be an aggregate type.
901</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000902<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000903<pre> &lt;returntype&gt; (&lt;parameter list&gt;)<br></pre>
John Criswell4c0cf7f2005-10-24 16:17:18 +0000904<p>...where '<tt>&lt;parameter list&gt;</tt>' is a comma-separated list of type
Misha Brukman20f9a622004-08-12 20:16:08 +0000905specifiers. Optionally, the parameter list may include a type <tt>...</tt>,
Chris Lattner5ed60612003-09-03 00:41:47 +0000906which indicates that the function takes a variable number of arguments.
907Variable argument functions can access their arguments with the <a
Chris Lattner48b383b02003-11-25 01:02:51 +0000908 href="#int_varargs">variable argument handling intrinsic</a> functions.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000909<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000910<table class="layout">
911 <tr class="layout">
912 <td class="left">
913 <tt>int (int)</tt> <br/>
914 <tt>float (int, int *) *</tt><br/>
915 <tt>int (sbyte *, ...)</tt><br/>
916 </td>
917 <td class="left">
918 function taking an <tt>int</tt>, returning an <tt>int</tt><br/>
919 <a href="#t_pointer">Pointer</a> to a function that takes an
Misha Brukman20f9a622004-08-12 20:16:08 +0000920 <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>,
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000921 returning <tt>float</tt>.<br/>
922 A vararg function that takes at least one <a href="#t_pointer">pointer</a>
923 to <tt>sbyte</tt> (signed char in C), which returns an integer. This is
924 the signature for <tt>printf</tt> in LLVM.<br/>
925 </td>
926 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000927</table>
Misha Brukmanc501f552004-03-01 17:47:27 +0000928
Misha Brukman76307852003-11-08 01:05:38 +0000929</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000930<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000931<div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000932<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +0000933<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000934<p>The structure type is used to represent a collection of data members
935together in memory. The packing of the field types is defined to match
936the ABI of the underlying processor. The elements of a structure may
937be any type that has a size.</p>
938<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
939and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
940field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
941instruction.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000942<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000943<pre> { &lt;type list&gt; }<br></pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000944<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000945<table class="layout">
946 <tr class="layout">
947 <td class="left">
948 <tt>{ int, int, int }</tt><br/>
949 <tt>{ float, int (int) * }</tt><br/>
950 </td>
951 <td class="left">
952 a triple of three <tt>int</tt> values<br/>
953 A pair, where the first element is a <tt>float</tt> and the second element
954 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
955 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
956 </td>
957 </tr>
Chris Lattner2f7c9632001-06-06 20:29:01 +0000958</table>
Misha Brukman76307852003-11-08 01:05:38 +0000959</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +0000960
Chris Lattner2f7c9632001-06-06 20:29:01 +0000961<!-- _______________________________________________________________________ -->
Andrew Lenharth8df88e22006-12-08 17:13:00 +0000962<div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a>
963</div>
964<div class="doc_text">
965<h5>Overview:</h5>
966<p>The packed structure type is used to represent a collection of data members
967together in memory. There is no padding between fields. Further, the alignment
968of a packed structure is 1 byte. The elements of a packed structure may
969be any type that has a size.</p>
970<p>Structures are accessed using '<tt><a href="#i_load">load</a></tt>
971and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a
972field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>'
973instruction.</p>
974<h5>Syntax:</h5>
975<pre> &lt; { &lt;type list&gt; } &gt; <br></pre>
976<h5>Examples:</h5>
977<table class="layout">
978 <tr class="layout">
979 <td class="left">
980 <tt> &lt; { int, int, int } &gt; </tt><br/>
981 <tt> &lt; { float, int (int) * } &gt; </tt><br/>
982 </td>
983 <td class="left">
984 a triple of three <tt>int</tt> values<br/>
985 A pair, where the first element is a <tt>float</tt> and the second element
986 is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a>
987 that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/>
988 </td>
989 </tr>
990</table>
991</div>
992
993<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +0000994<div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +0000995<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +0000996<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +0000997<p>As in many languages, the pointer type represents a pointer or
998reference to another object, which must live in memory.</p>
Chris Lattner590645f2002-04-14 06:13:44 +0000999<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001000<pre> &lt;type&gt; *<br></pre>
Chris Lattner590645f2002-04-14 06:13:44 +00001001<h5>Examples:</h5>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001002<table class="layout">
1003 <tr class="layout">
1004 <td class="left">
1005 <tt>[4x int]*</tt><br/>
1006 <tt>int (int *) *</tt><br/>
1007 </td>
1008 <td class="left">
1009 A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of
1010 four <tt>int</tt> values<br/>
1011 A <a href="#t_pointer">pointer</a> to a <a
Chris Lattner16fb0032005-02-19 02:22:14 +00001012 href="#t_function">function</a> that takes an <tt>int*</tt>, returning an
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001013 <tt>int</tt>.<br/>
1014 </td>
1015 </tr>
Misha Brukman76307852003-11-08 01:05:38 +00001016</table>
Misha Brukman76307852003-11-08 01:05:38 +00001017</div>
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001018
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001019<!-- _______________________________________________________________________ -->
1020<div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001021<div class="doc_text">
Chris Lattner37b6b092005-04-25 17:34:15 +00001022
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001023<h5>Overview:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001024
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001025<p>A packed type is a simple derived type that represents a vector
1026of elements. Packed types are used when multiple primitive data
1027are operated in parallel using a single instruction (SIMD).
1028A packed type requires a size (number of
Chris Lattner330ce692005-11-10 01:44:22 +00001029elements) and an underlying primitive data type. Vectors must have a power
1030of two length (1, 2, 4, 8, 16 ...). Packed types are
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001031considered <a href="#t_firstclass">first class</a>.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001032
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001033<h5>Syntax:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001034
1035<pre>
1036 &lt; &lt;# elements&gt; x &lt;elementtype&gt; &gt;
1037</pre>
1038
John Criswell4a3327e2005-05-13 22:25:59 +00001039<p>The number of elements is a constant integer value; elementtype may
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001040be any integral or floating point type.</p>
Chris Lattner37b6b092005-04-25 17:34:15 +00001041
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001042<h5>Examples:</h5>
Chris Lattner37b6b092005-04-25 17:34:15 +00001043
Reid Spencerc3c4c4f2004-11-01 08:19:36 +00001044<table class="layout">
1045 <tr class="layout">
1046 <td class="left">
1047 <tt>&lt;4 x int&gt;</tt><br/>
1048 <tt>&lt;8 x float&gt;</tt><br/>
1049 <tt>&lt;2 x uint&gt;</tt><br/>
1050 </td>
1051 <td class="left">
1052 Packed vector of 4 integer values.<br/>
1053 Packed vector of 8 floating-point values.<br/>
1054 Packed vector of 2 unsigned integer values.<br/>
1055 </td>
1056 </tr>
1057</table>
Misha Brukman76307852003-11-08 01:05:38 +00001058</div>
1059
Chris Lattner37b6b092005-04-25 17:34:15 +00001060<!-- _______________________________________________________________________ -->
1061<div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div>
1062<div class="doc_text">
1063
1064<h5>Overview:</h5>
1065
1066<p>Opaque types are used to represent unknown types in the system. This
1067corresponds (for example) to the C notion of a foward declared structure type.
1068In LLVM, opaque types can eventually be resolved to any type (not just a
1069structure type).</p>
1070
1071<h5>Syntax:</h5>
1072
1073<pre>
1074 opaque
1075</pre>
1076
1077<h5>Examples:</h5>
1078
1079<table class="layout">
1080 <tr class="layout">
1081 <td class="left">
1082 <tt>opaque</tt>
1083 </td>
1084 <td class="left">
1085 An opaque type.<br/>
1086 </td>
1087 </tr>
1088</table>
1089</div>
1090
1091
Chris Lattner74d3f822004-12-09 17:30:23 +00001092<!-- *********************************************************************** -->
1093<div class="doc_section"> <a name="constants">Constants</a> </div>
1094<!-- *********************************************************************** -->
1095
1096<div class="doc_text">
1097
1098<p>LLVM has several different basic types of constants. This section describes
1099them all and their syntax.</p>
1100
1101</div>
1102
1103<!-- ======================================================================= -->
Reid Spencer8f08d802004-12-09 18:02:53 +00001104<div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001105
1106<div class="doc_text">
1107
1108<dl>
1109 <dt><b>Boolean constants</b></dt>
1110
1111 <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid
1112 constants of the <tt><a href="#t_primitive">bool</a></tt> type.
1113 </dd>
1114
1115 <dt><b>Integer constants</b></dt>
1116
Reid Spencer8f08d802004-12-09 18:02:53 +00001117 <dd>Standard integers (such as '4') are constants of the <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001118 href="#t_integer">integer</a> type. Negative numbers may be used with signed
1119 integer types.
1120 </dd>
1121
1122 <dt><b>Floating point constants</b></dt>
1123
1124 <dd>Floating point constants use standard decimal notation (e.g. 123.421),
1125 exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal
Chris Lattner74d3f822004-12-09 17:30:23 +00001126 notation (see below). Floating point constants must have a <a
1127 href="#t_floating">floating point</a> type. </dd>
1128
1129 <dt><b>Null pointer constants</b></dt>
1130
John Criswelldfe6a862004-12-10 15:51:16 +00001131 <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant
Chris Lattner74d3f822004-12-09 17:30:23 +00001132 and must be of <a href="#t_pointer">pointer type</a>.</dd>
1133
1134</dl>
1135
John Criswelldfe6a862004-12-10 15:51:16 +00001136<p>The one non-intuitive notation for constants is the optional hexadecimal form
Chris Lattner74d3f822004-12-09 17:30:23 +00001137of floating point constants. For example, the form '<tt>double
11380x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double
11394.5e+15</tt>'. The only time hexadecimal floating point constants are required
Reid Spencer8f08d802004-12-09 18:02:53 +00001140(and the only time that they are generated by the disassembler) is when a
1141floating point constant must be emitted but it cannot be represented as a
1142decimal floating point number. For example, NaN's, infinities, and other
1143special values are represented in their IEEE hexadecimal format so that
1144assembly and disassembly do not cause any bits to change in the constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001145
1146</div>
1147
1148<!-- ======================================================================= -->
1149<div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a>
1150</div>
1151
1152<div class="doc_text">
Chris Lattner455fc8c2005-03-07 22:13:59 +00001153<p>Aggregate constants arise from aggregation of simple constants
1154and smaller aggregate constants.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001155
1156<dl>
1157 <dt><b>Structure constants</b></dt>
1158
1159 <dd>Structure constants are represented with notation similar to structure
1160 type definitions (a comma separated list of elements, surrounded by braces
Chris Lattner455fc8c2005-03-07 22:13:59 +00001161 (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>",
1162 where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants
1163 must have <a href="#t_struct">structure type</a>, and the number and
Chris Lattner74d3f822004-12-09 17:30:23 +00001164 types of elements must match those specified by the type.
1165 </dd>
1166
1167 <dt><b>Array constants</b></dt>
1168
1169 <dd>Array constants are represented with notation similar to array type
1170 definitions (a comma separated list of elements, surrounded by square brackets
John Criswelldfe6a862004-12-10 15:51:16 +00001171 (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array
Chris Lattner74d3f822004-12-09 17:30:23 +00001172 constants must have <a href="#t_array">array type</a>, and the number and
1173 types of elements must match those specified by the type.
1174 </dd>
1175
1176 <dt><b>Packed constants</b></dt>
1177
1178 <dd>Packed constants are represented with notation similar to packed type
1179 definitions (a comma separated list of elements, surrounded by
John Criswelldfe6a862004-12-10 15:51:16 +00001180 less-than/greater-than's (<tt>&lt;&gt;</tt>)). For example: "<tt>&lt; int 42,
Chris Lattner74d3f822004-12-09 17:30:23 +00001181 int 11, int 74, int 100 &gt;</tt>". Packed constants must have <a
1182 href="#t_packed">packed type</a>, and the number and types of elements must
1183 match those specified by the type.
1184 </dd>
1185
1186 <dt><b>Zero initialization</b></dt>
1187
1188 <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a
1189 value to zero of <em>any</em> type, including scalar and aggregate types.
1190 This is often used to avoid having to print large zero initializers (e.g. for
John Criswell4c0cf7f2005-10-24 16:17:18 +00001191 large arrays) and is always exactly equivalent to using explicit zero
Chris Lattner74d3f822004-12-09 17:30:23 +00001192 initializers.
1193 </dd>
1194</dl>
1195
1196</div>
1197
1198<!-- ======================================================================= -->
1199<div class="doc_subsection">
1200 <a name="globalconstants">Global Variable and Function Addresses</a>
1201</div>
1202
1203<div class="doc_text">
1204
1205<p>The addresses of <a href="#globalvars">global variables</a> and <a
1206href="#functionstructure">functions</a> are always implicitly valid (link-time)
John Criswelldfe6a862004-12-10 15:51:16 +00001207constants. These constants are explicitly referenced when the <a
1208href="#identifiers">identifier for the global</a> is used and always have <a
Chris Lattner74d3f822004-12-09 17:30:23 +00001209href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM
1210file:</p>
1211
1212<pre>
1213 %X = global int 17
1214 %Y = global int 42
1215 %Z = global [2 x int*] [ int* %X, int* %Y ]
1216</pre>
1217
1218</div>
1219
1220<!-- ======================================================================= -->
Reid Spencer641f5c92004-12-09 18:13:12 +00001221<div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001222<div class="doc_text">
Reid Spencer641f5c92004-12-09 18:13:12 +00001223 <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has
John Criswell4a3327e2005-05-13 22:25:59 +00001224 no specific value. Undefined values may be of any type and be used anywhere
Reid Spencer641f5c92004-12-09 18:13:12 +00001225 a constant is permitted.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001226
Reid Spencer641f5c92004-12-09 18:13:12 +00001227 <p>Undefined values indicate to the compiler that the program is well defined
1228 no matter what value is used, giving the compiler more freedom to optimize.
1229 </p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001230</div>
1231
1232<!-- ======================================================================= -->
1233<div class="doc_subsection"><a name="constantexprs">Constant Expressions</a>
1234</div>
1235
1236<div class="doc_text">
1237
1238<p>Constant expressions are used to allow expressions involving other constants
1239to be used as constants. Constant expressions may be of any <a
John Criswell4a3327e2005-05-13 22:25:59 +00001240href="#t_firstclass">first class</a> type and may involve any LLVM operation
Chris Lattner74d3f822004-12-09 17:30:23 +00001241that does not have side effects (e.g. load and call are not supported). The
1242following is the syntax for constant expressions:</p>
1243
1244<dl>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001245 <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt>
1246 <dd>Truncate a constant to another type. The bit size of CST must be larger
1247 than the bit size of TYPE. Both types must be integral.</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001248
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001249 <dt><b><tt>zext ( CST to TYPE )</tt></b></dt>
1250 <dd>Zero extend a constant to another type. The bit size of CST must be
1251 smaller or equal to the bit size of TYPE. Both types must be integral.</dd>
1252
1253 <dt><b><tt>sext ( CST to TYPE )</tt></b></dt>
1254 <dd>Sign extend a constant to another type. The bit size of CST must be
1255 smaller or equal to the bit size of TYPE. Both types must be integral.</dd>
1256
1257 <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt>
1258 <dd>Truncate a floating point constant to another floating point type. The
1259 size of CST must be larger than the size of TYPE. Both types must be
1260 floating point.</dd>
1261
1262 <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt>
1263 <dd>Floating point extend a constant to another type. The size of CST must be
1264 smaller or equal to the size of TYPE. Both types must be floating point.</dd>
1265
1266 <dt><b><tt>fp2uint ( CST to TYPE )</tt></b></dt>
1267 <dd>Convert a floating point constant to the corresponding unsigned integer
1268 constant. TYPE must be an integer type. CST must be floating point. If the
1269 value won't fit in the integer type, the results are undefined.</dd>
1270
Reid Spencer51b07252006-11-09 23:03:26 +00001271 <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001272 <dd>Convert a floating point constant to the corresponding signed integer
1273 constant. TYPE must be an integer type. CST must be floating point. If the
1274 value won't fit in the integer type, the results are undefined.</dd>
1275
Reid Spencer51b07252006-11-09 23:03:26 +00001276 <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001277 <dd>Convert an unsigned integer constant to the corresponding floating point
1278 constant. TYPE must be floating point. CST must be of integer type. If the
1279 value won't fit in the floating point type, the results are undefined.</dd>
1280
Reid Spencer51b07252006-11-09 23:03:26 +00001281 <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001282 <dd>Convert a signed integer constant to the corresponding floating point
1283 constant. TYPE must be floating point. CST must be of integer type. If the
1284 value won't fit in the floating point type, the results are undefined.</dd>
1285
Reid Spencer5b950642006-11-11 23:08:07 +00001286 <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt>
1287 <dd>Convert a pointer typed constant to the corresponding integer constant
1288 TYPE must be an integer type. CST must be of pointer type. The CST value is
1289 zero extended, truncated, or unchanged to make it fit in TYPE.</dd>
1290
1291 <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt>
1292 <dd>Convert a integer constant to a pointer constant. TYPE must be a
1293 pointer type. CST must be of integer type. The CST value is zero extended,
1294 truncated, or unchanged to make it fit in a pointer size. This one is
1295 <i>really</i> dangerous!</dd>
1296
1297 <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001298 <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be
1299 identical (same number of bits). The conversion is done as if the CST value
1300 was stored to memory and read back as TYPE. In other words, no bits change
Reid Spencer5b950642006-11-11 23:08:07 +00001301 with this operator, just the type. This can be used for conversion of
1302 packed types to any other type, as long as they have the same bit width. For
1303 pointers it is only valid to cast to another pointer type.
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001304 </dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001305
1306 <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt>
1307
1308 <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on
1309 constants. As with the <a href="#i_getelementptr">getelementptr</a>
1310 instruction, the index list may have zero or more indexes, which are required
1311 to make sense for the type of "CSTPTR".</dd>
1312
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001313 <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt>
1314
1315 <dd>Perform the <a href="#i_select">select operation</a> on
Reid Spencer9965ee72006-12-04 19:23:19 +00001316 constants.</dd>
1317
1318 <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt>
1319 <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd>
1320
1321 <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt>
1322 <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd>
Robert Bocchino7e97a6d2006-01-10 19:31:34 +00001323
1324 <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt>
1325
1326 <dd>Perform the <a href="#i_extractelement">extractelement
1327 operation</a> on constants.
1328
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001329 <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt>
1330
1331 <dd>Perform the <a href="#i_insertelement">insertelement
Reid Spencer9965ee72006-12-04 19:23:19 +00001332 operation</a> on constants.</dd>
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00001333
Chris Lattner016a0e52006-04-08 00:13:41 +00001334
1335 <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt>
1336
1337 <dd>Perform the <a href="#i_shufflevector">shufflevector
Reid Spencer9965ee72006-12-04 19:23:19 +00001338 operation</a> on constants.</dd>
Chris Lattner016a0e52006-04-08 00:13:41 +00001339
Chris Lattner74d3f822004-12-09 17:30:23 +00001340 <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt>
1341
Reid Spencer641f5c92004-12-09 18:13:12 +00001342 <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may
1343 be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise
Chris Lattner74d3f822004-12-09 17:30:23 +00001344 binary</a> operations. The constraints on operands are the same as those for
1345 the corresponding instruction (e.g. no bitwise operations on floating point
John Criswell02fdc6f2005-05-12 16:52:32 +00001346 values are allowed).</dd>
Chris Lattner74d3f822004-12-09 17:30:23 +00001347</dl>
Chris Lattner74d3f822004-12-09 17:30:23 +00001348</div>
Chris Lattnerb1652612004-03-08 16:49:10 +00001349
Chris Lattner2f7c9632001-06-06 20:29:01 +00001350<!-- *********************************************************************** -->
Chris Lattner98f013c2006-01-25 23:47:57 +00001351<div class="doc_section"> <a name="othervalues">Other Values</a> </div>
1352<!-- *********************************************************************** -->
1353
1354<!-- ======================================================================= -->
1355<div class="doc_subsection">
1356<a name="inlineasm">Inline Assembler Expressions</a>
1357</div>
1358
1359<div class="doc_text">
1360
1361<p>
1362LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm">
1363Module-Level Inline Assembly</a>) through the use of a special value. This
1364value represents the inline assembler as a string (containing the instructions
1365to emit), a list of operand constraints (stored as a string), and a flag that
1366indicates whether or not the inline asm expression has side effects. An example
1367inline assembler expression is:
1368</p>
1369
1370<pre>
1371 int(int) asm "bswap $0", "=r,r"
1372</pre>
1373
1374<p>
1375Inline assembler expressions may <b>only</b> be used as the callee operand of
1376a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have:
1377</p>
1378
1379<pre>
1380 %X = call int asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(int %Y)
1381</pre>
1382
1383<p>
1384Inline asms with side effects not visible in the constraint list must be marked
1385as having side effects. This is done through the use of the
1386'<tt>sideeffect</tt>' keyword, like so:
1387</p>
1388
1389<pre>
1390 call void asm sideeffect "eieio", ""()
1391</pre>
1392
1393<p>TODO: The format of the asm and constraints string still need to be
1394documented here. Constraints on what can be done (e.g. duplication, moving, etc
1395need to be documented).
1396</p>
1397
1398</div>
1399
1400<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001401<div class="doc_section"> <a name="instref">Instruction Reference</a> </div>
1402<!-- *********************************************************************** -->
Chris Lattner74d3f822004-12-09 17:30:23 +00001403
Misha Brukman76307852003-11-08 01:05:38 +00001404<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001405
Chris Lattner48b383b02003-11-25 01:02:51 +00001406<p>The LLVM instruction set consists of several different
1407classifications of instructions: <a href="#terminators">terminator
John Criswell4a3327e2005-05-13 22:25:59 +00001408instructions</a>, <a href="#binaryops">binary instructions</a>,
1409<a href="#bitwiseops">bitwise binary instructions</a>, <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001410 href="#memoryops">memory instructions</a>, and <a href="#otherops">other
1411instructions</a>.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001412
Misha Brukman76307852003-11-08 01:05:38 +00001413</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001414
Chris Lattner2f7c9632001-06-06 20:29:01 +00001415<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001416<div class="doc_subsection"> <a name="terminators">Terminator
1417Instructions</a> </div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001418
Misha Brukman76307852003-11-08 01:05:38 +00001419<div class="doc_text">
Chris Lattner74d3f822004-12-09 17:30:23 +00001420
Chris Lattner48b383b02003-11-25 01:02:51 +00001421<p>As mentioned <a href="#functionstructure">previously</a>, every
1422basic block in a program ends with a "Terminator" instruction, which
1423indicates which block should be executed after the current block is
1424finished. These terminator instructions typically yield a '<tt>void</tt>'
1425value: they produce control flow, not values (the one exception being
1426the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p>
John Criswelldfe6a862004-12-10 15:51:16 +00001427<p>There are six different terminator instructions: the '<a
Chris Lattner48b383b02003-11-25 01:02:51 +00001428 href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>'
1429instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction,
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001430the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a
1431 href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a
1432 href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p>
Chris Lattner74d3f822004-12-09 17:30:23 +00001433
Misha Brukman76307852003-11-08 01:05:38 +00001434</div>
Chris Lattner74d3f822004-12-09 17:30:23 +00001435
Chris Lattner2f7c9632001-06-06 20:29:01 +00001436<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001437<div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>'
1438Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001439<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001440<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001441<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 +00001442 ret void <i>; Return from void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001443</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001444<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001445<p>The '<tt>ret</tt>' instruction is used to return control flow (and a
John Criswell4a3327e2005-05-13 22:25:59 +00001446value) from a function back to the caller.</p>
John Criswell417228d2004-04-09 16:48:45 +00001447<p>There are two forms of the '<tt>ret</tt>' instruction: one that
Chris Lattner48b383b02003-11-25 01:02:51 +00001448returns a value and then causes control flow, and one that just causes
1449control flow to occur.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001450<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001451<p>The '<tt>ret</tt>' instruction may return any '<a
1452 href="#t_firstclass">first class</a>' type. Notice that a function is
1453not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>'
1454instruction inside of the function that returns a value that does not
1455match the return type of the function.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001456<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001457<p>When the '<tt>ret</tt>' instruction is executed, control flow
1458returns back to the calling function's context. If the caller is a "<a
John Criswell40db33f2004-06-25 15:16:57 +00001459 href="#i_call"><tt>call</tt></a>" instruction, execution continues at
Chris Lattner48b383b02003-11-25 01:02:51 +00001460the instruction after the call. If the caller was an "<a
1461 href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues
John Criswell02fdc6f2005-05-12 16:52:32 +00001462at the beginning of the "normal" destination block. If the instruction
Chris Lattner48b383b02003-11-25 01:02:51 +00001463returns a value, that value shall set the call or invoke instruction's
1464return value.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001465<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001466<pre> ret int 5 <i>; Return an integer value of 5</i>
Chris Lattner590645f2002-04-14 06:13:44 +00001467 ret void <i>; Return from a void function</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001468</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001469</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001470<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001471<div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001472<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001473<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001474<pre> br bool &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 +00001475</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001476<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001477<p>The '<tt>br</tt>' instruction is used to cause control flow to
1478transfer to a different basic block in the current function. There are
1479two forms of this instruction, corresponding to a conditional branch
1480and an unconditional branch.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001481<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001482<p>The conditional branch form of the '<tt>br</tt>' instruction takes a
1483single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The
1484unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>'
1485value as a target.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001486<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001487<p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>'
1488argument is evaluated. If the value is <tt>true</tt>, control flows
1489to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>,
1490control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001491<h5>Example:</h5>
Reid Spencere0083262006-11-18 21:55:45 +00001492<pre>Test:<br> %cond = <a href="#i_icmp">icmp</a> eq, int %a, %b<br> br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001493 href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre>
Misha Brukman76307852003-11-08 01:05:38 +00001494</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001495<!-- _______________________________________________________________________ -->
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001496<div class="doc_subsubsection">
1497 <a name="i_switch">'<tt>switch</tt>' Instruction</a>
1498</div>
1499
Misha Brukman76307852003-11-08 01:05:38 +00001500<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001501<h5>Syntax:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001502
1503<pre>
1504 switch &lt;intty&gt; &lt;value&gt;, label &lt;defaultdest&gt; [ &lt;intty&gt; &lt;val&gt;, label &lt;dest&gt; ... ]
1505</pre>
1506
Chris Lattner2f7c9632001-06-06 20:29:01 +00001507<h5>Overview:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001508
1509<p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of
1510several different places. It is a generalization of the '<tt>br</tt>'
Misha Brukman76307852003-11-08 01:05:38 +00001511instruction, allowing a branch to occur to one of many possible
1512destinations.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001513
1514
Chris Lattner2f7c9632001-06-06 20:29:01 +00001515<h5>Arguments:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001516
1517<p>The '<tt>switch</tt>' instruction uses three parameters: an integer
1518comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and
1519an array of pairs of comparison value constants and '<tt>label</tt>'s. The
1520table is not allowed to contain duplicate constant entries.</p>
1521
Chris Lattner2f7c9632001-06-06 20:29:01 +00001522<h5>Semantics:</h5>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001523
Chris Lattner48b383b02003-11-25 01:02:51 +00001524<p>The <tt>switch</tt> instruction specifies a table of values and
1525destinations. When the '<tt>switch</tt>' instruction is executed, this
John Criswellbcbb18c2004-06-25 16:05:06 +00001526table is searched for the given value. If the value is found, control flow is
1527transfered to the corresponding destination; otherwise, control flow is
1528transfered to the default destination.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001529
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001530<h5>Implementation:</h5>
1531
1532<p>Depending on properties of the target machine and the particular
1533<tt>switch</tt> instruction, this instruction may be code generated in different
John Criswellbcbb18c2004-06-25 16:05:06 +00001534ways. For example, it could be generated as a series of chained conditional
1535branches or with a lookup table.</p>
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001536
1537<h5>Example:</h5>
1538
1539<pre>
1540 <i>; Emulate a conditional br instruction</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00001541 %Val = <a href="#i_zext">zext</a> bool %value to int
Chris Lattnercf96c6c2004-02-24 04:54:45 +00001542 switch int %Val, label %truedest [int 0, label %falsedest ]
1543
1544 <i>; Emulate an unconditional br instruction</i>
1545 switch uint 0, label %dest [ ]
1546
1547 <i>; Implement a jump table:</i>
1548 switch uint %val, label %otherwise [ uint 0, label %onzero
1549 uint 1, label %onone
1550 uint 2, label %ontwo ]
Chris Lattner2f7c9632001-06-06 20:29:01 +00001551</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001552</div>
Chris Lattner0132aff2005-05-06 22:57:40 +00001553
Chris Lattner2f7c9632001-06-06 20:29:01 +00001554<!-- _______________________________________________________________________ -->
Chris Lattner0132aff2005-05-06 22:57:40 +00001555<div class="doc_subsubsection">
1556 <a name="i_invoke">'<tt>invoke</tt>' Instruction</a>
1557</div>
1558
Misha Brukman76307852003-11-08 01:05:38 +00001559<div class="doc_text">
Chris Lattner0132aff2005-05-06 22:57:40 +00001560
Chris Lattner2f7c9632001-06-06 20:29:01 +00001561<h5>Syntax:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001562
1563<pre>
1564 &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 +00001565 to label &lt;normal label&gt; unwind label &lt;exception label&gt;
Chris Lattner0132aff2005-05-06 22:57:40 +00001566</pre>
1567
Chris Lattnera8292f32002-05-06 22:08:29 +00001568<h5>Overview:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001569
1570<p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified
1571function, with the possibility of control flow transfer to either the
John Criswell02fdc6f2005-05-12 16:52:32 +00001572'<tt>normal</tt>' label or the
1573'<tt>exception</tt>' label. If the callee function returns with the
Chris Lattner0132aff2005-05-06 22:57:40 +00001574"<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the
1575"normal" label. If the callee (or any indirect callees) returns with the "<a
John Criswell02fdc6f2005-05-12 16:52:32 +00001576href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and
1577continued at the dynamically nearest "exception" label.</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001578
Chris Lattner2f7c9632001-06-06 20:29:01 +00001579<h5>Arguments:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001580
Misha Brukman76307852003-11-08 01:05:38 +00001581<p>This instruction requires several arguments:</p>
Chris Lattner0132aff2005-05-06 22:57:40 +00001582
Chris Lattner2f7c9632001-06-06 20:29:01 +00001583<ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001584 <li>
John Criswell4a3327e2005-05-13 22:25:59 +00001585 The optional "cconv" marker indicates which <a href="callingconv">calling
Chris Lattner0132aff2005-05-06 22:57:40 +00001586 convention</a> the call should use. If none is specified, the call defaults
1587 to using C calling conventions.
1588 </li>
1589 <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to
1590 function value being invoked. In most cases, this is a direct function
1591 invocation, but indirect <tt>invoke</tt>s are just as possible, branching off
1592 an arbitrary pointer to function value.
1593 </li>
1594
1595 <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a
1596 function to be invoked. </li>
1597
1598 <li>'<tt>function args</tt>': argument list whose types match the function
1599 signature argument types. If the function signature indicates the function
1600 accepts a variable number of arguments, the extra arguments can be
1601 specified. </li>
1602
1603 <li>'<tt>normal label</tt>': the label reached when the called function
1604 executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li>
1605
1606 <li>'<tt>exception label</tt>': the label reached when a callee returns with
1607 the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li>
1608
Chris Lattner2f7c9632001-06-06 20:29:01 +00001609</ol>
Chris Lattner0132aff2005-05-06 22:57:40 +00001610
Chris Lattner2f7c9632001-06-06 20:29:01 +00001611<h5>Semantics:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001612
Misha Brukman76307852003-11-08 01:05:38 +00001613<p>This instruction is designed to operate as a standard '<tt><a
Chris Lattner0132aff2005-05-06 22:57:40 +00001614href="#i_call">call</a></tt>' instruction in most regards. The primary
1615difference is that it establishes an association with a label, which is used by
1616the runtime library to unwind the stack.</p>
1617
1618<p>This instruction is used in languages with destructors to ensure that proper
1619cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown
1620exception. Additionally, this is important for implementation of
1621'<tt>catch</tt>' clauses in high-level languages that support them.</p>
1622
Chris Lattner2f7c9632001-06-06 20:29:01 +00001623<h5>Example:</h5>
Chris Lattner0132aff2005-05-06 22:57:40 +00001624<pre>
1625 %retval = invoke int %Test(int 15) to label %Continue
Chris Lattner6b7a0082006-05-14 18:23:06 +00001626 unwind label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner0132aff2005-05-06 22:57:40 +00001627 %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue
Chris Lattner6b7a0082006-05-14 18:23:06 +00001628 unwind label %TestCleanup <i>; {int}:retval set</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001629</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001630</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001631
1632
Chris Lattner5ed60612003-09-03 00:41:47 +00001633<!-- _______________________________________________________________________ -->
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001634
Chris Lattner48b383b02003-11-25 01:02:51 +00001635<div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>'
1636Instruction</a> </div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001637
Misha Brukman76307852003-11-08 01:05:38 +00001638<div class="doc_text">
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001639
Chris Lattner5ed60612003-09-03 00:41:47 +00001640<h5>Syntax:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001641<pre>
1642 unwind
1643</pre>
1644
Chris Lattner5ed60612003-09-03 00:41:47 +00001645<h5>Overview:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001646
1647<p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow
1648at the first callee in the dynamic call stack which used an <a
1649href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is
1650primarily used to implement exception handling.</p>
1651
Chris Lattner5ed60612003-09-03 00:41:47 +00001652<h5>Semantics:</h5>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001653
1654<p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to
1655immediately halt. The dynamic call stack is then searched for the first <a
1656href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found,
1657execution continues at the "exceptional" destination block specified by the
1658<tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the
1659dynamic call chain, undefined behavior results.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001660</div>
Chris Lattner08b7d5b2004-10-16 18:04:13 +00001661
1662<!-- _______________________________________________________________________ -->
1663
1664<div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>'
1665Instruction</a> </div>
1666
1667<div class="doc_text">
1668
1669<h5>Syntax:</h5>
1670<pre>
1671 unreachable
1672</pre>
1673
1674<h5>Overview:</h5>
1675
1676<p>The '<tt>unreachable</tt>' instruction has no defined semantics. This
1677instruction is used to inform the optimizer that a particular portion of the
1678code is not reachable. This can be used to indicate that the code after a
1679no-return function cannot be reached, and other facts.</p>
1680
1681<h5>Semantics:</h5>
1682
1683<p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p>
1684</div>
1685
1686
1687
Chris Lattner2f7c9632001-06-06 20:29:01 +00001688<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001689<div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001690<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001691<p>Binary operators are used to do most of the computation in a
1692program. They require two operands, execute an operation on them, and
John Criswelldfe6a862004-12-10 15:51:16 +00001693produce a single value. The operands might represent
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001694multiple data, as is the case with the <a href="#t_packed">packed</a> data type.
1695The result value of a binary operator is not
Chris Lattner48b383b02003-11-25 01:02:51 +00001696necessarily the same type as its operands.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001697<p>There are several different binary operators:</p>
Misha Brukman76307852003-11-08 01:05:38 +00001698</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001699<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001700<div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>'
1701Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001702<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001703<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001704<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 +00001705</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001706<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001707<p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001708<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001709<p>The two arguments to the '<tt>add</tt>' instruction must be either <a
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001710 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values.
1711 This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1712Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001713<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001714<p>The value produced is the integer or floating point sum of the two
1715operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001716<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001717<pre> &lt;result&gt; = add int 4, %var <i>; yields {int}:result = 4 + %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001718</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001719</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001720<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001721<div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>'
1722Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001723<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001724<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001725<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 +00001726</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001727<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001728<p>The '<tt>sub</tt>' instruction returns the difference of its two
1729operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001730<p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>'
1731instruction present in most other intermediate representations.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001732<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001733<p>The two arguments to the '<tt>sub</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001734 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001735values.
1736This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1737Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001738<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001739<p>The value produced is the integer or floating point difference of
1740the two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001741<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001742<pre> &lt;result&gt; = sub int 4, %var <i>; yields {int}:result = 4 - %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001743 &lt;result&gt; = sub int 0, %val <i>; yields {int}:result = -%var</i>
1744</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001745</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001746<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001747<div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>'
1748Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001749<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001750<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001751<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 +00001752</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001753<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001754<p>The '<tt>mul</tt>' instruction returns the product of its two
1755operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001756<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001757<p>The two arguments to the '<tt>mul</tt>' instruction must be either <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001758 href="#t_integer">integer</a> or <a href="#t_floating">floating point</a>
Chris Lattnerc8cb6952004-08-12 19:12:28 +00001759values.
1760This instruction can also take <a href="#t_packed">packed</a> versions of the values.
1761Both arguments must have identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001762<h5>Semantics:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001763<p>The value produced is the integer or floating point product of the
Misha Brukman76307852003-11-08 01:05:38 +00001764two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001765<p>There is no signed vs unsigned multiplication. The appropriate
1766action is taken based on the type of the operand.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001767<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001768<pre> &lt;result&gt; = mul int 4, %var <i>; yields {int}:result = 4 * %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001769</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001770</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001771<!-- _______________________________________________________________________ -->
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001772<div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction
1773</a></div>
1774<div class="doc_text">
1775<h5>Syntax:</h5>
1776<pre> &lt;result&gt; = udiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1777</pre>
1778<h5>Overview:</h5>
1779<p>The '<tt>udiv</tt>' instruction returns the quotient of its two
1780operands.</p>
1781<h5>Arguments:</h5>
1782<p>The two arguments to the '<tt>udiv</tt>' instruction must be
1783<a href="#t_integer">integer</a> values. Both arguments must have identical
1784types. This instruction can also take <a href="#t_packed">packed</a> versions
1785of the values in which case the elements must be integers.</p>
1786<h5>Semantics:</h5>
1787<p>The value produced is the unsigned integer quotient of the two operands. This
1788instruction always performs an unsigned division operation, regardless of
1789whether the arguments are unsigned or not.</p>
1790<h5>Example:</h5>
1791<pre> &lt;result&gt; = udiv uint 4, %var <i>; yields {uint}:result = 4 / %var</i>
1792</pre>
1793</div>
1794<!-- _______________________________________________________________________ -->
1795<div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction
1796</a> </div>
1797<div class="doc_text">
1798<h5>Syntax:</h5>
1799<pre> &lt;result&gt; = sdiv &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1800</pre>
1801<h5>Overview:</h5>
1802<p>The '<tt>sdiv</tt>' instruction returns the quotient of its two
1803operands.</p>
1804<h5>Arguments:</h5>
1805<p>The two arguments to the '<tt>sdiv</tt>' instruction must be
1806<a href="#t_integer">integer</a> values. Both arguments must have identical
1807types. This instruction can also take <a href="#t_packed">packed</a> versions
1808of the values in which case the elements must be integers.</p>
1809<h5>Semantics:</h5>
1810<p>The value produced is the signed integer quotient of the two operands. This
1811instruction always performs a signed division operation, regardless of whether
1812the arguments are signed or not.</p>
1813<h5>Example:</h5>
1814<pre> &lt;result&gt; = sdiv int 4, %var <i>; yields {int}:result = 4 / %var</i>
1815</pre>
1816</div>
1817<!-- _______________________________________________________________________ -->
1818<div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001819Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001820<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001821<h5>Syntax:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001822<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 +00001823</pre>
1824<h5>Overview:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001825<p>The '<tt>fdiv</tt>' instruction returns the quotient of its two
Chris Lattner48b383b02003-11-25 01:02:51 +00001826operands.</p>
1827<h5>Arguments:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001828<p>The two arguments to the '<tt>div</tt>' instruction must be
1829<a href="#t_floating">floating point</a> values. Both arguments must have
1830identical types. This instruction can also take <a href="#t_packed">packed</a>
1831versions of the values in which case the elements must be floating point.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001832<h5>Semantics:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001833<p>The value produced is the floating point quotient of the two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001834<h5>Example:</h5>
Reid Spencer7e80b0b2006-10-26 06:15:43 +00001835<pre> &lt;result&gt; = fdiv float 4.0, %var <i>; yields {float}:result = 4.0 / %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001836</pre>
1837</div>
1838<!-- _______________________________________________________________________ -->
Reid Spencer7eb55b32006-11-02 01:53:59 +00001839<div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a>
1840</div>
1841<div class="doc_text">
1842<h5>Syntax:</h5>
1843<pre> &lt;result&gt; = urem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1844</pre>
1845<h5>Overview:</h5>
1846<p>The '<tt>urem</tt>' instruction returns the remainder from the
1847unsigned division of its two arguments.</p>
1848<h5>Arguments:</h5>
1849<p>The two arguments to the '<tt>urem</tt>' instruction must be
1850<a href="#t_integer">integer</a> values. Both arguments must have identical
1851types.</p>
1852<h5>Semantics:</h5>
1853<p>This instruction returns the unsigned integer <i>remainder</i> of a division.
1854This instruction always performs an unsigned division to get the remainder,
1855regardless of whether the arguments are unsigned or not.</p>
1856<h5>Example:</h5>
1857<pre> &lt;result&gt; = urem uint 4, %var <i>; yields {uint}:result = 4 % %var</i>
1858</pre>
1859
1860</div>
1861<!-- _______________________________________________________________________ -->
1862<div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00001863Instruction</a> </div>
1864<div class="doc_text">
1865<h5>Syntax:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001866<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 +00001867</pre>
1868<h5>Overview:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001869<p>The '<tt>srem</tt>' instruction returns the remainder from the
1870signed division of its two operands.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001871<h5>Arguments:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001872<p>The two arguments to the '<tt>srem</tt>' instruction must be
1873<a href="#t_integer">integer</a> values. Both arguments must have identical
1874types.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001875<h5>Semantics:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001876<p>This instruction returns the <i>remainder</i> of a division (where the result
Chris Lattner48b383b02003-11-25 01:02:51 +00001877has the same sign as the divisor), not the <i>modulus</i> (where the
1878result has the same sign as the dividend) of a value. For more
John Criswell4c0cf7f2005-10-24 16:17:18 +00001879information about the difference, see <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001880 href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The
1881Math Forum</a>.</p>
1882<h5>Example:</h5>
Reid Spencer7eb55b32006-11-02 01:53:59 +00001883<pre> &lt;result&gt; = srem int 4, %var <i>; yields {int}:result = 4 % %var</i>
1884</pre>
1885
1886</div>
1887<!-- _______________________________________________________________________ -->
1888<div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>'
1889Instruction</a> </div>
1890<div class="doc_text">
1891<h5>Syntax:</h5>
1892<pre> &lt;result&gt; = frem &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {ty}:result</i>
1893</pre>
1894<h5>Overview:</h5>
1895<p>The '<tt>frem</tt>' instruction returns the remainder from the
1896division of its two operands.</p>
1897<h5>Arguments:</h5>
1898<p>The two arguments to the '<tt>frem</tt>' instruction must be
1899<a href="#t_floating">floating point</a> values. Both arguments must have
1900identical types.</p>
1901<h5>Semantics:</h5>
1902<p>This instruction returns the <i>remainder</i> of a division.</p>
1903<h5>Example:</h5>
1904<pre> &lt;result&gt; = frem float 4.0, %var <i>; yields {float}:result = 4.0 % %var</i>
Chris Lattner48b383b02003-11-25 01:02:51 +00001905</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001906</div>
Robert Bocchino820bc75b2006-02-17 21:18:08 +00001907
Chris Lattner2f7c9632001-06-06 20:29:01 +00001908<!-- ======================================================================= -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001909<div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary
1910Operations</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001911<div class="doc_text">
Chris Lattner48b383b02003-11-25 01:02:51 +00001912<p>Bitwise binary operators are used to do various forms of
1913bit-twiddling in a program. They are generally very efficient
John Criswelldfe6a862004-12-10 15:51:16 +00001914instructions and can commonly be strength reduced from other
Chris Lattner48b383b02003-11-25 01:02:51 +00001915instructions. They require two operands, execute an operation on them,
1916and produce a single value. The resulting value of the bitwise binary
1917operators is always the same type as its first operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00001918</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001919<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001920<div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>'
1921Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001922<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001923<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001924<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 +00001925</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001926<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001927<p>The '<tt>and</tt>' instruction returns the bitwise logical and of
1928its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001929<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001930<p>The two arguments to the '<tt>and</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001931 href="#t_integral">integral</a> values. Both arguments must have
1932identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001933<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001934<p>The truth table used for the '<tt>and</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001935<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001936<div style="align: center">
Misha Brukman76307852003-11-08 01:05:38 +00001937<table border="1" cellspacing="0" cellpadding="4">
Chris Lattner48b383b02003-11-25 01:02:51 +00001938 <tbody>
1939 <tr>
1940 <td>In0</td>
1941 <td>In1</td>
1942 <td>Out</td>
1943 </tr>
1944 <tr>
1945 <td>0</td>
1946 <td>0</td>
1947 <td>0</td>
1948 </tr>
1949 <tr>
1950 <td>0</td>
1951 <td>1</td>
1952 <td>0</td>
1953 </tr>
1954 <tr>
1955 <td>1</td>
1956 <td>0</td>
1957 <td>0</td>
1958 </tr>
1959 <tr>
1960 <td>1</td>
1961 <td>1</td>
1962 <td>1</td>
1963 </tr>
1964 </tbody>
1965</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00001966</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001967<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001968<pre> &lt;result&gt; = and int 4, %var <i>; yields {int}:result = 4 &amp; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001969 &lt;result&gt; = and int 15, 40 <i>; yields {int}:result = 8</i>
1970 &lt;result&gt; = and int 4, 8 <i>; yields {int}:result = 0</i>
1971</pre>
Misha Brukman76307852003-11-08 01:05:38 +00001972</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001973<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00001974<div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00001975<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00001976<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00001977<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 +00001978</pre>
Chris Lattner48b383b02003-11-25 01:02:51 +00001979<h5>Overview:</h5>
1980<p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive
1981or of its two operands.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001982<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001983<p>The two arguments to the '<tt>or</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00001984 href="#t_integral">integral</a> values. Both arguments must have
1985identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00001986<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00001987<p>The truth table used for the '<tt>or</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00001988<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00001989<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00001990<table border="1" cellspacing="0" cellpadding="4">
1991 <tbody>
1992 <tr>
1993 <td>In0</td>
1994 <td>In1</td>
1995 <td>Out</td>
1996 </tr>
1997 <tr>
1998 <td>0</td>
1999 <td>0</td>
2000 <td>0</td>
2001 </tr>
2002 <tr>
2003 <td>0</td>
2004 <td>1</td>
2005 <td>1</td>
2006 </tr>
2007 <tr>
2008 <td>1</td>
2009 <td>0</td>
2010 <td>1</td>
2011 </tr>
2012 <tr>
2013 <td>1</td>
2014 <td>1</td>
2015 <td>1</td>
2016 </tr>
2017 </tbody>
2018</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002019</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002020<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002021<pre> &lt;result&gt; = or int 4, %var <i>; yields {int}:result = 4 | %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002022 &lt;result&gt; = or int 15, 40 <i>; yields {int}:result = 47</i>
2023 &lt;result&gt; = or int 4, 8 <i>; yields {int}:result = 12</i>
2024</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002025</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002026<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002027<div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>'
2028Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002029<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002030<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002031<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 +00002032</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002033<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002034<p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive
2035or of its two operands. The <tt>xor</tt> is used to implement the
2036"one's complement" operation, which is the "~" operator in C.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002037<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002038<p>The two arguments to the '<tt>xor</tt>' instruction must be <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002039 href="#t_integral">integral</a> values. Both arguments must have
2040identical types.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002041<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002042<p>The truth table used for the '<tt>xor</tt>' instruction is:</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00002043<p> </p>
Misha Brukmanc501f552004-03-01 17:47:27 +00002044<div style="align: center">
Chris Lattner48b383b02003-11-25 01:02:51 +00002045<table border="1" cellspacing="0" cellpadding="4">
2046 <tbody>
2047 <tr>
2048 <td>In0</td>
2049 <td>In1</td>
2050 <td>Out</td>
2051 </tr>
2052 <tr>
2053 <td>0</td>
2054 <td>0</td>
2055 <td>0</td>
2056 </tr>
2057 <tr>
2058 <td>0</td>
2059 <td>1</td>
2060 <td>1</td>
2061 </tr>
2062 <tr>
2063 <td>1</td>
2064 <td>0</td>
2065 <td>1</td>
2066 </tr>
2067 <tr>
2068 <td>1</td>
2069 <td>1</td>
2070 <td>0</td>
2071 </tr>
2072 </tbody>
2073</table>
Misha Brukmanc501f552004-03-01 17:47:27 +00002074</div>
Chris Lattner48b383b02003-11-25 01:02:51 +00002075<p> </p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002076<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002077<pre> &lt;result&gt; = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002078 &lt;result&gt; = xor int 15, 40 <i>; yields {int}:result = 39</i>
2079 &lt;result&gt; = xor int 4, 8 <i>; yields {int}:result = 12</i>
Chris Lattner5ed60612003-09-03 00:41:47 +00002080 &lt;result&gt; = xor int %V, -1 <i>; yields {int}:result = ~%V</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002081</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002082</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002083<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002084<div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>'
2085Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002086<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002087<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002088<pre> &lt;result&gt; = shl &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002089</pre>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002090<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002091<p>The '<tt>shl</tt>' instruction returns the first operand shifted to
2092the left a specified number of bits.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002093<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002094<p>The first argument to the '<tt>shl</tt>' instruction must be an <a
Chris Lattner48b383b02003-11-25 01:02:51 +00002095 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>'
2096type.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002097<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002098<p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002099<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002100<pre> &lt;result&gt; = shl int 4, ubyte %var <i>; yields {int}:result = 4 &lt;&lt; %var</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002101 &lt;result&gt; = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i>
2102 &lt;result&gt; = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i>
2103</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002104</div>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002105<!-- _______________________________________________________________________ -->
Reid Spencerfdff9382006-11-08 06:47:33 +00002106<div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>'
Chris Lattner48b383b02003-11-25 01:02:51 +00002107Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002108<div class="doc_text">
Chris Lattner2f7c9632001-06-06 20:29:01 +00002109<h5>Syntax:</h5>
Reid Spencerfdff9382006-11-08 06:47:33 +00002110<pre> &lt;result&gt; = lshr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002111</pre>
Reid Spencerfdff9382006-11-08 06:47:33 +00002112
Chris Lattner2f7c9632001-06-06 20:29:01 +00002113<h5>Overview:</h5>
Reid Spencerfdff9382006-11-08 06:47:33 +00002114<p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first
2115operand shifted to the right a specified number of bits.</p>
2116
Chris Lattner2f7c9632001-06-06 20:29:01 +00002117<h5>Arguments:</h5>
Reid Spencerfdff9382006-11-08 06:47:33 +00002118<p>The first argument to the '<tt>lshr</tt>' instruction must be an <a
2119 href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' type.</p>
2120
Chris Lattner2f7c9632001-06-06 20:29:01 +00002121<h5>Semantics:</h5>
Reid Spencerfdff9382006-11-08 06:47:33 +00002122<p>This instruction always performs a logical shift right operation, regardless
2123of whether the arguments are unsigned or not. The <tt>var2</tt> most significant
2124bits will be filled with zero bits after the shift.</p>
2125
Chris Lattner2f7c9632001-06-06 20:29:01 +00002126<h5>Example:</h5>
Reid Spencerfdff9382006-11-08 06:47:33 +00002127<pre>
2128 &lt;result&gt; = lshr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
2129 &lt;result&gt; = lshr int 4, ubyte 2 <i>; yields {uint}:result = 1</i>
2130 &lt;result&gt; = lshr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i>
2131 &lt;result&gt; = lshr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = 0x7FFFFFFF </i>
2132</pre>
2133</div>
2134
2135<!-- ======================================================================= -->
2136<div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>'
2137Instruction</a> </div>
2138<div class="doc_text">
2139
2140<h5>Syntax:</h5>
2141<pre> &lt;result&gt; = ashr &lt;ty&gt; &lt;var1&gt;, ubyte &lt;var2&gt; <i>; yields {ty}:result</i>
2142</pre>
2143
2144<h5>Overview:</h5>
2145<p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first
2146operand shifted to the right a specified number of bits.</p>
2147
2148<h5>Arguments:</h5>
2149<p>The first argument to the '<tt>ashr</tt>' instruction must be an
2150<a href="#t_integer">integer</a> type. The second argument must be an
2151'<tt>ubyte</tt>' type.</p>
2152
2153<h5>Semantics:</h5>
2154<p>This instruction always performs an arithmetic shift right operation,
2155regardless of whether the arguments are signed or not. The <tt>var2</tt> most
2156significant bits will be filled with the sign bit of <tt>var1</tt>.</p>
2157
2158<h5>Example:</h5>
2159<pre>
2160 &lt;result&gt; = ashr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i>
2161 &lt;result&gt; = ashr int 4, ubyte 2 <i>; yields {int}:result = 1</i>
2162 &lt;result&gt; = ashr ubyte 4, ubyte 3 <i>; yields {ubyte}:result = 0</i>
2163 &lt;result&gt; = ashr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002164</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002165</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002166
Chris Lattner2f7c9632001-06-06 20:29:01 +00002167<!-- ======================================================================= -->
Chris Lattner54611b42005-11-06 08:02:57 +00002168<div class="doc_subsection">
Chris Lattnerce83bff2006-04-08 23:07:04 +00002169 <a name="vectorops">Vector Operations</a>
2170</div>
2171
2172<div class="doc_text">
2173
2174<p>LLVM supports several instructions to represent vector operations in a
2175target-independent manner. This instructions cover the element-access and
2176vector-specific operations needed to process vectors effectively. While LLVM
2177does directly support these vector operations, many sophisticated algorithms
2178will want to use target-specific intrinsics to take full advantage of a specific
2179target.</p>
2180
2181</div>
2182
2183<!-- _______________________________________________________________________ -->
2184<div class="doc_subsubsection">
2185 <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a>
2186</div>
2187
2188<div class="doc_text">
2189
2190<h5>Syntax:</h5>
2191
2192<pre>
2193 &lt;result&gt; = extractelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, uint &lt;idx&gt; <i>; yields &lt;ty&gt;</i>
2194</pre>
2195
2196<h5>Overview:</h5>
2197
2198<p>
2199The '<tt>extractelement</tt>' instruction extracts a single scalar
2200element from a packed vector at a specified index.
2201</p>
2202
2203
2204<h5>Arguments:</h5>
2205
2206<p>
2207The first operand of an '<tt>extractelement</tt>' instruction is a
2208value of <a href="#t_packed">packed</a> type. The second operand is
2209an index indicating the position from which to extract the element.
2210The index may be a variable.</p>
2211
2212<h5>Semantics:</h5>
2213
2214<p>
2215The result is a scalar of the same type as the element type of
2216<tt>val</tt>. Its value is the value at position <tt>idx</tt> of
2217<tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the
2218results are undefined.
2219</p>
2220
2221<h5>Example:</h5>
2222
2223<pre>
2224 %result = extractelement &lt;4 x int&gt; %vec, uint 0 <i>; yields int</i>
2225</pre>
2226</div>
2227
2228
2229<!-- _______________________________________________________________________ -->
2230<div class="doc_subsubsection">
2231 <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a>
2232</div>
2233
2234<div class="doc_text">
2235
2236<h5>Syntax:</h5>
2237
2238<pre>
2239 &lt;result&gt; = insertelement &lt;n x &lt;ty&gt;&gt; &lt;val&gt;, &lt;ty&gt; &lt;elt&gt, uint &lt;idx&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2240</pre>
2241
2242<h5>Overview:</h5>
2243
2244<p>
2245The '<tt>insertelement</tt>' instruction inserts a scalar
2246element into a packed vector at a specified index.
2247</p>
2248
2249
2250<h5>Arguments:</h5>
2251
2252<p>
2253The first operand of an '<tt>insertelement</tt>' instruction is a
2254value of <a href="#t_packed">packed</a> type. The second operand is a
2255scalar value whose type must equal the element type of the first
2256operand. The third operand is an index indicating the position at
2257which to insert the value. The index may be a variable.</p>
2258
2259<h5>Semantics:</h5>
2260
2261<p>
2262The result is a packed vector of the same type as <tt>val</tt>. Its
2263element values are those of <tt>val</tt> except at position
2264<tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt>
2265exceeds the length of <tt>val</tt>, the results are undefined.
2266</p>
2267
2268<h5>Example:</h5>
2269
2270<pre>
2271 %result = insertelement &lt;4 x int&gt; %vec, int 1, uint 0 <i>; yields &lt;4 x int&gt;</i>
2272</pre>
2273</div>
2274
2275<!-- _______________________________________________________________________ -->
2276<div class="doc_subsubsection">
2277 <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a>
2278</div>
2279
2280<div class="doc_text">
2281
2282<h5>Syntax:</h5>
2283
2284<pre>
2285 &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 uint&gt; &lt;mask&gt; <i>; yields &lt;n x &lt;ty&gt;&gt;</i>
2286</pre>
2287
2288<h5>Overview:</h5>
2289
2290<p>
2291The '<tt>shufflevector</tt>' instruction constructs a permutation of elements
2292from two input vectors, returning a vector of the same type.
2293</p>
2294
2295<h5>Arguments:</h5>
2296
2297<p>
2298The first two operands of a '<tt>shufflevector</tt>' instruction are vectors
2299with types that match each other and types that match the result of the
2300instruction. The third argument is a shuffle mask, which has the same number
2301of elements as the other vector type, but whose element type is always 'uint'.
2302</p>
2303
2304<p>
2305The shuffle mask operand is required to be a constant vector with either
2306constant integer or undef values.
2307</p>
2308
2309<h5>Semantics:</h5>
2310
2311<p>
2312The elements of the two input vectors are numbered from left to right across
2313both of the vectors. The shuffle mask operand specifies, for each element of
2314the result vector, which element of the two input registers the result element
2315gets. The element selector may be undef (meaning "don't care") and the second
2316operand may be undef if performing a shuffle from only one vector.
2317</p>
2318
2319<h5>Example:</h5>
2320
2321<pre>
2322 %result = shufflevector &lt;4 x int&gt; %v1, &lt;4 x int&gt; %v2,
2323 &lt;4 x uint&gt; &lt;uint 0, uint 4, uint 1, uint 5&gt; <i>; yields &lt;4 x int&gt;</i>
2324 %result = shufflevector &lt;4 x int&gt; %v1, &lt;4 x int&gt; undef,
2325 &lt;4 x uint&gt; &lt;uint 0, uint 1, uint 2, uint 3&gt; <i>; yields &lt;4 x int&gt;</i> - Identity shuffle.
2326</pre>
2327</div>
2328
Tanya Lattnerb138bbe2006-04-14 19:24:33 +00002329
Chris Lattnerce83bff2006-04-08 23:07:04 +00002330<!-- ======================================================================= -->
2331<div class="doc_subsection">
Chris Lattner6ab66722006-08-15 00:45:58 +00002332 <a name="memoryops">Memory Access and Addressing Operations</a>
Chris Lattner54611b42005-11-06 08:02:57 +00002333</div>
2334
Misha Brukman76307852003-11-08 01:05:38 +00002335<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002336
Chris Lattner48b383b02003-11-25 01:02:51 +00002337<p>A key design point of an SSA-based representation is how it
2338represents memory. In LLVM, no memory locations are in SSA form, which
2339makes things very simple. This section describes how to read, write,
John Criswelldfe6a862004-12-10 15:51:16 +00002340allocate, and free memory in LLVM.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002341
Misha Brukman76307852003-11-08 01:05:38 +00002342</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002343
Chris Lattner2f7c9632001-06-06 20:29:01 +00002344<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002345<div class="doc_subsubsection">
2346 <a name="i_malloc">'<tt>malloc</tt>' Instruction</a>
2347</div>
2348
Misha Brukman76307852003-11-08 01:05:38 +00002349<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002350
Chris Lattner2f7c9632001-06-06 20:29:01 +00002351<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002352
2353<pre>
2354 &lt;result&gt; = malloc &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002355</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002356
Chris Lattner2f7c9632001-06-06 20:29:01 +00002357<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002358
Chris Lattner48b383b02003-11-25 01:02:51 +00002359<p>The '<tt>malloc</tt>' instruction allocates memory from the system
2360heap and returns a pointer to it.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002361
Chris Lattner2f7c9632001-06-06 20:29:01 +00002362<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002363
2364<p>The '<tt>malloc</tt>' instruction allocates
2365<tt>sizeof(&lt;type&gt;)*NumElements</tt>
John Criswella92e5862004-02-24 16:13:56 +00002366bytes of memory from the operating system and returns a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002367appropriate type to the program. If "NumElements" is specified, it is the
2368number of elements allocated. If an alignment is specified, the value result
2369of the allocation is guaranteed to be aligned to at least that boundary. If
2370not specified, or if zero, the target can choose to align the allocation on any
2371convenient boundary.</p>
2372
Misha Brukman76307852003-11-08 01:05:38 +00002373<p>'<tt>type</tt>' must be a sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002374
Chris Lattner2f7c9632001-06-06 20:29:01 +00002375<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002376
Chris Lattner48b383b02003-11-25 01:02:51 +00002377<p>Memory is allocated using the system "<tt>malloc</tt>" function, and
2378a pointer is returned.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002379
Chris Lattner54611b42005-11-06 08:02:57 +00002380<h5>Example:</h5>
2381
2382<pre>
2383 %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i>
2384
2385 %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002386 %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i>
2387 %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002388 %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i>
2389 %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002390</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002391</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002392
Chris Lattner2f7c9632001-06-06 20:29:01 +00002393<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002394<div class="doc_subsubsection">
2395 <a name="i_free">'<tt>free</tt>' Instruction</a>
2396</div>
2397
Misha Brukman76307852003-11-08 01:05:38 +00002398<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002399
Chris Lattner2f7c9632001-06-06 20:29:01 +00002400<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002401
2402<pre>
2403 free &lt;type&gt; &lt;value&gt; <i>; yields {void}</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002404</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002405
Chris Lattner2f7c9632001-06-06 20:29:01 +00002406<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002407
Chris Lattner48b383b02003-11-25 01:02:51 +00002408<p>The '<tt>free</tt>' instruction returns memory back to the unused
John Criswell4a3327e2005-05-13 22:25:59 +00002409memory heap to be reallocated in the future.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002410
Chris Lattner2f7c9632001-06-06 20:29:01 +00002411<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002412
Chris Lattner48b383b02003-11-25 01:02:51 +00002413<p>'<tt>value</tt>' shall be a pointer value that points to a value
2414that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>'
2415instruction.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002416
Chris Lattner2f7c9632001-06-06 20:29:01 +00002417<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002418
John Criswelldfe6a862004-12-10 15:51:16 +00002419<p>Access to the memory pointed to by the pointer is no longer defined
Chris Lattner48b383b02003-11-25 01:02:51 +00002420after this instruction executes.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002421
Chris Lattner2f7c9632001-06-06 20:29:01 +00002422<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002423
2424<pre>
2425 %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002426 free [4 x ubyte]* %array
2427</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002428</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002429
Chris Lattner2f7c9632001-06-06 20:29:01 +00002430<!-- _______________________________________________________________________ -->
Chris Lattner54611b42005-11-06 08:02:57 +00002431<div class="doc_subsubsection">
2432 <a name="i_alloca">'<tt>alloca</tt>' Instruction</a>
2433</div>
2434
Misha Brukman76307852003-11-08 01:05:38 +00002435<div class="doc_text">
Chris Lattner54611b42005-11-06 08:02:57 +00002436
Chris Lattner2f7c9632001-06-06 20:29:01 +00002437<h5>Syntax:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002438
2439<pre>
2440 &lt;result&gt; = alloca &lt;type&gt;[, uint &lt;NumElements&gt;][, align &lt;alignment&gt;] <i>; yields {type*}:result</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002441</pre>
Chris Lattner54611b42005-11-06 08:02:57 +00002442
Chris Lattner2f7c9632001-06-06 20:29:01 +00002443<h5>Overview:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002444
Chris Lattner48b383b02003-11-25 01:02:51 +00002445<p>The '<tt>alloca</tt>' instruction allocates memory on the current
2446stack frame of the procedure that is live until the current function
2447returns to its caller.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002448
Chris Lattner2f7c9632001-06-06 20:29:01 +00002449<h5>Arguments:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002450
John Criswelldfe6a862004-12-10 15:51:16 +00002451<p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(&lt;type&gt;)*NumElements</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00002452bytes of memory on the runtime stack, returning a pointer of the
Chris Lattner54611b42005-11-06 08:02:57 +00002453appropriate type to the program. If "NumElements" is specified, it is the
2454number of elements allocated. If an alignment is specified, the value result
2455of the allocation is guaranteed to be aligned to at least that boundary. If
2456not specified, or if zero, the target can choose to align the allocation on any
2457convenient boundary.</p>
2458
Misha Brukman76307852003-11-08 01:05:38 +00002459<p>'<tt>type</tt>' may be any sized type.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002460
Chris Lattner2f7c9632001-06-06 20:29:01 +00002461<h5>Semantics:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002462
John Criswell4a3327e2005-05-13 22:25:59 +00002463<p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d
Chris Lattner48b383b02003-11-25 01:02:51 +00002464memory is automatically released when the function returns. The '<tt>alloca</tt>'
2465instruction is commonly used to represent automatic variables that must
2466have an address available. When the function returns (either with the <tt><a
John Criswellc932bef2005-05-12 16:55:34 +00002467 href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt>
Misha Brukman76307852003-11-08 01:05:38 +00002468instructions), the memory is reclaimed.</p>
Chris Lattner54611b42005-11-06 08:02:57 +00002469
Chris Lattner2f7c9632001-06-06 20:29:01 +00002470<h5>Example:</h5>
Chris Lattner54611b42005-11-06 08:02:57 +00002471
2472<pre>
2473 %ptr = alloca int <i>; yields {int*}:ptr</i>
Chris Lattner590645f2002-04-14 06:13:44 +00002474 %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i>
Chris Lattner54611b42005-11-06 08:02:57 +00002475 %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i>
2476 %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i>
Chris Lattner2f7c9632001-06-06 20:29:01 +00002477</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002478</div>
Chris Lattner54611b42005-11-06 08:02:57 +00002479
Chris Lattner2f7c9632001-06-06 20:29:01 +00002480<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002481<div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>'
2482Instruction</a> </div>
Misha Brukman76307852003-11-08 01:05:38 +00002483<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002484<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002485<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 +00002486<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002487<p>The '<tt>load</tt>' instruction is used to read from memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002488<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002489<p>The argument to the '<tt>load</tt>' instruction specifies the memory
John Criswell4c0cf7f2005-10-24 16:17:18 +00002490address from which to load. The pointer must point to a <a
Chris Lattner10ee9652004-06-03 22:57:15 +00002491 href="#t_firstclass">first class</a> type. If the <tt>load</tt> is
John Criswell4c0cf7f2005-10-24 16:17:18 +00002492marked as <tt>volatile</tt>, then the optimizer is not allowed to modify
Chris Lattner48b383b02003-11-25 01:02:51 +00002493the number or order of execution of this <tt>load</tt> with other
2494volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt>
2495instructions. </p>
Chris Lattner095735d2002-05-06 03:03:22 +00002496<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002497<p>The location of memory pointed to is loaded.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002498<h5>Examples:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002499<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2500 <a
2501 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002502 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2503</pre>
Misha Brukman76307852003-11-08 01:05:38 +00002504</div>
Chris Lattner095735d2002-05-06 03:03:22 +00002505<!-- _______________________________________________________________________ -->
Chris Lattner48b383b02003-11-25 01:02:51 +00002506<div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>'
2507Instruction</a> </div>
Reid Spencera89fb182006-11-09 21:18:01 +00002508<div class="doc_text">
Chris Lattner095735d2002-05-06 03:03:22 +00002509<h5>Syntax:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002510<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 +00002511 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 +00002512</pre>
Chris Lattner095735d2002-05-06 03:03:22 +00002513<h5>Overview:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00002514<p>The '<tt>store</tt>' instruction is used to write to memory.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002515<h5>Arguments:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002516<p>There are two arguments to the '<tt>store</tt>' instruction: a value
John Criswell4c0cf7f2005-10-24 16:17:18 +00002517to 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 +00002518operand must be a pointer to the type of the '<tt>&lt;value&gt;</tt>'
John Criswell4a3327e2005-05-13 22:25:59 +00002519operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the
Chris Lattner48b383b02003-11-25 01:02:51 +00002520optimizer is not allowed to modify the number or order of execution of
2521this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a
2522 href="#i_store">store</a></tt> instructions.</p>
2523<h5>Semantics:</h5>
2524<p>The contents of memory are updated to contain '<tt>&lt;value&gt;</tt>'
2525at the location specified by the '<tt>&lt;pointer&gt;</tt>' operand.</p>
Chris Lattner095735d2002-05-06 03:03:22 +00002526<h5>Example:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00002527<pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i>
2528 <a
2529 href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i>
Chris Lattner095735d2002-05-06 03:03:22 +00002530 %val = load int* %ptr <i>; yields {int}:val = int 3</i>
2531</pre>
Reid Spencer443460a2006-11-09 21:15:49 +00002532</div>
2533
Chris Lattner095735d2002-05-06 03:03:22 +00002534<!-- _______________________________________________________________________ -->
Chris Lattner33fd7022004-04-05 01:30:49 +00002535<div class="doc_subsubsection">
2536 <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a>
2537</div>
2538
Misha Brukman76307852003-11-08 01:05:38 +00002539<div class="doc_text">
Chris Lattner590645f2002-04-14 06:13:44 +00002540<h5>Syntax:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002541<pre>
2542 &lt;result&gt; = getelementptr &lt;ty&gt;* &lt;ptrval&gt;{, &lt;ty&gt; &lt;idx&gt;}*
2543</pre>
2544
Chris Lattner590645f2002-04-14 06:13:44 +00002545<h5>Overview:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002546
2547<p>
2548The '<tt>getelementptr</tt>' instruction is used to get the address of a
2549subelement of an aggregate data structure.</p>
2550
Chris Lattner590645f2002-04-14 06:13:44 +00002551<h5>Arguments:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002552
Reid Spencercee005c2006-12-04 21:29:24 +00002553<p>This instruction takes a list of integer operands that indicate what
Chris Lattner33fd7022004-04-05 01:30:49 +00002554elements of the aggregate object to index to. The actual types of the arguments
2555provided depend on the type of the first pointer argument. The
2556'<tt>getelementptr</tt>' instruction is used to index down through the type
John Criswell88190562005-05-16 16:17:45 +00002557levels of a structure or to a specific index in an array. When indexing into a
Reid Spencerc0312692006-12-03 16:53:48 +00002558structure, only <tt>uint</tt> integer constants are allowed. When indexing
Reid Spencercee005c2006-12-04 21:29:24 +00002559into an array or pointer, only integers of 32 or 64 bits are allowed, and will
2560be sign extended to 64-bit values.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002561
Chris Lattner48b383b02003-11-25 01:02:51 +00002562<p>For example, let's consider a C code fragment and how it gets
2563compiled to LLVM:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002564
2565<pre>
2566 struct RT {
2567 char A;
2568 int B[10][20];
2569 char C;
2570 };
2571 struct ST {
2572 int X;
2573 double Y;
2574 struct RT Z;
2575 };
2576
2577 int *foo(struct ST *s) {
2578 return &amp;s[1].Z.B[5][13];
2579 }
2580</pre>
2581
Misha Brukman76307852003-11-08 01:05:38 +00002582<p>The LLVM code generated by the GCC frontend is:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002583
2584<pre>
2585 %RT = type { sbyte, [10 x [20 x int]], sbyte }
2586 %ST = type { int, double, %RT }
2587
Brian Gaeke317ef962004-07-02 21:08:14 +00002588 implementation
2589
2590 int* %foo(%ST* %s) {
2591 entry:
2592 %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13
Chris Lattner33fd7022004-04-05 01:30:49 +00002593 ret int* %reg
2594 }
2595</pre>
2596
Chris Lattner590645f2002-04-14 06:13:44 +00002597<h5>Semantics:</h5>
Chris Lattner33fd7022004-04-05 01:30:49 +00002598
2599<p>The index types specified for the '<tt>getelementptr</tt>' instruction depend
John Criswell4a3327e2005-05-13 22:25:59 +00002600on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a>
Reid Spencercee005c2006-12-04 21:29:24 +00002601and <a href="#t_array">array</a> types can use a 32-bit or 64-bit
Reid Spencerc0312692006-12-03 16:53:48 +00002602<a href="#t_integer">integer</a> type but the value will always be sign extended
2603to 64-bits. <a href="#t_struct">Structure</a> types, require <tt>uint</tt>
2604<b>constants</b>.</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002605
Misha Brukman76307852003-11-08 01:05:38 +00002606<p>In the example above, the first index is indexing into the '<tt>%ST*</tt>'
Chris Lattner33fd7022004-04-05 01:30:49 +00002607type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT
2608}</tt>' type, a structure. The second index indexes into the third element of
2609the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]],
2610sbyte }</tt>' type, another structure. The third index indexes into the second
2611element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an
2612array. The two dimensions of the array are subscripted into, yielding an
John Criswell88190562005-05-16 16:17:45 +00002613'<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer
Chris Lattner33fd7022004-04-05 01:30:49 +00002614to this element, thus computing a value of '<tt>int*</tt>' type.</p>
2615
Chris Lattner48b383b02003-11-25 01:02:51 +00002616<p>Note that it is perfectly legal to index partially through a
2617structure, returning a pointer to an inner element. Because of this,
2618the LLVM code for the given testcase is equivalent to:</p>
Chris Lattner33fd7022004-04-05 01:30:49 +00002619
2620<pre>
Chris Lattner455fc8c2005-03-07 22:13:59 +00002621 int* %foo(%ST* %s) {
Chris Lattner33fd7022004-04-05 01:30:49 +00002622 %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i>
2623 %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i>
2624 %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i>
2625 %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i>
2626 %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i>
2627 ret int* %t5
2628 }
Chris Lattnera8292f32002-05-06 22:08:29 +00002629</pre>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002630
2631<p>Note that it is undefined to access an array out of bounds: array and
2632pointer indexes must always be within the defined bounds of the array type.
2633The one exception for this rules is zero length arrays. These arrays are
2634defined to be accessible as variable length arrays, which requires access
2635beyond the zero'th element.</p>
2636
Chris Lattner6ab66722006-08-15 00:45:58 +00002637<p>The getelementptr instruction is often confusing. For some more insight
2638into how it works, see <a href="GetElementPtr.html">the getelementptr
2639FAQ</a>.</p>
2640
Chris Lattner590645f2002-04-14 06:13:44 +00002641<h5>Example:</h5>
Chris Lattnerc0ad71e2005-06-24 17:22:57 +00002642
Chris Lattner33fd7022004-04-05 01:30:49 +00002643<pre>
2644 <i>; yields [12 x ubyte]*:aptr</i>
2645 %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1
2646</pre>
Chris Lattner33fd7022004-04-05 01:30:49 +00002647</div>
Reid Spencer443460a2006-11-09 21:15:49 +00002648
Chris Lattner2f7c9632001-06-06 20:29:01 +00002649<!-- ======================================================================= -->
Reid Spencer97c5fa42006-11-08 01:18:52 +00002650<div class="doc_subsection"> <a name="convertops">Conversion Operations</a>
Misha Brukman76307852003-11-08 01:05:38 +00002651</div>
Misha Brukman76307852003-11-08 01:05:38 +00002652<div class="doc_text">
Reid Spencer97c5fa42006-11-08 01:18:52 +00002653<p>The instructions in this category are the conversion instructions (casting)
2654which all take a single operand and a type. They perform various bit conversions
2655on the operand.</p>
Misha Brukman76307852003-11-08 01:05:38 +00002656</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002657
Chris Lattnera8292f32002-05-06 22:08:29 +00002658<!-- _______________________________________________________________________ -->
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002659<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002660 <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a>
2661</div>
2662<div class="doc_text">
2663
2664<h5>Syntax:</h5>
2665<pre>
2666 &lt;result&gt; = trunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2667</pre>
2668
2669<h5>Overview:</h5>
2670<p>
2671The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>.
2672</p>
2673
2674<h5>Arguments:</h5>
2675<p>
2676The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must
2677be an <a href="#t_integer">integer</a> type, and a type that specifies the size
2678and type of the result, which must be an <a href="#t_integral">integral</a>
Reid Spencer51b07252006-11-09 23:03:26 +00002679type. The bit size of <tt>value</tt> must be larger than the bit size of
2680<tt>ty2</tt>. Equal sized types are not allowed.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002681
2682<h5>Semantics:</h5>
2683<p>
2684The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt>
Reid Spencer51b07252006-11-09 23:03:26 +00002685and converts the remaining bits to <tt>ty2</tt>. Since the source size must be
2686larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>.
2687It will always truncate bits.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002688
2689<h5>Example:</h5>
2690<pre>
2691 %X = trunc int 257 to ubyte <i>; yields ubyte:1</i>
2692 %Y = trunc int 123 to bool <i>; yields bool:true</i>
2693</pre>
2694</div>
2695
2696<!-- _______________________________________________________________________ -->
2697<div class="doc_subsubsection">
2698 <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a>
2699</div>
2700<div class="doc_text">
2701
2702<h5>Syntax:</h5>
2703<pre>
2704 &lt;result&gt; = zext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2705</pre>
2706
2707<h5>Overview:</h5>
2708<p>The '<tt>zext</tt>' instruction zero extends its operand to type
2709<tt>ty2</tt>.</p>
2710
2711
2712<h5>Arguments:</h5>
2713<p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of
2714<a href="#t_integral">integral</a> type, and a type to cast it to, which must
2715also be of <a href="#t_integral">integral</a> type. The bit size of the
Reid Spencer51b07252006-11-09 23:03:26 +00002716<tt>value</tt> must be smaller than the bit size of the destination type,
2717<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002718
2719<h5>Semantics:</h5>
2720<p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero
2721bits until it reaches the size of the destination type, <tt>ty2</tt>. When the
2722the operand and the type are the same size, no bit filling is done and the
2723cast is considered a <i>no-op cast</i> because no bits change (only the type
2724changes).</p>
2725
Reid Spencer51b07252006-11-09 23:03:26 +00002726<p>When zero extending from bool, the result will alwasy be either 0 or 1.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002727
2728<h5>Example:</h5>
2729<pre>
2730 %X = zext int 257 to ulong <i>; yields ulong:257</i>
2731 %Y = zext bool true to int <i>; yields int:1</i>
2732</pre>
2733</div>
2734
2735<!-- _______________________________________________________________________ -->
2736<div class="doc_subsubsection">
2737 <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a>
2738</div>
2739<div class="doc_text">
2740
2741<h5>Syntax:</h5>
2742<pre>
2743 &lt;result&gt; = sext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2744</pre>
2745
2746<h5>Overview:</h5>
2747<p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p>
2748
2749<h5>Arguments:</h5>
2750<p>
2751The '<tt>sext</tt>' instruction takes a value to cast, which must be of
2752<a href="#t_integral">integral</a> type, and a type to cast it to, which must
Reid Spencer51b07252006-11-09 23:03:26 +00002753also be of <a href="#t_integral">integral</a> type. The bit size of the
2754<tt>value</tt> must be smaller than the bit size of the destination type,
2755<tt>ty2</tt>.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002756
2757<h5>Semantics:</h5>
2758<p>
2759The '<tt>sext</tt>' instruction performs a sign extension by copying the sign
2760bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of
2761the type <tt>ty2</tt>. When the the operand and the type are the same size,
2762no bit filling is done and the cast is considered a <i>no-op cast</i> because
2763no bits change (only the type changes).</p>
2764
Reid Spencer51b07252006-11-09 23:03:26 +00002765<p>When sign extending from bool, the extension always results in -1 or 0.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002766
2767<h5>Example:</h5>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002768<pre>
2769 %X = sext sbyte -1 to ushort <i>; yields ushort:65535</i>
2770 %Y = sext bool true to int <i>; yields int:-1</i>
2771</pre>
2772</div>
2773
2774<!-- _______________________________________________________________________ -->
2775<div class="doc_subsubsection">
Reid Spencer2e2740d2006-11-09 21:48:10 +00002776 <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a>
2777</div>
2778
2779<div class="doc_text">
2780
2781<h5>Syntax:</h5>
2782
2783<pre>
2784 &lt;result&gt; = fptrunc &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2785</pre>
2786
2787<h5>Overview:</h5>
2788<p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type
2789<tt>ty2</tt>.</p>
2790
2791
2792<h5>Arguments:</h5>
2793<p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating
2794 point</a> value to cast and a <a href="#t_floating">floating point</a> type to
2795cast it to. The size of <tt>value</tt> must be larger than the size of
2796<tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a
2797<i>no-op cast</i>.</p>
2798
2799<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002800<p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger
2801<a href="#t_floating">floating point</a> type to a smaller
2802<a href="#t_floating">floating point</a> type. If the value cannot fit within
2803the destination type, <tt>ty2</tt>, then the results are undefined.</p>
Reid Spencer2e2740d2006-11-09 21:48:10 +00002804
2805<h5>Example:</h5>
2806<pre>
2807 %X = fptrunc double 123.0 to float <i>; yields float:123.0</i>
2808 %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i>
2809</pre>
2810</div>
2811
2812<!-- _______________________________________________________________________ -->
2813<div class="doc_subsubsection">
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002814 <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a>
2815</div>
2816<div class="doc_text">
2817
2818<h5>Syntax:</h5>
2819<pre>
2820 &lt;result&gt; = fpext &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2821</pre>
2822
2823<h5>Overview:</h5>
2824<p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger
2825floating point value.</p>
2826
2827<h5>Arguments:</h5>
2828<p>The '<tt>fpext</tt>' instruction takes a
2829<a href="#t_floating">floating point</a> <tt>value</tt> to cast,
Reid Spencer51b07252006-11-09 23:03:26 +00002830and a <a href="#t_floating">floating point</a> type to cast it to. The source
2831type must be smaller than the destination type.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002832
2833<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002834<p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller
2835<a href="t_floating">floating point</a> type to a larger
2836<a href="t_floating">floating point</a> type. The <tt>fpext</tt> cannot be
2837used to make a <i>no-op cast</i> because it always changes bits. Use
Reid Spencer5b950642006-11-11 23:08:07 +00002838<tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002839
2840<h5>Example:</h5>
2841<pre>
2842 %X = fpext float 3.1415 to double <i>; yields double:3.1415</i>
2843 %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i>
2844</pre>
2845</div>
2846
2847<!-- _______________________________________________________________________ -->
2848<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002849 <a name="i_fp2uint">'<tt>fptoui .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002850</div>
2851<div class="doc_text">
2852
2853<h5>Syntax:</h5>
2854<pre>
2855 &lt;result&gt; = fp2uint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
2856</pre>
2857
2858<h5>Overview:</h5>
2859<p>The '<tt>fp2uint</tt>' converts a floating point <tt>value</tt> to its
2860unsigned integer equivalent of type <tt>ty2</tt>.
2861</p>
2862
2863<h5>Arguments:</h5>
2864<p>The '<tt>fp2uint</tt>' instruction takes a value to cast, which must be a
2865<a href="#t_floating">floating point</a> value, and a type to cast it to, which
2866must be an <a href="#t_integral">integral</a> type.</p>
2867
2868<h5>Semantics:</h5>
2869<p> The '<tt>fp2uint</tt>' instruction converts its
2870<a href="#t_floating">floating point</a> operand into the nearest (rounding
2871towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>,
2872the results are undefined.</p>
2873
2874<p>When converting to bool, the conversion is done as a comparison against
2875zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>.
2876If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p>
2877
2878<h5>Example:</h5>
2879<pre>
2880 %X = fp2uint double 123.0 to int <i>; yields int:123</i>
2881 %Y = fp2uint float 1.0E+300 to bool <i>; yields bool:true</i>
2882 %X = fp2uint float 1.04E+17 to ubyte <i>; yields undefined:1</i>
2883</pre>
2884</div>
2885
2886<!-- _______________________________________________________________________ -->
2887<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002888 <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002889</div>
2890<div class="doc_text">
2891
2892<h5>Syntax:</h5>
2893<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002894 &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 +00002895</pre>
2896
2897<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002898<p>The '<tt>fptosi</tt>' instruction converts
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002899<a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002900</p>
2901
2902
Chris Lattnera8292f32002-05-06 22:08:29 +00002903<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002904<p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002905<a href="#t_floating">floating point</a> value, and a type to cast it to, which
2906must also be an <a href="#t_integral">integral</a> type.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002907
Chris Lattnera8292f32002-05-06 22:08:29 +00002908<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002909<p>The '<tt>fptosi</tt>' instruction converts its
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002910<a href="#t_floating">floating point</a> operand into the nearest (rounding
2911towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>,
2912the results are undefined.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002913
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002914<p>When converting to bool, the conversion is done as a comparison against
2915zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>.
2916If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002917
Chris Lattner70de6632001-07-09 00:26:23 +00002918<h5>Example:</h5>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00002919<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002920 %X = fptosi double -123.0 to int <i>; yields int:-123</i>
2921 %Y = fptosi float 1.0E-247 to bool <i>; yields bool:true</i>
2922 %X = fptosi float 1.04E+17 to sbyte <i>; yields undefined:1</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002923</pre>
2924</div>
2925
2926<!-- _______________________________________________________________________ -->
2927<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002928 <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002929</div>
2930<div class="doc_text">
2931
2932<h5>Syntax:</h5>
2933<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002934 &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 +00002935</pre>
2936
2937<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002938<p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002939integer and converts that value to the <tt>ty2</tt> type.</p>
2940
2941
2942<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002943<p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be an
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002944<a href="#t_integral">integral</a> value, and a type to cast it to, which must
2945be a <a href="#t_floating">floating point</a> type.</p>
2946
2947<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002948<p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002949integer quantity and converts it to the corresponding floating point value. If
2950the value cannot fit in the floating point value, the results are undefined.</p>
2951
2952
2953<h5>Example:</h5>
2954<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002955 %X = uitofp int 257 to float <i>; yields float:257.0</i>
2956 %Y = uitofp sbyte -1 to double <i>; yields double:255.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002957</pre>
2958</div>
2959
2960<!-- _______________________________________________________________________ -->
2961<div class="doc_subsubsection">
Reid Spencer51b07252006-11-09 23:03:26 +00002962 <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002963</div>
2964<div class="doc_text">
2965
2966<h5>Syntax:</h5>
2967<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002968 &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 +00002969</pre>
2970
2971<h5>Overview:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002972<p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002973integer and converts that value to the <tt>ty2</tt> type.</p>
2974
2975<h5>Arguments:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002976<p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be an
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002977<a href="#t_integral">integral</a> value, and a type to cast it to, which must be
2978a <a href="#t_floating">floating point</a> type.</p>
2979
2980<h5>Semantics:</h5>
Reid Spencer51b07252006-11-09 23:03:26 +00002981<p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002982integer quantity and converts it to the corresponding floating point value. If
2983the value cannot fit in the floating point value, the results are undefined.</p>
2984
2985<h5>Example:</h5>
2986<pre>
Reid Spencer51b07252006-11-09 23:03:26 +00002987 %X = sitofp int 257 to float <i>; yields float:257.0</i>
2988 %Y = sitofp sbyte -1 to double <i>; yields double:-1.0</i>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00002989</pre>
2990</div>
2991
2992<!-- _______________________________________________________________________ -->
2993<div class="doc_subsubsection">
Reid Spencerb7344ff2006-11-11 21:00:47 +00002994 <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a>
2995</div>
2996<div class="doc_text">
2997
2998<h5>Syntax:</h5>
2999<pre>
3000 &lt;result&gt; = ptrtoint &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3001</pre>
3002
3003<h5>Overview:</h5>
3004<p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to
3005the integer type <tt>ty2</tt>.</p>
3006
3007<h5>Arguments:</h5>
3008<p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which
3009must be a <a href="t_pointer">pointer</a> value, and a type to cast it to
3010<tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.
3011
3012<h5>Semantics:</h5>
3013<p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type
3014<tt>ty2</tt> by interpreting the pointer value as an integer and either
3015truncating or zero extending that value to the size of the integer type. If
3016<tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If
3017<tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they
3018are the same size, then nothing is done (<i>no-op cast</i>).</p>
3019
3020<h5>Example:</h5>
3021<pre>
3022 %X = ptrtoint int* %X to sbyte <i>; yields truncation on 32-bit</i>
3023 %Y = ptrtoint int* %x to ulong <i>; yields zero extend on 32-bit</i>
3024</pre>
3025</div>
3026
3027<!-- _______________________________________________________________________ -->
3028<div class="doc_subsubsection">
3029 <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a>
3030</div>
3031<div class="doc_text">
3032
3033<h5>Syntax:</h5>
3034<pre>
3035 &lt;result&gt; = inttoptr &lt;ty&gt; &lt;value&gt; to &lt;ty2&gt; <i>; yields ty2</i>
3036</pre>
3037
3038<h5>Overview:</h5>
3039<p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to
3040a pointer type, <tt>ty2</tt>.</p>
3041
3042<h5>Arguments:</h5>
3043<p>The '<tt>inttoptr</tt>' instruction takes an <a href="i_integer">integer</a>
3044value to cast, and a type to cast it to, which must be a
3045<a href="#t_pointer">pointer</a> type. </tt>
3046
3047<h5>Semantics:</h5>
3048<p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type
3049<tt>ty2</tt> by applying either a zero extension or a truncation depending on
3050the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the
3051size of a pointer then a truncation is done. If <tt>value</tt> is smaller than
3052the size of a pointer then a zero extension is done. If they are the same size,
3053nothing is done (<i>no-op cast</i>).</p>
3054
3055<h5>Example:</h5>
3056<pre>
3057 %X = inttoptr int 255 to int* <i>; yields zero extend on 64-bit</i>
3058 %X = inttoptr int 255 to int* <i>; yields no-op on 32-bit </i>
3059 %Y = inttoptr short 0 to int* <i>; yields zero extend on 32-bit</i>
3060</pre>
3061</div>
3062
3063<!-- _______________________________________________________________________ -->
3064<div class="doc_subsubsection">
Reid Spencer5b950642006-11-11 23:08:07 +00003065 <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003066</div>
3067<div class="doc_text">
3068
3069<h5>Syntax:</h5>
3070<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00003071 &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 +00003072</pre>
3073
3074<h5>Overview:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003075<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003076<tt>ty2</tt> without changing any bits.</p>
3077
3078<h5>Arguments:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003079<p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003080a first class value, and a type to cast it to, which must also be a <a
3081 href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt>
3082and the destination type, <tt>ty2</tt>, must be identical.</p>
3083
3084<h5>Semantics:</h5>
Reid Spencer5b950642006-11-11 23:08:07 +00003085<p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type
Reid Spencerb7344ff2006-11-11 21:00:47 +00003086<tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with
3087this conversion. The conversion is done as if the <tt>value</tt> had been
3088stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be
3089converted to other pointer types with this instruction. To convert pointers to
3090other types, use the <a href="#i_inttoptr">inttoptr</a> or
3091<a href="#i_ptrtoint">ptrtoint</a> instructions first.</p>
Reid Spencer59b6b7d2006-11-08 01:11:31 +00003092
3093<h5>Example:</h5>
3094<pre>
Reid Spencer5b950642006-11-11 23:08:07 +00003095 %X = bitcast ubyte 255 to sbyte <i>; yields sbyte:-1</i>
3096 %Y = bitcast uint* %x to sint* <i>; yields sint*:%x</i>
3097 %Z = bitcast <2xint> %V to long; <i>; yields long: %V</i>
Chris Lattner70de6632001-07-09 00:26:23 +00003098</pre>
Misha Brukman76307852003-11-08 01:05:38 +00003099</div>
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003100
Reid Spencer97c5fa42006-11-08 01:18:52 +00003101<!-- ======================================================================= -->
3102<div class="doc_subsection"> <a name="otherops">Other Operations</a> </div>
3103<div class="doc_text">
3104<p>The instructions in this category are the "miscellaneous"
3105instructions, which defy better classification.</p>
3106</div>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003107
3108<!-- _______________________________________________________________________ -->
3109<div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a>
3110</div>
3111<div class="doc_text">
3112<h5>Syntax:</h5>
3113<pre> &lt;result&gt; = icmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
3114</pre>
3115<h5>Overview:</h5>
3116<p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison
3117of its two integer operands.</p>
3118<h5>Arguments:</h5>
3119<p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is
3120the condition code which indicates the kind of comparison to perform. It is not
3121a value, just a keyword. The possibilities for the condition code are:
3122<ol>
3123 <li><tt>eq</tt>: equal</li>
3124 <li><tt>ne</tt>: not equal </li>
3125 <li><tt>ugt</tt>: unsigned greater than</li>
3126 <li><tt>uge</tt>: unsigned greater or equal</li>
3127 <li><tt>ult</tt>: unsigned less than</li>
3128 <li><tt>ule</tt>: unsigned less or equal</li>
3129 <li><tt>sgt</tt>: signed greater than</li>
3130 <li><tt>sge</tt>: signed greater or equal</li>
3131 <li><tt>slt</tt>: signed less than</li>
3132 <li><tt>sle</tt>: signed less or equal</li>
3133</ol>
3134<p>The remaining two arguments must be of <a href="#t_integral">integral</a>,
3135<a href="#t_pointer">pointer</a> or a <a href="#t_packed">packed</a> integral
3136type. They must have identical types.</p>
3137<h5>Semantics:</h5>
3138<p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3139the condition code given as <tt>cond</tt>. The comparison performed always
3140yields a <a href="#t_bool">bool</a> result, as follows:
3141<ol>
3142 <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,
3143 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3144 </li>
3145 <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,
3146 <tt>false</tt> otherwise. No sign interpretation is necessary or performed.
3147 <li><tt>ugt</tt>: interprets the operands as unsigned values and yields
3148 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3149 <li><tt>uge</tt>: interprets the operands as unsigned values and yields
3150 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3151 <li><tt>ult</tt>: interprets the operands as unsigned values and yields
3152 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3153 <li><tt>ule</tt>: interprets the operands as unsigned values and yields
3154 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3155 <li><tt>sgt</tt>: interprets the operands as signed values and yields
3156 <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li>
3157 <li><tt>sge</tt>: interprets the operands as signed values and yields
3158 <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
3159 <li><tt>slt</tt>: interprets the operands as signed values and yields
3160 <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li>
3161 <li><tt>sle</tt>: interprets the operands as signed values and yields
3162 <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
3163 </li>
3164</ol>
3165<p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer
3166values are treated as integers and then compared.</p>
3167<p>If the operands are <a href="#t_packed">packed</a> typed, the elements of
Reid Spencerf69acf32006-11-19 03:00:14 +00003168the vector are compared in turn and the predicate must hold for all
3169elements.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003170
3171<h5>Example:</h5>
3172<pre> &lt;result&gt; = icmp eq int 4, 5 <i>; yields: result=false</i>
3173 &lt;result&gt; = icmp ne float* %X, %X <i>; yields: result=false</i>
3174 &lt;result&gt; = icmp ult short 4, 5 <i>; yields: result=true</i>
3175 &lt;result&gt; = icmp sgt sbyte 4, 5 <i>; yields: result=false</i>
3176 &lt;result&gt; = icmp ule sbyte -4, 5 <i>; yields: result=false</i>
3177 &lt;result&gt; = icmp sge sbyte 4, 5 <i>; yields: result=false</i>
3178</pre>
3179</div>
3180
3181<!-- _______________________________________________________________________ -->
3182<div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a>
3183</div>
3184<div class="doc_text">
3185<h5>Syntax:</h5>
3186<pre> &lt;result&gt; = fcmp &lt;cond&gt; &lt;ty&gt; &lt;var1&gt;, &lt;var2&gt; <i>; yields {bool}:result</i>
3187</pre>
3188<h5>Overview:</h5>
3189<p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison
3190of its floating point operands.</p>
3191<h5>Arguments:</h5>
3192<p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is
3193the condition code which indicates the kind of comparison to perform. It is not
3194a value, just a keyword. The possibilities for the condition code are:
3195<ol>
Reid Spencerf69acf32006-11-19 03:00:14 +00003196 <li><tt>false</tt>: no comparison, always returns false</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003197 <li><tt>oeq</tt>: ordered and equal</li>
3198 <li><tt>ogt</tt>: ordered and greater than </li>
3199 <li><tt>oge</tt>: ordered and greater than or equal</li>
3200 <li><tt>olt</tt>: ordered and less than </li>
3201 <li><tt>ole</tt>: ordered and less than or equal</li>
3202 <li><tt>one</tt>: ordered and not equal</li>
3203 <li><tt>ord</tt>: ordered (no nans)</li>
3204 <li><tt>ueq</tt>: unordered or equal</li>
3205 <li><tt>ugt</tt>: unordered or greater than </li>
3206 <li><tt>uge</tt>: unordered or greater than or equal</li>
3207 <li><tt>ult</tt>: unordered or less than </li>
3208 <li><tt>ule</tt>: unordered or less than or equal</li>
3209 <li><tt>une</tt>: unordered or not equal</li>
3210 <li><tt>uno</tt>: unordered (either nans)</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003211 <li><tt>true</tt>: no comparison, always returns true</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003212</ol>
Reid Spencer02e0d1d2006-12-06 07:08:07 +00003213<p>In the preceding, <i>ordered</i> means that neither operand is a QNAN while
3214<i>unordered</i> means that either operand may be a QNAN.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003215<p>The <tt>val1</tt> and <tt>val2</tt> arguments must be of
3216<a href="#t_floating">floating point</a>, or a <a href="#t_packed">packed</a>
3217floating point type. They must have identical types.</p>
Reid Spencerf69acf32006-11-19 03:00:14 +00003218<p>In the foregoing, <i>ordered</i> means that neither operand is a QNAN and
3219<i>unordered</i> means that either operand is a QNAN.</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003220<h5>Semantics:</h5>
3221<p>The '<tt>fcmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to
3222the condition code given as <tt>cond</tt>. The comparison performed always
3223yields a <a href="#t_bool">bool</a> result, as follows:
3224<ol>
3225 <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003226 <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003227 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003228 <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003229 <tt>var1</tt> is greather than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003230 <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003231 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003232 <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003233 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003234 <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003235 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003236 <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and
Reid Spencerc828a0e2006-11-18 21:50:54 +00003237 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003238 <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li>
3239 <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003240 <tt>var1</tt> is equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003241 <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003242 <tt>var1</tt> is greater than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003243 <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003244 <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003245 <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003246 <tt>var1</tt> is less than <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003247 <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003248 <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003249 <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or
Reid Spencerc828a0e2006-11-18 21:50:54 +00003250 <tt>var1</tt> is not equal to <tt>var2</tt>.</li>
Reid Spencerf69acf32006-11-19 03:00:14 +00003251 <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003252 <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li>
3253</ol>
3254<p>If the operands are <a href="#t_packed">packed</a> typed, the elements of
3255the vector are compared in turn and the predicate must hold for all elements.
Reid Spencerf69acf32006-11-19 03:00:14 +00003256</p>
Reid Spencerc828a0e2006-11-18 21:50:54 +00003257
3258<h5>Example:</h5>
3259<pre> &lt;result&gt; = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i>
3260 &lt;result&gt; = icmp one float 4.0, 5.0 <i>; yields: result=true</i>
3261 &lt;result&gt; = icmp olt float 4.0, 5.0 <i>; yields: result=true</i>
3262 &lt;result&gt; = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i>
3263</pre>
3264</div>
3265
Reid Spencer97c5fa42006-11-08 01:18:52 +00003266<!-- _______________________________________________________________________ -->
3267<div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>'
3268Instruction</a> </div>
3269<div class="doc_text">
3270<h5>Syntax:</h5>
3271<pre> &lt;result&gt; = phi &lt;ty&gt; [ &lt;val0&gt;, &lt;label0&gt;], ...<br></pre>
3272<h5>Overview:</h5>
3273<p>The '<tt>phi</tt>' instruction is used to implement the &#966; node in
3274the SSA graph representing the function.</p>
3275<h5>Arguments:</h5>
3276<p>The type of the incoming values are specified with the first type
3277field. After this, the '<tt>phi</tt>' instruction takes a list of pairs
3278as arguments, with one pair for each predecessor basic block of the
3279current block. Only values of <a href="#t_firstclass">first class</a>
3280type may be used as the value arguments to the PHI node. Only labels
3281may be used as the label arguments.</p>
3282<p>There must be no non-phi instructions between the start of a basic
3283block and the PHI instructions: i.e. PHI instructions must be first in
3284a basic block.</p>
3285<h5>Semantics:</h5>
3286<p>At runtime, the '<tt>phi</tt>' instruction logically takes on the
3287value specified by the parameter, depending on which basic block we
3288came from in the last <a href="#terminators">terminator</a> instruction.</p>
3289<h5>Example:</h5>
3290<pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre>
3291</div>
3292
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003293<!-- _______________________________________________________________________ -->
3294<div class="doc_subsubsection">
3295 <a name="i_select">'<tt>select</tt>' Instruction</a>
3296</div>
3297
3298<div class="doc_text">
3299
3300<h5>Syntax:</h5>
3301
3302<pre>
3303 &lt;result&gt; = select bool &lt;cond&gt;, &lt;ty&gt; &lt;val1&gt;, &lt;ty&gt; &lt;val2&gt; <i>; yields ty</i>
3304</pre>
3305
3306<h5>Overview:</h5>
3307
3308<p>
3309The '<tt>select</tt>' instruction is used to choose one value based on a
3310condition, without branching.
3311</p>
3312
3313
3314<h5>Arguments:</h5>
3315
3316<p>
3317The '<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.
3318</p>
3319
3320<h5>Semantics:</h5>
3321
3322<p>
3323If the boolean condition evaluates to true, the instruction returns the first
John Criswell88190562005-05-16 16:17:45 +00003324value argument; otherwise, it returns the second value argument.
Chris Lattnerb53c28d2004-03-12 05:50:16 +00003325</p>
3326
3327<h5>Example:</h5>
3328
3329<pre>
3330 %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i>
3331</pre>
3332</div>
3333
Robert Bocchinof72fdfe2006-01-15 20:48:27 +00003334
3335<!-- _______________________________________________________________________ -->
3336<div class="doc_subsubsection">
Chris Lattnere23c1392005-05-06 05:47:36 +00003337 <a name="i_call">'<tt>call</tt>' Instruction</a>
3338</div>
3339
Misha Brukman76307852003-11-08 01:05:38 +00003340<div class="doc_text">
Chris Lattnere23c1392005-05-06 05:47:36 +00003341
Chris Lattner2f7c9632001-06-06 20:29:01 +00003342<h5>Syntax:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003343<pre>
Chris Lattner0132aff2005-05-06 22:57:40 +00003344 &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 +00003345</pre>
3346
Chris Lattner2f7c9632001-06-06 20:29:01 +00003347<h5>Overview:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003348
Misha Brukman76307852003-11-08 01:05:38 +00003349<p>The '<tt>call</tt>' instruction represents a simple function call.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003350
Chris Lattner2f7c9632001-06-06 20:29:01 +00003351<h5>Arguments:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003352
Misha Brukman76307852003-11-08 01:05:38 +00003353<p>This instruction requires several arguments:</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003354
Chris Lattnera8292f32002-05-06 22:08:29 +00003355<ol>
Chris Lattner48b383b02003-11-25 01:02:51 +00003356 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003357 <p>The optional "tail" marker indicates whether the callee function accesses
3358 any allocas or varargs in the caller. If the "tail" marker is present, the
Chris Lattnere23c1392005-05-06 05:47:36 +00003359 function call is eligible for tail call optimization. Note that calls may
3360 be marked "tail" even if they do not occur before a <a
3361 href="#i_ret"><tt>ret</tt></a> instruction.
Chris Lattner48b383b02003-11-25 01:02:51 +00003362 </li>
3363 <li>
Chris Lattner0132aff2005-05-06 22:57:40 +00003364 <p>The optional "cconv" marker indicates which <a href="callingconv">calling
3365 convention</a> the call should use. If none is specified, the call defaults
3366 to using C calling conventions.
3367 </li>
3368 <li>
Chris Lattnere23c1392005-05-06 05:47:36 +00003369 <p>'<tt>ty</tt>': shall be the signature of the pointer to function value
3370 being invoked. The argument types must match the types implied by this
John Criswell88190562005-05-16 16:17:45 +00003371 signature. This type can be omitted if the function is not varargs and
3372 if the function type does not return a pointer to a function.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003373 </li>
3374 <li>
3375 <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to
3376 be invoked. In most cases, this is a direct function invocation, but
3377 indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer
John Criswell88190562005-05-16 16:17:45 +00003378 to function value.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003379 </li>
3380 <li>
3381 <p>'<tt>function args</tt>': argument list whose types match the
Reid Spencerd845d162005-05-01 22:22:57 +00003382 function signature argument types. All arguments must be of
3383 <a href="#t_firstclass">first class</a> type. If the function signature
3384 indicates the function accepts a variable number of arguments, the extra
3385 arguments can be specified.</p>
Chris Lattner48b383b02003-11-25 01:02:51 +00003386 </li>
Chris Lattnera8292f32002-05-06 22:08:29 +00003387</ol>
Chris Lattnere23c1392005-05-06 05:47:36 +00003388
Chris Lattner2f7c9632001-06-06 20:29:01 +00003389<h5>Semantics:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003390
Chris Lattner48b383b02003-11-25 01:02:51 +00003391<p>The '<tt>call</tt>' instruction is used to cause control flow to
3392transfer to a specified function, with its incoming arguments bound to
3393the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>'
3394instruction in the called function, control flow continues with the
3395instruction after the function call, and the return value of the
3396function is bound to the result argument. This is a simpler case of
3397the <a href="#i_invoke">invoke</a> instruction.</p>
Chris Lattnere23c1392005-05-06 05:47:36 +00003398
Chris Lattner2f7c9632001-06-06 20:29:01 +00003399<h5>Example:</h5>
Chris Lattnere23c1392005-05-06 05:47:36 +00003400
3401<pre>
3402 %retval = call int %test(int %argc)
3403 call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);
3404 %X = tail call int %foo()
Chris Lattner0132aff2005-05-06 22:57:40 +00003405 %Y = tail call <a href="#callingconv">fastcc</a> int %foo()
Chris Lattnere23c1392005-05-06 05:47:36 +00003406</pre>
3407
Misha Brukman76307852003-11-08 01:05:38 +00003408</div>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003409
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003410<!-- _______________________________________________________________________ -->
Chris Lattner6a4a0492004-09-27 21:51:25 +00003411<div class="doc_subsubsection">
Chris Lattner33337472006-01-13 23:26:01 +00003412 <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003413</div>
3414
Misha Brukman76307852003-11-08 01:05:38 +00003415<div class="doc_text">
Chris Lattner6a4a0492004-09-27 21:51:25 +00003416
Chris Lattner26ca62e2003-10-18 05:51:36 +00003417<h5>Syntax:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003418
3419<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003420 &lt;resultval&gt; = va_arg &lt;va_list*&gt; &lt;arglist&gt;, &lt;argty&gt;
Chris Lattner6a4a0492004-09-27 21:51:25 +00003421</pre>
3422
Chris Lattner26ca62e2003-10-18 05:51:36 +00003423<h5>Overview:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003424
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003425<p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through
Chris Lattner6a4a0492004-09-27 21:51:25 +00003426the "variable argument" area of a function call. It is used to implement the
3427<tt>va_arg</tt> macro in C.</p>
3428
Chris Lattner26ca62e2003-10-18 05:51:36 +00003429<h5>Arguments:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003430
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003431<p>This instruction takes a <tt>va_list*</tt> value and the type of
3432the argument. It returns a value of the specified argument type and
Jeff Cohendc6bfea2005-11-11 02:15:27 +00003433increments the <tt>va_list</tt> to point to the next argument. Again, the
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003434actual type of <tt>va_list</tt> is target specific.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003435
Chris Lattner26ca62e2003-10-18 05:51:36 +00003436<h5>Semantics:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003437
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003438<p>The '<tt>va_arg</tt>' instruction loads an argument of the specified
3439type from the specified <tt>va_list</tt> and causes the
3440<tt>va_list</tt> to point to the next argument. For more information,
3441see the variable argument handling <a href="#int_varargs">Intrinsic
3442Functions</a>.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003443
3444<p>It is legal for this instruction to be called in a function which does not
3445take a variable number of arguments, for example, the <tt>vfprintf</tt>
Misha Brukman76307852003-11-08 01:05:38 +00003446function.</p>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003447
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003448<p><tt>va_arg</tt> is an LLVM instruction instead of an <a
John Criswell88190562005-05-16 16:17:45 +00003449href="#intrinsics">intrinsic function</a> because it takes a type as an
Chris Lattner6a4a0492004-09-27 21:51:25 +00003450argument.</p>
3451
Chris Lattner26ca62e2003-10-18 05:51:36 +00003452<h5>Example:</h5>
Chris Lattner6a4a0492004-09-27 21:51:25 +00003453
3454<p>See the <a href="#int_varargs">variable argument processing</a> section.</p>
3455
Misha Brukman76307852003-11-08 01:05:38 +00003456</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003457
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003458<!-- *********************************************************************** -->
Chris Lattner48b383b02003-11-25 01:02:51 +00003459<div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div>
3460<!-- *********************************************************************** -->
Chris Lattner941515c2004-01-06 05:31:32 +00003461
Misha Brukman76307852003-11-08 01:05:38 +00003462<div class="doc_text">
Chris Lattnerfee11462004-02-12 17:01:32 +00003463
3464<p>LLVM supports the notion of an "intrinsic function". These functions have
John Criswell88190562005-05-16 16:17:45 +00003465well known names and semantics and are required to follow certain
Chris Lattnerfee11462004-02-12 17:01:32 +00003466restrictions. Overall, these instructions represent an extension mechanism for
3467the LLVM language that does not require changing all of the transformations in
3468LLVM to add to the language (or the bytecode reader/writer, the parser,
3469etc...).</p>
3470
John Criswell88190562005-05-16 16:17:45 +00003471<p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This
3472prefix is reserved in LLVM for intrinsic names; thus, functions may not be named
Chris Lattnerfee11462004-02-12 17:01:32 +00003473this. Intrinsic functions must always be external functions: you cannot define
3474the body of intrinsic functions. Intrinsic functions may only be used in call
3475or invoke instructions: it is illegal to take the address of an intrinsic
3476function. Additionally, because intrinsic functions are part of the LLVM
3477language, it is required that they all be documented here if any are added.</p>
3478
3479
John Criswell88190562005-05-16 16:17:45 +00003480<p>To learn how to add an intrinsic function, please see the <a
Chris Lattner90391c12005-05-11 03:35:57 +00003481href="ExtendingLLVM.html">Extending LLVM Guide</a>.
Chris Lattnerfee11462004-02-12 17:01:32 +00003482</p>
3483
Misha Brukman76307852003-11-08 01:05:38 +00003484</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003485
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003486<!-- ======================================================================= -->
Chris Lattner941515c2004-01-06 05:31:32 +00003487<div class="doc_subsection">
3488 <a name="int_varargs">Variable Argument Handling Intrinsics</a>
3489</div>
3490
Misha Brukman76307852003-11-08 01:05:38 +00003491<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003492
Misha Brukman76307852003-11-08 01:05:38 +00003493<p>Variable argument support is defined in LLVM with the <a
Chris Lattner33337472006-01-13 23:26:01 +00003494 href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three
Chris Lattner48b383b02003-11-25 01:02:51 +00003495intrinsic functions. These functions are related to the similarly
3496named macros defined in the <tt>&lt;stdarg.h&gt;</tt> header file.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003497
Chris Lattner48b383b02003-11-25 01:02:51 +00003498<p>All of these functions operate on arguments that use a
3499target-specific value type "<tt>va_list</tt>". The LLVM assembly
3500language reference manual does not define what this type is, so all
3501transformations should be prepared to handle intrinsics with any type
3502used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003503
Chris Lattner30b868d2006-05-15 17:26:46 +00003504<p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a>
Chris Lattner48b383b02003-11-25 01:02:51 +00003505instruction and the variable argument handling intrinsic functions are
3506used.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003507
Chris Lattnerfee11462004-02-12 17:01:32 +00003508<pre>
3509int %test(int %X, ...) {
3510 ; Initialize variable argument processing
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003511 %ap = alloca sbyte*
3512 call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00003513
3514 ; Read a single integer argument
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003515 %tmp = va_arg sbyte** %ap, int
Chris Lattnerfee11462004-02-12 17:01:32 +00003516
3517 ; Demonstrate usage of llvm.va_copy and llvm.va_end
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003518 %aq = alloca sbyte*
Andrew Lenharth5305ea52005-06-22 20:38:11 +00003519 call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap)
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003520 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq)
Chris Lattnerfee11462004-02-12 17:01:32 +00003521
3522 ; Stop processing of arguments.
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003523 call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap)
Chris Lattnerfee11462004-02-12 17:01:32 +00003524 ret int %tmp
3525}
3526</pre>
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_subsubsection">
3531 <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a>
3532</div>
3533
3534
Misha Brukman76307852003-11-08 01:05:38 +00003535<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003536<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003537<pre> declare void %llvm.va_start(&lt;va_list&gt;* &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003538<h5>Overview:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003539<P>The '<tt>llvm.va_start</tt>' intrinsic initializes
3540<tt>*&lt;arglist&gt;</tt> for subsequent use by <tt><a
3541href="#i_va_arg">va_arg</a></tt>.</p>
3542
3543<h5>Arguments:</h5>
3544
3545<P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p>
3546
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003547<h5>Semantics:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003548
3549<P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt>
3550macro available in C. In a target-dependent way, it initializes the
3551<tt>va_list</tt> element the argument points to, so that the next call to
3552<tt>va_arg</tt> will produce the first variable argument passed to the function.
3553Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the
3554last argument of the function, the compiler can figure that out.</p>
3555
Misha Brukman76307852003-11-08 01:05:38 +00003556</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003557
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003558<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003559<div class="doc_subsubsection">
3560 <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a>
3561</div>
3562
Misha Brukman76307852003-11-08 01:05:38 +00003563<div class="doc_text">
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003564<h5>Syntax:</h5>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003565<pre> declare void %llvm.va_end(&lt;va_list*&gt; &lt;arglist&gt;)<br></pre>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003566<h5>Overview:</h5>
Chris Lattner48b383b02003-11-25 01:02:51 +00003567<p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>&lt;arglist&gt;</tt>
3568which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt>
3569or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003570<h5>Arguments:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003571<p>The argument is a <tt>va_list</tt> to destroy.</p>
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003572<h5>Semantics:</h5>
Misha Brukman76307852003-11-08 01:05:38 +00003573<p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt>
Chris Lattner48b383b02003-11-25 01:02:51 +00003574macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>.
3575Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a
3576 href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly
3577with calls to <tt>llvm.va_end</tt>.</p>
Misha Brukman76307852003-11-08 01:05:38 +00003578</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003579
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003580<!-- _______________________________________________________________________ -->
Chris Lattner941515c2004-01-06 05:31:32 +00003581<div class="doc_subsubsection">
3582 <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a>
3583</div>
3584
Misha Brukman76307852003-11-08 01:05:38 +00003585<div class="doc_text">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003586
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003587<h5>Syntax:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003588
3589<pre>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003590 declare void %llvm.va_copy(&lt;va_list&gt;* &lt;destarglist&gt;,
Andrew Lenharth5305ea52005-06-22 20:38:11 +00003591 &lt;va_list&gt;* &lt;srcarglist&gt;)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003592</pre>
3593
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003594<h5>Overview:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003595
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003596<p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from
3597the source argument list to the destination argument list.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003598
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003599<h5>Arguments:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003600
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003601<p>The first argument is a pointer to a <tt>va_list</tt> element to initialize.
Andrew Lenharth5305ea52005-06-22 20:38:11 +00003602The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p>
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003603
Chris Lattner757528b0b2004-05-23 21:06:01 +00003604
Chris Lattnerbd64b4e2003-05-08 04:57:36 +00003605<h5>Semantics:</h5>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003606
Andrew Lenharth5fb787c2005-06-18 18:28:17 +00003607<p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro
3608available in C. In a target-dependent way, it copies the source
3609<tt>va_list</tt> element into the destination list. This intrinsic is necessary
3610because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be
Chris Lattner757528b0b2004-05-23 21:06:01 +00003611arbitrarily complex and require memory allocation, for example.</p>
3612
Misha Brukman76307852003-11-08 01:05:38 +00003613</div>
Chris Lattner941515c2004-01-06 05:31:32 +00003614
Chris Lattnerfee11462004-02-12 17:01:32 +00003615<!-- ======================================================================= -->
3616<div class="doc_subsection">
Chris Lattner757528b0b2004-05-23 21:06:01 +00003617 <a name="int_gc">Accurate Garbage Collection Intrinsics</a>
3618</div>
3619
3620<div class="doc_text">
3621
3622<p>
3623LLVM support for <a href="GarbageCollection.html">Accurate Garbage
3624Collection</a> requires the implementation and generation of these intrinsics.
3625These intrinsics allow identification of <a href="#i_gcroot">GC roots on the
3626stack</a>, as well as garbage collector implementations that require <a
3627href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers.
3628Front-ends for type-safe garbage collected languages should generate these
3629intrinsics to make use of the LLVM garbage collectors. For more details, see <a
3630href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>.
3631</p>
3632</div>
3633
3634<!-- _______________________________________________________________________ -->
3635<div class="doc_subsubsection">
3636 <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a>
3637</div>
3638
3639<div class="doc_text">
3640
3641<h5>Syntax:</h5>
3642
3643<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003644 declare void %llvm.gcroot(&lt;ty&gt;** %ptrloc, &lt;ty2&gt;* %metadata)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003645</pre>
3646
3647<h5>Overview:</h5>
3648
John Criswelldfe6a862004-12-10 15:51:16 +00003649<p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to
Chris Lattner757528b0b2004-05-23 21:06:01 +00003650the code generator, and allows some metadata to be associated with it.</p>
3651
3652<h5>Arguments:</h5>
3653
3654<p>The first argument specifies the address of a stack object that contains the
3655root pointer. The second pointer (which must be either a constant or a global
3656value address) contains the meta-data to be associated with the root.</p>
3657
3658<h5>Semantics:</h5>
3659
3660<p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc"
3661location. At compile-time, the code generator generates information to allow
3662the runtime to find the pointer at GC safe points.
3663</p>
3664
3665</div>
3666
3667
3668<!-- _______________________________________________________________________ -->
3669<div class="doc_subsubsection">
3670 <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a>
3671</div>
3672
3673<div class="doc_text">
3674
3675<h5>Syntax:</h5>
3676
3677<pre>
Chris Lattnerf9228072006-03-14 20:02:51 +00003678 declare sbyte* %llvm.gcread(sbyte* %ObjPtr, sbyte** %Ptr)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003679</pre>
3680
3681<h5>Overview:</h5>
3682
3683<p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap
3684locations, allowing garbage collector implementations that require read
3685barriers.</p>
3686
3687<h5>Arguments:</h5>
3688
Chris Lattnerf9228072006-03-14 20:02:51 +00003689<p>The second argument is the address to read from, which should be an address
3690allocated from the garbage collector. The first object is a pointer to the
3691start of the referenced object, if needed by the language runtime (otherwise
3692null).</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003693
3694<h5>Semantics:</h5>
3695
3696<p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load
3697instruction, but may be replaced with substantially more complex code by the
3698garbage collector runtime, as needed.</p>
3699
3700</div>
3701
3702
3703<!-- _______________________________________________________________________ -->
3704<div class="doc_subsubsection">
3705 <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a>
3706</div>
3707
3708<div class="doc_text">
3709
3710<h5>Syntax:</h5>
3711
3712<pre>
Chris Lattnerf9228072006-03-14 20:02:51 +00003713 declare void %llvm.gcwrite(sbyte* %P1, sbyte* %Obj, sbyte** %P2)
Chris Lattner757528b0b2004-05-23 21:06:01 +00003714</pre>
3715
3716<h5>Overview:</h5>
3717
3718<p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap
3719locations, allowing garbage collector implementations that require write
3720barriers (such as generational or reference counting collectors).</p>
3721
3722<h5>Arguments:</h5>
3723
Chris Lattnerf9228072006-03-14 20:02:51 +00003724<p>The first argument is the reference to store, the second is the start of the
3725object to store it to, and the third is the address of the field of Obj to
3726store to. If the runtime does not require a pointer to the object, Obj may be
3727null.</p>
Chris Lattner757528b0b2004-05-23 21:06:01 +00003728
3729<h5>Semantics:</h5>
3730
3731<p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store
3732instruction, but may be replaced with substantially more complex code by the
3733garbage collector runtime, as needed.</p>
3734
3735</div>
3736
3737
3738
3739<!-- ======================================================================= -->
3740<div class="doc_subsection">
Chris Lattner3649c3a2004-02-14 04:08:35 +00003741 <a name="int_codegen">Code Generator Intrinsics</a>
3742</div>
3743
3744<div class="doc_text">
3745<p>
3746These intrinsics are provided by LLVM to expose special features that may only
3747be implemented with code generator support.
3748</p>
3749
3750</div>
3751
3752<!-- _______________________________________________________________________ -->
3753<div class="doc_subsubsection">
3754 <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a>
3755</div>
3756
3757<div class="doc_text">
3758
3759<h5>Syntax:</h5>
3760<pre>
Chris Lattnerb3d430e2006-01-13 01:20:27 +00003761 declare sbyte *%llvm.returnaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003762</pre>
3763
3764<h5>Overview:</h5>
3765
3766<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003767The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a
3768target-specific value indicating the return address of the current function
3769or one of its callers.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003770</p>
3771
3772<h5>Arguments:</h5>
3773
3774<p>
3775The argument to this intrinsic indicates which function to return the address
3776for. Zero indicates the calling function, one indicates its caller, etc. The
3777argument is <b>required</b> to be a constant integer value.
3778</p>
3779
3780<h5>Semantics:</h5>
3781
3782<p>
3783The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating
3784the return address of the specified call frame, or zero if it cannot be
3785identified. The value returned by this intrinsic is likely to be incorrect or 0
3786for arguments other than zero, so it should only be used for debugging purposes.
3787</p>
3788
3789<p>
3790Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003791aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003792source-language caller.
3793</p>
3794</div>
3795
3796
3797<!-- _______________________________________________________________________ -->
3798<div class="doc_subsubsection">
3799 <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a>
3800</div>
3801
3802<div class="doc_text">
3803
3804<h5>Syntax:</h5>
3805<pre>
Chris Lattnerb3d430e2006-01-13 01:20:27 +00003806 declare sbyte *%llvm.frameaddress(uint &lt;level&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00003807</pre>
3808
3809<h5>Overview:</h5>
3810
3811<p>
Chris Lattnerc1fb4262006-10-15 20:05:59 +00003812The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the
3813target-specific frame pointer value for the specified stack frame.
Chris Lattner3649c3a2004-02-14 04:08:35 +00003814</p>
3815
3816<h5>Arguments:</h5>
3817
3818<p>
3819The argument to this intrinsic indicates which function to return the frame
3820pointer for. Zero indicates the calling function, one indicates its caller,
3821etc. The argument is <b>required</b> to be a constant integer value.
3822</p>
3823
3824<h5>Semantics:</h5>
3825
3826<p>
3827The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating
3828the frame address of the specified call frame, or zero if it cannot be
3829identified. The value returned by this intrinsic is likely to be incorrect or 0
3830for arguments other than zero, so it should only be used for debugging purposes.
3831</p>
3832
3833<p>
3834Note that calling this intrinsic does not prevent function inlining or other
Chris Lattner2e6eb5f2005-03-07 20:30:51 +00003835aggressive transformations, so the value returned may not be that of the obvious
Chris Lattner3649c3a2004-02-14 04:08:35 +00003836source-language caller.
3837</p>
3838</div>
3839
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003840<!-- _______________________________________________________________________ -->
3841<div class="doc_subsubsection">
Chris Lattner2f0f0012006-01-13 02:03:13 +00003842 <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a>
3843</div>
3844
3845<div class="doc_text">
3846
3847<h5>Syntax:</h5>
3848<pre>
3849 declare sbyte *%llvm.stacksave()
3850</pre>
3851
3852<h5>Overview:</h5>
3853
3854<p>
3855The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of
3856the function stack, for use with <a href="#i_stackrestore">
3857<tt>llvm.stackrestore</tt></a>. This is useful for implementing language
3858features like scoped automatic variable sized arrays in C99.
3859</p>
3860
3861<h5>Semantics:</h5>
3862
3863<p>
3864This intrinsic returns a opaque pointer value that can be passed to <a
3865href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an
3866<tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from
3867<tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the
3868state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In
3869practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack
3870that were allocated after the <tt>llvm.stacksave</tt> was executed.
3871</p>
3872
3873</div>
3874
3875<!-- _______________________________________________________________________ -->
3876<div class="doc_subsubsection">
3877 <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a>
3878</div>
3879
3880<div class="doc_text">
3881
3882<h5>Syntax:</h5>
3883<pre>
3884 declare void %llvm.stackrestore(sbyte* %ptr)
3885</pre>
3886
3887<h5>Overview:</h5>
3888
3889<p>
3890The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of
3891the function stack to the state it was in when the corresponding <a
3892href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is
3893useful for implementing language features like scoped automatic variable sized
3894arrays in C99.
3895</p>
3896
3897<h5>Semantics:</h5>
3898
3899<p>
3900See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>.
3901</p>
3902
3903</div>
3904
3905
3906<!-- _______________________________________________________________________ -->
3907<div class="doc_subsubsection">
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003908 <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a>
3909</div>
3910
3911<div class="doc_text">
3912
3913<h5>Syntax:</h5>
3914<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003915 declare void %llvm.prefetch(sbyte * &lt;address&gt;,
3916 uint &lt;rw&gt;, uint &lt;locality&gt;)
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003917</pre>
3918
3919<h5>Overview:</h5>
3920
3921
3922<p>
3923The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert
John Criswell88190562005-05-16 16:17:45 +00003924a prefetch instruction if supported; otherwise, it is a noop. Prefetches have
3925no
3926effect on the behavior of the program but can change its performance
Chris Lattnerff851072005-02-28 19:47:14 +00003927characteristics.
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003928</p>
3929
3930<h5>Arguments:</h5>
3931
3932<p>
3933<tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier
3934determining if the fetch should be for a read (0) or write (1), and
3935<tt>locality</tt> is a temporal locality specifier ranging from (0) - no
Chris Lattnerd3e641c2005-03-07 20:31:38 +00003936locality, to (3) - extremely local keep in cache. The <tt>rw</tt> and
Chris Lattnerc8a2c222005-02-28 19:24:19 +00003937<tt>locality</tt> arguments must be constant integers.
3938</p>
3939
3940<h5>Semantics:</h5>
3941
3942<p>
3943This intrinsic does not modify the behavior of the program. In particular,
3944prefetches cannot trap and do not produce a value. On targets that support this
3945intrinsic, the prefetch can provide hints to the processor cache for better
3946performance.
3947</p>
3948
3949</div>
3950
Andrew Lenharthb4427912005-03-28 20:05:49 +00003951<!-- _______________________________________________________________________ -->
3952<div class="doc_subsubsection">
3953 <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a>
3954</div>
3955
3956<div class="doc_text">
3957
3958<h5>Syntax:</h5>
3959<pre>
Reid Spencer7821d062005-04-26 20:50:44 +00003960 declare void %llvm.pcmarker( uint &lt;id&gt; )
Andrew Lenharthb4427912005-03-28 20:05:49 +00003961</pre>
3962
3963<h5>Overview:</h5>
3964
3965
3966<p>
John Criswell88190562005-05-16 16:17:45 +00003967The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter
3968(PC) in a region of
Andrew Lenharthb4427912005-03-28 20:05:49 +00003969code to simulators and other tools. The method is target specific, but it is
3970expected that the marker will use exported symbols to transmit the PC of the marker.
Jeff Cohendc6bfea2005-11-11 02:15:27 +00003971The marker makes no guarantees that it will remain with any specific instruction
Chris Lattnere64d41d2005-11-15 06:07:55 +00003972after optimizations. It is possible that the presence of a marker will inhibit
Chris Lattnerb40261e2006-03-24 07:16:10 +00003973optimizations. The intended use is to be inserted after optimizations to allow
John Criswell88190562005-05-16 16:17:45 +00003974correlations of simulation runs.
Andrew Lenharthb4427912005-03-28 20:05:49 +00003975</p>
3976
3977<h5>Arguments:</h5>
3978
3979<p>
3980<tt>id</tt> is a numerical id identifying the marker.
3981</p>
3982
3983<h5>Semantics:</h5>
3984
3985<p>
3986This intrinsic does not modify the behavior of the program. Backends that do not
3987support this intrinisic may ignore it.
3988</p>
3989
3990</div>
3991
Andrew Lenharth01aa5632005-11-11 16:47:30 +00003992<!-- _______________________________________________________________________ -->
3993<div class="doc_subsubsection">
3994 <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a>
3995</div>
3996
3997<div class="doc_text">
3998
3999<h5>Syntax:</h5>
4000<pre>
4001 declare ulong %llvm.readcyclecounter( )
4002</pre>
4003
4004<h5>Overview:</h5>
4005
4006
4007<p>
4008The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle
4009counter register (or similar low latency, high accuracy clocks) on those targets
4010that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC.
4011As the backing counters overflow quickly (on the order of 9 seconds on alpha), this
4012should only be used for small timings.
4013</p>
4014
4015<h5>Semantics:</h5>
4016
4017<p>
4018When directly supported, reading the cycle counter should not modify any memory.
4019Implementations are allowed to either return a application specific value or a
4020system wide value. On backends without support, this is lowered to a constant 0.
4021</p>
4022
4023</div>
4024
Chris Lattner3649c3a2004-02-14 04:08:35 +00004025<!-- ======================================================================= -->
4026<div class="doc_subsection">
Chris Lattnerfee11462004-02-12 17:01:32 +00004027 <a name="int_libc">Standard C Library Intrinsics</a>
4028</div>
4029
4030<div class="doc_text">
4031<p>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004032LLVM provides intrinsics for a few important standard C library functions.
4033These intrinsics allow source-language front-ends to pass information about the
4034alignment of the pointer arguments to the code generator, providing opportunity
4035for more efficient code generation.
Chris Lattnerfee11462004-02-12 17:01:32 +00004036</p>
4037
4038</div>
4039
4040<!-- _______________________________________________________________________ -->
4041<div class="doc_subsubsection">
4042 <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a>
4043</div>
4044
4045<div class="doc_text">
4046
4047<h5>Syntax:</h5>
4048<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004049 declare void %llvm.memcpy.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
4050 uint &lt;len&gt;, uint &lt;align&gt;)
4051 declare void %llvm.memcpy.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
4052 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerfee11462004-02-12 17:01:32 +00004053</pre>
4054
4055<h5>Overview:</h5>
4056
4057<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004058The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004059location to the destination location.
4060</p>
4061
4062<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004063Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>
4064intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerfee11462004-02-12 17:01:32 +00004065</p>
4066
4067<h5>Arguments:</h5>
4068
4069<p>
4070The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004071the source. The third argument is an integer argument
Chris Lattnerfee11462004-02-12 17:01:32 +00004072specifying the number of bytes to copy, and the fourth argument is the alignment
4073of the source and destination locations.
4074</p>
4075
Chris Lattner4c67c482004-02-12 21:18:15 +00004076<p>
4077If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004078the caller guarantees that both the source and destination pointers are aligned
4079to that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004080</p>
4081
Chris Lattnerfee11462004-02-12 17:01:32 +00004082<h5>Semantics:</h5>
4083
4084<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004085The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerfee11462004-02-12 17:01:32 +00004086location to the destination location, which are not allowed to overlap. It
4087copies "len" bytes of memory over. If the argument is known to be aligned to
4088some boundary, this can be specified as the fourth argument, otherwise it should
4089be set to 0 or 1.
4090</p>
4091</div>
4092
4093
Chris Lattnerf30152e2004-02-12 18:10:10 +00004094<!-- _______________________________________________________________________ -->
4095<div class="doc_subsubsection">
4096 <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a>
4097</div>
4098
4099<div class="doc_text">
4100
4101<h5>Syntax:</h5>
4102<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004103 declare void %llvm.memmove.i32(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
4104 uint &lt;len&gt;, uint &lt;align&gt;)
4105 declare void %llvm.memmove.i64(sbyte* &lt;dest&gt;, sbyte* &lt;src&gt;,
4106 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattnerf30152e2004-02-12 18:10:10 +00004107</pre>
4108
4109<h5>Overview:</h5>
4110
4111<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004112The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source
4113location to the destination location. It is similar to the
4114'<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004115</p>
4116
4117<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004118Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>
4119intrinsics do not return a value, and takes an extra alignment argument.
Chris Lattnerf30152e2004-02-12 18:10:10 +00004120</p>
4121
4122<h5>Arguments:</h5>
4123
4124<p>
4125The first argument is a pointer to the destination, the second is a pointer to
Chris Lattner0c8b2592006-03-03 00:07:20 +00004126the source. The third argument is an integer argument
Chris Lattnerf30152e2004-02-12 18:10:10 +00004127specifying the number of bytes to copy, and the fourth argument is the alignment
4128of the source and destination locations.
4129</p>
4130
Chris Lattner4c67c482004-02-12 21:18:15 +00004131<p>
4132If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004133the caller guarantees that the source and destination pointers are aligned to
4134that boundary.
Chris Lattner4c67c482004-02-12 21:18:15 +00004135</p>
4136
Chris Lattnerf30152e2004-02-12 18:10:10 +00004137<h5>Semantics:</h5>
4138
4139<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004140The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source
Chris Lattnerf30152e2004-02-12 18:10:10 +00004141location to the destination location, which may overlap. It
4142copies "len" bytes of memory over. If the argument is known to be aligned to
4143some boundary, this can be specified as the fourth argument, otherwise it should
4144be set to 0 or 1.
4145</p>
4146</div>
4147
Chris Lattner941515c2004-01-06 05:31:32 +00004148
Chris Lattner3649c3a2004-02-14 04:08:35 +00004149<!-- _______________________________________________________________________ -->
4150<div class="doc_subsubsection">
Chris Lattner0c8b2592006-03-03 00:07:20 +00004151 <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a>
Chris Lattner3649c3a2004-02-14 04:08:35 +00004152</div>
4153
4154<div class="doc_text">
4155
4156<h5>Syntax:</h5>
4157<pre>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004158 declare void %llvm.memset.i32(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
4159 uint &lt;len&gt;, uint &lt;align&gt;)
4160 declare void %llvm.memset.i64(sbyte* &lt;dest&gt;, ubyte &lt;val&gt;,
4161 ulong &lt;len&gt;, uint &lt;align&gt;)
Chris Lattner3649c3a2004-02-14 04:08:35 +00004162</pre>
4163
4164<h5>Overview:</h5>
4165
4166<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004167The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular
Chris Lattner3649c3a2004-02-14 04:08:35 +00004168byte value.
4169</p>
4170
4171<p>
4172Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic
4173does not return a value, and takes an extra alignment argument.
4174</p>
4175
4176<h5>Arguments:</h5>
4177
4178<p>
4179The first argument is a pointer to the destination to fill, the second is the
Chris Lattner0c8b2592006-03-03 00:07:20 +00004180byte value to fill it with, the third argument is an integer
Chris Lattner3649c3a2004-02-14 04:08:35 +00004181argument specifying the number of bytes to fill, and the fourth argument is the
4182known alignment of destination location.
4183</p>
4184
4185<p>
4186If the call to this intrinisic has an alignment value that is not 0 or 1, then
Chris Lattner5316e5d2006-03-04 00:02:10 +00004187the caller guarantees that the destination pointer is aligned to that boundary.
Chris Lattner3649c3a2004-02-14 04:08:35 +00004188</p>
4189
4190<h5>Semantics:</h5>
4191
4192<p>
Chris Lattner0c8b2592006-03-03 00:07:20 +00004193The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at
4194the
Chris Lattner3649c3a2004-02-14 04:08:35 +00004195destination location. If the argument is known to be aligned to some boundary,
4196this can be specified as the fourth argument, otherwise it should be set to 0 or
41971.
4198</p>
4199</div>
4200
4201
Chris Lattner3b4f4372004-06-11 02:28:03 +00004202<!-- _______________________________________________________________________ -->
4203<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004204 <a name="i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a>
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00004205</div>
4206
4207<div class="doc_text">
4208
4209<h5>Syntax:</h5>
4210<pre>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004211 declare bool %llvm.isunordered.f32(float Val1, float Val2)
4212 declare bool %llvm.isunordered.f64(double Val1, double Val2)
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00004213</pre>
4214
4215<h5>Overview:</h5>
4216
4217<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004218The '<tt>llvm.isunordered</tt>' intrinsics return true if either or both of the
Alkis Evlogimenos0fa39232004-06-13 01:16:15 +00004219specified floating point values is a NAN.
4220</p>
4221
4222<h5>Arguments:</h5>
4223
4224<p>
4225The arguments are floating point numbers of the same type.
4226</p>
4227
4228<h5>Semantics:</h5>
4229
4230<p>
4231If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise
4232false.
4233</p>
4234</div>
4235
4236
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004237<!-- _______________________________________________________________________ -->
4238<div class="doc_subsubsection">
Chris Lattner069b5bd2006-01-16 22:38:59 +00004239 <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a>
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004240</div>
4241
4242<div class="doc_text">
4243
4244<h5>Syntax:</h5>
4245<pre>
Chris Lattner33b73f92006-09-08 06:34:02 +00004246 declare float %llvm.sqrt.f32(float %Val)
4247 declare double %llvm.sqrt.f64(double %Val)
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004248</pre>
4249
4250<h5>Overview:</h5>
4251
4252<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004253The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand,
Chris Lattner8a8f2e52005-07-21 01:29:16 +00004254returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike
4255<tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for
4256negative numbers (which allows for better optimization).
4257</p>
4258
4259<h5>Arguments:</h5>
4260
4261<p>
4262The argument and return value are floating point numbers of the same type.
4263</p>
4264
4265<h5>Semantics:</h5>
4266
4267<p>
4268This function returns the sqrt of the specified operand if it is a positive
4269floating point number.
4270</p>
4271</div>
4272
Chris Lattner33b73f92006-09-08 06:34:02 +00004273<!-- _______________________________________________________________________ -->
4274<div class="doc_subsubsection">
4275 <a name="i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a>
4276</div>
4277
4278<div class="doc_text">
4279
4280<h5>Syntax:</h5>
4281<pre>
4282 declare float %llvm.powi.f32(float %Val, int %power)
4283 declare double %llvm.powi.f64(double %Val, int %power)
4284</pre>
4285
4286<h5>Overview:</h5>
4287
4288<p>
4289The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the
4290specified (positive or negative) power. The order of evaluation of
4291multiplications is not defined.
4292</p>
4293
4294<h5>Arguments:</h5>
4295
4296<p>
4297The second argument is an integer power, and the first is a value to raise to
4298that power.
4299</p>
4300
4301<h5>Semantics:</h5>
4302
4303<p>
4304This function returns the first value raised to the second power with an
4305unspecified sequence of rounding operations.</p>
4306</div>
4307
4308
Andrew Lenharth1d463522005-05-03 18:01:48 +00004309<!-- ======================================================================= -->
4310<div class="doc_subsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004311 <a name="int_manip">Bit Manipulation Intrinsics</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004312</div>
4313
4314<div class="doc_text">
4315<p>
Nate Begeman0f223bb2006-01-13 23:26:38 +00004316LLVM provides intrinsics for a few important bit manipulation operations.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004317These allow efficient code generation for some algorithms.
4318</p>
4319
4320</div>
4321
4322<!-- _______________________________________________________________________ -->
4323<div class="doc_subsubsection">
Nate Begeman0f223bb2006-01-13 23:26:38 +00004324 <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a>
4325</div>
4326
4327<div class="doc_text">
4328
4329<h5>Syntax:</h5>
4330<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004331 declare ushort %llvm.bswap.i16(ushort &lt;id&gt;)
4332 declare uint %llvm.bswap.i32(uint &lt;id&gt;)
4333 declare ulong %llvm.bswap.i64(ulong &lt;id&gt;)
Nate Begeman0f223bb2006-01-13 23:26:38 +00004334</pre>
4335
4336<h5>Overview:</h5>
4337
4338<p>
4339The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or
434064 bit quantity. These are useful for performing operations on data that is not
4341in the target's native byte order.
4342</p>
4343
4344<h5>Semantics:</h5>
4345
4346<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004347The <tt>llvm.bswap.16</tt> intrinsic returns a ushort value that has the high and low
4348byte of the input ushort swapped. Similarly, the <tt>llvm.bswap.i32</tt> intrinsic
Nate Begeman0f223bb2006-01-13 23:26:38 +00004349returns a uint value that has the four bytes of the input uint swapped, so that
4350if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its
Chris Lattner069b5bd2006-01-16 22:38:59 +00004351bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt> intrinsic extends this concept
Nate Begeman0f223bb2006-01-13 23:26:38 +00004352to 64 bits.
4353</p>
4354
4355</div>
4356
4357<!-- _______________________________________________________________________ -->
4358<div class="doc_subsubsection">
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004359 <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004360</div>
4361
4362<div class="doc_text">
4363
4364<h5>Syntax:</h5>
4365<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004366 declare ubyte %llvm.ctpop.i8 (ubyte &lt;src&gt;)
4367 declare ushort %llvm.ctpop.i16(ushort &lt;src&gt;)
4368 declare uint %llvm.ctpop.i32(uint &lt;src&gt;)
4369 declare ulong %llvm.ctpop.i64(ulong &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004370</pre>
4371
4372<h5>Overview:</h5>
4373
4374<p>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004375The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a
4376value.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004377</p>
4378
4379<h5>Arguments:</h5>
4380
4381<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004382The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00004383unsigned integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004384</p>
4385
4386<h5>Semantics:</h5>
4387
4388<p>
4389The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable.
4390</p>
4391</div>
4392
4393<!-- _______________________________________________________________________ -->
4394<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004395 <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a>
Andrew Lenharth1d463522005-05-03 18:01:48 +00004396</div>
4397
4398<div class="doc_text">
4399
4400<h5>Syntax:</h5>
4401<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004402 declare ubyte %llvm.ctlz.i8 (ubyte &lt;src&gt;)
4403 declare ushort %llvm.ctlz.i16(ushort &lt;src&gt;)
4404 declare uint %llvm.ctlz.i32(uint &lt;src&gt;)
4405 declare ulong %llvm.ctlz.i64(ulong &lt;src&gt;)
Andrew Lenharth1d463522005-05-03 18:01:48 +00004406</pre>
4407
4408<h5>Overview:</h5>
4409
4410<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004411The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of
4412leading zeros in a variable.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004413</p>
4414
4415<h5>Arguments:</h5>
4416
4417<p>
Chris Lattner573f64e2005-05-07 01:46:40 +00004418The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00004419unsigned integer type. The return type must match the argument type.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004420</p>
4421
4422<h5>Semantics:</h5>
4423
4424<p>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004425The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros
4426in a variable. If the src == 0 then the result is the size in bits of the type
Chris Lattner905bd172006-04-21 21:37:40 +00004427of src. For example, <tt>llvm.ctlz(int 2) = 30</tt>.
Andrew Lenharth1d463522005-05-03 18:01:48 +00004428</p>
4429</div>
Chris Lattner3b4f4372004-06-11 02:28:03 +00004430
4431
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004432
4433<!-- _______________________________________________________________________ -->
4434<div class="doc_subsubsection">
Chris Lattnerb748c672006-01-16 22:34:14 +00004435 <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a>
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004436</div>
4437
4438<div class="doc_text">
4439
4440<h5>Syntax:</h5>
4441<pre>
Chris Lattner069b5bd2006-01-16 22:38:59 +00004442 declare ubyte %llvm.cttz.i8 (ubyte &lt;src&gt;)
4443 declare ushort %llvm.cttz.i16(ushort &lt;src&gt;)
4444 declare uint %llvm.cttz.i32(uint &lt;src&gt;)
4445 declare ulong %llvm.cttz.i64(ulong &lt;src&gt;)
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004446</pre>
4447
4448<h5>Overview:</h5>
4449
4450<p>
Reid Spencerb4f9a6f2006-01-16 21:12:35 +00004451The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of
4452trailing zeros.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004453</p>
4454
4455<h5>Arguments:</h5>
4456
4457<p>
4458The only argument is the value to be counted. The argument may be of any
Chris Lattner069b5bd2006-01-16 22:38:59 +00004459unsigned integer type. The return type must match the argument type.
Chris Lattnerefa20fa2005-05-15 19:39:26 +00004460</p>
4461
4462<h5>Semantics:</h5>
4463
4464<p>
4465The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros
4466in a variable. If the src == 0 then the result is the size in bits of the type
4467of src. For example, <tt>llvm.cttz(2) = 1</tt>.
4468</p>
4469</div>
4470
Chris Lattner941515c2004-01-06 05:31:32 +00004471<!-- ======================================================================= -->
4472<div class="doc_subsection">
4473 <a name="int_debugger">Debugger Intrinsics</a>
4474</div>
4475
4476<div class="doc_text">
4477<p>
4478The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix),
4479are described in the <a
4480href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level
4481Debugging</a> document.
4482</p>
4483</div>
4484
4485
Chris Lattner2f7c9632001-06-06 20:29:01 +00004486<!-- *********************************************************************** -->
Chris Lattner2f7c9632001-06-06 20:29:01 +00004487<hr>
Misha Brukmanc501f552004-03-01 17:47:27 +00004488<address>
4489 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
4490 src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
4491 <a href="http://validator.w3.org/check/referer"><img
4492 src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a>
4493
4494 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
Reid Spencerca058542006-03-14 05:39:39 +00004495 <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
Misha Brukmanc501f552004-03-01 17:47:27 +00004496 Last modified: $Date$
4497</address>
Misha Brukman76307852003-11-08 01:05:38 +00004498</body>
4499</html>