Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3 | <html> |
| 4 | <head> |
| 5 | <title>LLVM Assembly Language Reference Manual</title> |
Reid Spencer | 3921c74 | 2004-08-26 20:44:00 +0000 | [diff] [blame] | 6 | <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 Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 10 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
| 11 | </head> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 12 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 13 | <body> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 14 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 15 | <div class="doc_title"> LLVM Language Reference Manual </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 17 | <li><a href="#abstract">Abstract</a></li> |
| 18 | <li><a href="#introduction">Introduction</a></li> |
| 19 | <li><a href="#identifiers">Identifiers</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 20 | <li><a href="#highlevel">High Level Structure</a> |
| 21 | <ol> |
| 22 | <li><a href="#modulestructure">Module Structure</a></li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 23 | <li><a href="#linkage">Linkage Types</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 24 | <li><a href="#globalvars">Global Variables</a></li> |
| 25 | <li><a href="#functionstructure">Function Structure</a></li> |
| 26 | </ol> |
| 27 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 28 | <li><a href="#typesystem">Type System</a> |
| 29 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 30 | <li><a href="#t_primitive">Primitive Types</a> |
| 31 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 32 | <li><a href="#t_classifications">Type Classifications</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 33 | </ol> |
| 34 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 35 | <li><a href="#t_derived">Derived Types</a> |
| 36 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 37 | <li><a href="#t_array">Array Type</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 38 | <li><a href="#t_function">Function Type</a></li> |
| 39 | <li><a href="#t_pointer">Pointer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 40 | <li><a href="#t_struct">Structure Type</a></li> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 41 | <li><a href="#t_packed">Packed Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 42 | </ol> |
| 43 | </li> |
| 44 | </ol> |
| 45 | </li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 46 | <li><a href="#constants">Constants</a> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 47 | <ol> |
| 48 | <li><a href="#simpleconstants">Simple Constants</a> |
| 49 | <li><a href="#aggregateconstants">Aggregate Constants</a> |
| 50 | <li><a href="#globalconstants">Global Variable and Function Addresses</a> |
| 51 | <li><a href="#undefvalues">Undefined Values</a> |
| 52 | <li><a href="#constantexprs">Constant Expressions</a> |
| 53 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 54 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 55 | <li><a href="#instref">Instruction Reference</a> |
| 56 | <ol> |
| 57 | <li><a href="#terminators">Terminator Instructions</a> |
| 58 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 59 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> |
| 60 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 61 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> |
| 62 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 63 | <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 64 | <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 65 | </ol> |
| 66 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 67 | <li><a href="#binaryops">Binary Operations</a> |
| 68 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 69 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> |
| 70 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> |
| 71 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> |
| 72 | <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li> |
| 73 | <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 74 | <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 75 | </ol> |
| 76 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 77 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> |
| 78 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 79 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 80 | <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 81 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> |
| 82 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> |
| 83 | <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 84 | </ol> |
| 85 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 86 | <li><a href="#memoryops">Memory Access Operations</a> |
| 87 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 88 | <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li> |
| 89 | <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li> |
| 90 | <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li> |
| 91 | <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li> |
| 92 | <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li> |
| 93 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> |
| 94 | </ol> |
| 95 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 96 | <li><a href="#otherops">Other Operations</a> |
| 97 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 98 | <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 99 | <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 100 | <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 101 | <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 102 | <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 103 | <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 104 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 105 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 106 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 107 | </li> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 108 | <li><a href="#intrinsics">Intrinsic Functions</a> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 109 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 110 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> |
| 111 | <ol> |
| 112 | <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> |
| 113 | <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li> |
| 114 | <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li> |
| 115 | </ol> |
| 116 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 117 | <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> |
| 118 | <ol> |
| 119 | <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> |
| 120 | <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> |
| 121 | <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> |
| 122 | </ol> |
| 123 | </li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 124 | <li><a href="#int_codegen">Code Generator Intrinsics</a> |
| 125 | <ol> |
| 126 | <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> |
| 127 | <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 128 | </ol> |
| 129 | </li> |
| 130 | <li><a href="#int_os">Operating System Intrinsics</a> |
| 131 | <ol> |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 132 | <li><a href="#i_readport">'<tt>llvm.readport</tt>' Intrinsic</a></li> |
| 133 | <li><a href="#i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a></li> |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 134 | <li><a href="#i_readio">'<tt>llvm.readio</tt>' Intrinsic</a></li> |
| 135 | <li><a href="#i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a></li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 136 | </ol> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 137 | <li><a href="#int_libc">Standard C Library Intrinsics</a> |
| 138 | <ol> |
| 139 | <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li> |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 140 | <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 141 | <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li> |
Alkis Evlogimenos | 9685372 | 2004-06-12 19:19:14 +0000 | [diff] [blame] | 142 | <li><a href="#i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a></li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 143 | </ol> |
| 144 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 145 | <li><a href="#int_debugger">Debugger intrinsics</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 146 | </ol> |
| 147 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 148 | </ol> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 149 | |
| 150 | <div class="doc_author"> |
| 151 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
| 152 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 153 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 154 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 155 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 156 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 157 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 158 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 159 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 160 | <p>This document is a reference manual for the LLVM assembly language. |
| 161 | LLVM is an SSA based representation that provides type safety, |
| 162 | low-level operations, flexibility, and the capability of representing |
| 163 | 'all' high-level languages cleanly. It is the common code |
| 164 | representation used throughout all phases of the LLVM compilation |
| 165 | strategy.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 166 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 167 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 168 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 169 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> |
| 170 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 171 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 172 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 174 | <p>The LLVM code representation is designed to be used in three |
| 175 | different forms: as an in-memory compiler IR, as an on-disk bytecode |
| 176 | representation (suitable for fast loading by a Just-In-Time compiler), |
| 177 | and as a human readable assembly language representation. This allows |
| 178 | LLVM to provide a powerful intermediate representation for efficient |
| 179 | compiler transformations and analysis, while providing a natural means |
| 180 | to debug and visualize the transformations. The three different forms |
| 181 | of LLVM are all equivalent. This document describes the human readable |
| 182 | representation and notation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 183 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 184 | <p>The LLVM representation aims to be a light-weight and low-level |
| 185 | while being expressive, typed, and extensible at the same time. It |
| 186 | aims to be a "universal IR" of sorts, by being at a low enough level |
| 187 | that high-level ideas may be cleanly mapped to it (similar to how |
| 188 | microprocessors are "universal IR's", allowing many source languages to |
| 189 | be mapped to them). By providing type information, LLVM can be used as |
| 190 | the target of optimizations: for example, through pointer analysis, it |
| 191 | can be proven that a C automatic variable is never accessed outside of |
| 192 | the current function... allowing it to be promoted to a simple SSA |
| 193 | value instead of a memory location.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 194 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 195 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 197 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 198 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 199 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 200 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 201 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 202 | <p>It is important to note that this document describes 'well formed' |
| 203 | LLVM assembly language. There is a difference between what the parser |
| 204 | accepts and what is considered 'well formed'. For example, the |
| 205 | following instruction is syntactically okay, but not well formed:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 206 | |
| 207 | <pre> |
| 208 | %x = <a href="#i_add">add</a> int 1, %x |
| 209 | </pre> |
| 210 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 211 | <p>...because the definition of <tt>%x</tt> does not dominate all of |
| 212 | its uses. The LLVM infrastructure provides a verification pass that may |
| 213 | be used to verify that an LLVM module is well formed. This pass is |
| 214 | automatically run by the parser after parsing input assembly, and by |
| 215 | the optimizer before it outputs bytecode. The violations pointed out |
| 216 | by the verifier pass indicate bugs in transformation passes or input to |
| 217 | the parser.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 218 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 219 | <!-- Describe the typesetting conventions here. --> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 220 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 221 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 222 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 223 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 224 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 225 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 226 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 227 | <p>LLVM uses three different forms of identifiers, for different |
| 228 | purposes:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 229 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 230 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 231 | <li>Named values are represented as a string of characters with a '%' prefix. |
| 232 | For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual |
| 233 | regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. |
| 234 | Identifiers which require other characters in their names can be surrounded |
| 235 | with quotes. In this way, anything except a <tt>"</tt> character can be used |
| 236 | in a name.</li> |
| 237 | |
| 238 | <li>Unnamed values are represented as an unsigned numeric value with a '%' |
| 239 | prefix. For example, %12, %2, %44.</li> |
| 240 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 241 | <li>Constants, which are described in <a href="#constants">section about |
| 242 | constants</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 243 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 244 | |
| 245 | <p>LLVM requires that values start with a '%' sign for two reasons: Compilers |
| 246 | don't need to worry about name clashes with reserved words, and the set of |
| 247 | reserved words may be expanded in the future without penalty. Additionally, |
| 248 | unnamed identifiers allow a compiler to quickly come up with a temporary |
| 249 | variable without having to avoid symbol table conflicts.</p> |
| 250 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 251 | <p>Reserved words in LLVM are very similar to reserved words in other |
| 252 | languages. There are keywords for different opcodes ('<tt><a |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 253 | href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a |
| 254 | href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a |
| 255 | href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...), |
| 256 | and others. These reserved words cannot conflict with variable names, because |
| 257 | none of them start with a '%' character.</p> |
| 258 | |
| 259 | <p>Here is an example of LLVM code to multiply the integer variable |
| 260 | '<tt>%X</tt>' by 8:</p> |
| 261 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 262 | <p>The easy way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 263 | |
| 264 | <pre> |
| 265 | %result = <a href="#i_mul">mul</a> uint %X, 8 |
| 266 | </pre> |
| 267 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 268 | <p>After strength reduction:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 269 | |
| 270 | <pre> |
| 271 | %result = <a href="#i_shl">shl</a> uint %X, ubyte 3 |
| 272 | </pre> |
| 273 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 274 | <p>And the hard way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 275 | |
| 276 | <pre> |
| 277 | <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i> |
| 278 | <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i> |
| 279 | %result = <a href="#i_add">add</a> uint %1, %1 |
| 280 | </pre> |
| 281 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 282 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several |
| 283 | important lexical features of LLVM:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 284 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 285 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 286 | |
| 287 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end of |
| 288 | line.</li> |
| 289 | |
| 290 | <li>Unnamed temporaries are created when the result of a computation is not |
| 291 | assigned to a named value.</li> |
| 292 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 293 | <li>Unnamed temporaries are numbered sequentially</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 294 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 295 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 296 | |
| 297 | <p>...and it also show a convention that we follow in this document. When |
| 298 | demonstrating instructions, we will follow an instruction with a comment that |
| 299 | defines the type and name of value produced. Comments are shown in italic |
| 300 | text.</p> |
| 301 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 302 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 303 | |
| 304 | <!-- *********************************************************************** --> |
| 305 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> |
| 306 | <!-- *********************************************************************** --> |
| 307 | |
| 308 | <!-- ======================================================================= --> |
| 309 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> |
| 310 | </div> |
| 311 | |
| 312 | <div class="doc_text"> |
| 313 | |
| 314 | <p>LLVM programs are composed of "Module"s, each of which is a |
| 315 | translation unit of the input programs. Each module consists of |
| 316 | functions, global variables, and symbol table entries. Modules may be |
| 317 | combined together with the LLVM linker, which merges function (and |
| 318 | global variable) definitions, resolves forward declarations, and merges |
| 319 | symbol table entries. Here is an example of the "hello world" module:</p> |
| 320 | |
| 321 | <pre><i>; Declare the string constant as a global constant...</i> |
| 322 | <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a |
| 323 | href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i> |
| 324 | |
| 325 | <i>; External declaration of the puts function</i> |
| 326 | <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i> |
| 327 | |
| 328 | <i>; Definition of main function</i> |
| 329 | int %main() { <i>; int()* </i> |
| 330 | <i>; Convert [13x sbyte]* to sbyte *...</i> |
| 331 | %cast210 = <a |
| 332 | href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i> |
| 333 | |
| 334 | <i>; Call puts function to write out the string to stdout...</i> |
| 335 | <a |
| 336 | href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i> |
| 337 | <a |
| 338 | href="#i_ret">ret</a> int 0<br>}<br></pre> |
| 339 | |
| 340 | <p>This example is made up of a <a href="#globalvars">global variable</a> |
| 341 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" |
| 342 | function, and a <a href="#functionstructure">function definition</a> |
| 343 | for "<tt>main</tt>".</p> |
| 344 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 345 | <p>In general, a module is made up of a list of global values, |
| 346 | where both functions and global variables are global values. Global values are |
| 347 | represented by a pointer to a memory location (in this case, a pointer to an |
| 348 | array of char, and a pointer to a function), and have one of the following <a |
| 349 | href="#linkage">linkage types</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 350 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 351 | </div> |
| 352 | |
| 353 | <!-- ======================================================================= --> |
| 354 | <div class="doc_subsection"> |
| 355 | <a name="linkage">Linkage Types</a> |
| 356 | </div> |
| 357 | |
| 358 | <div class="doc_text"> |
| 359 | |
| 360 | <p> |
| 361 | All Global Variables and Functions have one of the following types of linkage: |
| 362 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 363 | |
| 364 | <dl> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 365 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 366 | <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 367 | |
| 368 | <dd>Global values with internal linkage are only directly accessible by |
| 369 | objects in the current module. In particular, linking code into a module with |
| 370 | an internal global value may cause the internal to be renamed as necessary to |
| 371 | avoid collisions. Because the symbol is internal to the module, all |
| 372 | references can be updated. This corresponds to the notion of the |
| 373 | '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 374 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 375 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 376 | <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 377 | |
| 378 | <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with |
| 379 | the twist that linking together two modules defining the same |
| 380 | <tt>linkonce</tt> globals will cause one of the globals to be discarded. This |
| 381 | is typically used to implement inline functions. Unreferenced |
| 382 | <tt>linkonce</tt> globals are allowed to be discarded. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 383 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 384 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 385 | <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 386 | |
| 387 | <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage, |
| 388 | except that unreferenced <tt>weak</tt> globals may not be discarded. This is |
| 389 | used to implement constructs in C such as "<tt>int X;</tt>" at global scope. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 390 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 391 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 392 | <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 393 | |
| 394 | <dd>"<tt>appending</tt>" linkage may only be applied to global variables of |
| 395 | pointer to array type. When two global variables with appending linkage are |
| 396 | linked together, the two global arrays are appended together. This is the |
| 397 | LLVM, typesafe, equivalent of having the system linker append together |
| 398 | "sections" with identical names when .o files are linked. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 399 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 400 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 401 | <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 402 | |
| 403 | <dd>If none of the above identifiers are used, the global is externally |
| 404 | visible, meaning that it participates in linkage and can be used to resolve |
| 405 | external symbol references. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 406 | </dd> |
| 407 | </dl> |
| 408 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 409 | <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>" |
| 410 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" |
| 411 | variable and was linked with this one, one of the two would be renamed, |
| 412 | preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are |
| 413 | external (i.e., lacking any linkage declarations), they are accessible |
| 414 | outside of the current module. It is illegal for a function <i>declaration</i> |
| 415 | to have any linkage type other than "externally visible".</a></p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 416 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 417 | </div> |
| 418 | |
| 419 | <!-- ======================================================================= --> |
| 420 | <div class="doc_subsection"> |
| 421 | <a name="globalvars">Global Variables</a> |
| 422 | </div> |
| 423 | |
| 424 | <div class="doc_text"> |
| 425 | |
| 426 | <p>Global variables define regions of memory allocated at compilation |
| 427 | time instead of run-time. Global variables may optionally be |
| 428 | initialized. A variable may be defined as a global "constant", which |
| 429 | indicates that the contents of the variable will never be modified |
| 430 | (enabling better optimization, allowing the global data to be placed in the |
| 431 | read-only section of an executable, etc).</p> |
| 432 | |
| 433 | <p>As SSA values, global variables define pointer values that are in |
| 434 | scope (i.e. they dominate) all basic blocks in the program. Global |
| 435 | variables always define a pointer to their "content" type because they |
| 436 | describe a region of memory, and all memory objects in LLVM are |
| 437 | accessed through pointers.</p> |
| 438 | |
| 439 | </div> |
| 440 | |
| 441 | |
| 442 | <!-- ======================================================================= --> |
| 443 | <div class="doc_subsection"> |
| 444 | <a name="functionstructure">Functions</a> |
| 445 | </div> |
| 446 | |
| 447 | <div class="doc_text"> |
| 448 | |
| 449 | <p>LLVM function definitions are composed of a (possibly empty) argument list, |
| 450 | an opening curly brace, a list of basic blocks, and a closing curly brace. LLVM |
| 451 | function declarations are defined with the "<tt>declare</tt>" keyword, a |
| 452 | function name, and a function signature.</p> |
| 453 | |
| 454 | <p>A function definition contains a list of basic blocks, forming the CFG for |
| 455 | the function. Each basic block may optionally start with a label (giving the |
| 456 | basic block a symbol table entry), contains a list of instructions, and ends |
| 457 | with a <a href="#terminators">terminator</a> instruction (such as a branch or |
| 458 | function return).</p> |
| 459 | |
| 460 | <p>The first basic block in program is special in two ways: it is immediately |
| 461 | executed on entrance to the function, and it is not allowed to have predecessor |
| 462 | basic blocks (i.e. there can not be any branches to the entry block of a |
| 463 | function). Because the block can have no predecessors, it also cannot have any |
| 464 | <a href="#i_phi">PHI nodes</a>.</p> |
| 465 | |
| 466 | <p>LLVM functions are identified by their name and type signature. Hence, two |
| 467 | functions with the same name but different parameter lists or return values are |
| 468 | considered different functions, and LLVM will resolves references to each |
| 469 | appropriately.</p> |
| 470 | |
| 471 | </div> |
| 472 | |
| 473 | |
| 474 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 475 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 476 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> |
| 477 | <!-- *********************************************************************** --> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 478 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 479 | <div class="doc_text"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 480 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 481 | <p>The LLVM type system is one of the most important features of the |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 482 | intermediate representation. Being typed enables a number of |
| 483 | optimizations to be performed on the IR directly, without having to do |
| 484 | extra analyses on the side before the transformation. A strong type |
| 485 | system makes it easier to read the generated code and enables novel |
| 486 | analyses and transformations that are not feasible to perform on normal |
| 487 | three address code representations.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 488 | |
| 489 | </div> |
| 490 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 491 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 492 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 493 | <div class="doc_text"> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 494 | <p>The primitive types are the fundamental building blocks of the LLVM |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 495 | system. The current set of primitive types are as follows:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 496 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 497 | <table class="layout"> |
| 498 | <tr class="layout"> |
| 499 | <td class="left"> |
| 500 | <table> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 501 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 502 | <tr><th>Type</th><th>Description</th></tr> |
| 503 | <tr><td><tt>void</tt></td><td>No value</td></tr> |
| 504 | <tr><td><tt>ubyte</tt></td><td>Unsigned 8 bit value</td></tr> |
| 505 | <tr><td><tt>ushort</tt></td><td>Unsigned 16 bit value</td></tr> |
| 506 | <tr><td><tt>uint</tt></td><td>Unsigned 32 bit value</td></tr> |
| 507 | <tr><td><tt>ulong</tt></td><td>Unsigned 64 bit value</td></tr> |
| 508 | <tr><td><tt>float</tt></td><td>32 bit floating point value</td></tr> |
| 509 | <tr><td><tt>label</tt></td><td>Branch destination</td></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 510 | </tbody> |
| 511 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 512 | </td> |
| 513 | <td class="right"> |
| 514 | <table> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 515 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 516 | <tr><th>Type</th><th>Description</th></tr> |
| 517 | <tr><td><tt>bool</tt></td><td>True or False value</td></tr> |
| 518 | <tr><td><tt>sbyte</tt></td><td>Signed 8 bit value</td></tr> |
| 519 | <tr><td><tt>short</tt></td><td>Signed 16 bit value</td></tr> |
| 520 | <tr><td><tt>int</tt></td><td>Signed 32 bit value</td></tr> |
| 521 | <tr><td><tt>long</tt></td><td>Signed 64 bit value</td></tr> |
| 522 | <tr><td><tt>double</tt></td><td>64 bit floating point value</td></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 523 | </tbody> |
| 524 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 525 | </td> |
| 526 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 527 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 528 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 529 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 530 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 531 | <div class="doc_subsubsection"> <a name="t_classifications">Type |
| 532 | Classifications</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 533 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 534 | <p>These different primitive types fall into a few useful |
| 535 | classifications:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 536 | |
| 537 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 538 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 539 | <tr><th>Classification</th><th>Types</th></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 540 | <tr> |
| 541 | <td><a name="t_signed">signed</a></td> |
| 542 | <td><tt>sbyte, short, int, long, float, double</tt></td> |
| 543 | </tr> |
| 544 | <tr> |
| 545 | <td><a name="t_unsigned">unsigned</a></td> |
| 546 | <td><tt>ubyte, ushort, uint, ulong</tt></td> |
| 547 | </tr> |
| 548 | <tr> |
| 549 | <td><a name="t_integer">integer</a></td> |
| 550 | <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td> |
| 551 | </tr> |
| 552 | <tr> |
| 553 | <td><a name="t_integral">integral</a></td> |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 554 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt> |
| 555 | </td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 556 | </tr> |
| 557 | <tr> |
| 558 | <td><a name="t_floating">floating point</a></td> |
| 559 | <td><tt>float, double</tt></td> |
| 560 | </tr> |
| 561 | <tr> |
| 562 | <td><a name="t_firstclass">first class</a></td> |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 563 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br> |
| 564 | float, double, <a href="#t_pointer">pointer</a>, |
| 565 | <a href="#t_packed">packed</a></tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 566 | </tr> |
| 567 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 568 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 569 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 570 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the |
| 571 | most important. Values of these types are the only ones which can be |
| 572 | produced by instructions, passed as arguments, or used as operands to |
| 573 | instructions. This means that all structures and arrays must be |
| 574 | manipulated either by pointer or by component.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 575 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 576 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 577 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 578 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 579 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 580 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 581 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 582 | <p>The real power in LLVM comes from the derived types in the system. |
| 583 | This is what allows a programmer to represent arrays, functions, |
| 584 | pointers, and other useful types. Note that these derived types may be |
| 585 | recursive: For example, it is possible to have a two dimensional array.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 586 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 587 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 588 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 589 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 590 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 591 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 592 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 593 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 594 | <h5>Overview:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 595 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 596 | <p>The array type is a very simple derived type that arranges elements |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 597 | sequentially in memory. The array type requires a size (number of |
| 598 | elements) and an underlying data type.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 599 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 600 | <h5>Syntax:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 601 | |
| 602 | <pre> |
| 603 | [<# elements> x <elementtype>] |
| 604 | </pre> |
| 605 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 606 | <p>The number of elements is a constant integer value, elementtype may |
| 607 | be any type with a size.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 608 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 609 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 610 | <table class="layout"> |
| 611 | <tr class="layout"> |
| 612 | <td class="left"> |
| 613 | <tt>[40 x int ]</tt><br/> |
| 614 | <tt>[41 x int ]</tt><br/> |
| 615 | <tt>[40 x uint]</tt><br/> |
| 616 | </td> |
| 617 | <td class="left"> |
| 618 | Array of 40 integer values.<br/> |
| 619 | Array of 41 integer values.<br/> |
| 620 | Array of 40 unsigned integer values.<br/> |
| 621 | </td> |
| 622 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 623 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 624 | <p>Here are some examples of multidimensional arrays:</p> |
| 625 | <table class="layout"> |
| 626 | <tr class="layout"> |
| 627 | <td class="left"> |
| 628 | <tt>[3 x [4 x int]]</tt><br/> |
| 629 | <tt>[12 x [10 x float]]</tt><br/> |
| 630 | <tt>[2 x [3 x [4 x uint]]]</tt><br/> |
| 631 | </td> |
| 632 | <td class="left"> |
| 633 | 3x4 array integer values.<br/> |
| 634 | 12x10 array of single precision floating point values.<br/> |
| 635 | 2x3x4 array of unsigned integer values.<br/> |
| 636 | </td> |
| 637 | </tr> |
| 638 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 639 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 640 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 641 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 642 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 643 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 644 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 645 | <p>The function type can be thought of as a function signature. It |
| 646 | consists of a return type and a list of formal parameter types. |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 647 | Function types are usually used to build virtual function tables |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 648 | (which are structures of pointers to functions), for indirect function |
| 649 | calls, and when defining a function.</p> |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 650 | <p> |
| 651 | The return type of a function type cannot be an aggregate type. |
| 652 | </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 653 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 654 | <pre> <returntype> (<parameter list>)<br></pre> |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 655 | <p>Where '<tt><parameter list></tt>' is a comma-separated list of type |
| 656 | specifiers. Optionally, the parameter list may include a type <tt>...</tt>, |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 657 | which indicates that the function takes a variable number of arguments. |
| 658 | Variable argument functions can access their arguments with the <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 659 | href="#int_varargs">variable argument handling intrinsic</a> functions.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 660 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 661 | <table class="layout"> |
| 662 | <tr class="layout"> |
| 663 | <td class="left"> |
| 664 | <tt>int (int)</tt> <br/> |
| 665 | <tt>float (int, int *) *</tt><br/> |
| 666 | <tt>int (sbyte *, ...)</tt><br/> |
| 667 | </td> |
| 668 | <td class="left"> |
| 669 | function taking an <tt>int</tt>, returning an <tt>int</tt><br/> |
| 670 | <a href="#t_pointer">Pointer</a> to a function that takes an |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 671 | <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>, |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 672 | returning <tt>float</tt>.<br/> |
| 673 | A vararg function that takes at least one <a href="#t_pointer">pointer</a> |
| 674 | to <tt>sbyte</tt> (signed char in C), which returns an integer. This is |
| 675 | the signature for <tt>printf</tt> in LLVM.<br/> |
| 676 | </td> |
| 677 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 678 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 679 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 680 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 681 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 682 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 683 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 684 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 685 | <p>The structure type is used to represent a collection of data members |
| 686 | together in memory. The packing of the field types is defined to match |
| 687 | the ABI of the underlying processor. The elements of a structure may |
| 688 | be any type that has a size.</p> |
| 689 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 690 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 691 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 692 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 693 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 694 | <pre> { <type list> }<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 695 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 696 | <table class="layout"> |
| 697 | <tr class="layout"> |
| 698 | <td class="left"> |
| 699 | <tt>{ int, int, int }</tt><br/> |
| 700 | <tt>{ float, int (int) * }</tt><br/> |
| 701 | </td> |
| 702 | <td class="left"> |
| 703 | a triple of three <tt>int</tt> values<br/> |
| 704 | A pair, where the first element is a <tt>float</tt> and the second element |
| 705 | is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a> |
| 706 | that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/> |
| 707 | </td> |
| 708 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 709 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 710 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 711 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 712 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 713 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 714 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 715 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 716 | <p>As in many languages, the pointer type represents a pointer or |
| 717 | reference to another object, which must live in memory.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 718 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 719 | <pre> <type> *<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 720 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 721 | <table class="layout"> |
| 722 | <tr class="layout"> |
| 723 | <td class="left"> |
| 724 | <tt>[4x int]*</tt><br/> |
| 725 | <tt>int (int *) *</tt><br/> |
| 726 | </td> |
| 727 | <td class="left"> |
| 728 | A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of |
| 729 | four <tt>int</tt> values<br/> |
| 730 | A <a href="#t_pointer">pointer</a> to a <a |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 731 | href="#t_function">function</a> that takes an <tt>int</tt>, returning an |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 732 | <tt>int</tt>.<br/> |
| 733 | </td> |
| 734 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 735 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 736 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 737 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 738 | <!-- _______________________________________________________________________ --> |
| 739 | <div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 740 | <div class="doc_text"> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 741 | <h5>Overview:</h5> |
| 742 | <p>A packed type is a simple derived type that represents a vector |
| 743 | of elements. Packed types are used when multiple primitive data |
| 744 | are operated in parallel using a single instruction (SIMD). |
| 745 | A packed type requires a size (number of |
| 746 | elements) and an underlying primitive data type. Packed types are |
| 747 | considered <a href="#t_firstclass">first class</a>.</p> |
| 748 | <h5>Syntax:</h5> |
| 749 | <pre> < <# elements> x <elementtype> ><br></pre> |
| 750 | <p>The number of elements is a constant integer value, elementtype may |
| 751 | be any integral or floating point type.</p> |
| 752 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 753 | <table class="layout"> |
| 754 | <tr class="layout"> |
| 755 | <td class="left"> |
| 756 | <tt><4 x int></tt><br/> |
| 757 | <tt><8 x float></tt><br/> |
| 758 | <tt><2 x uint></tt><br/> |
| 759 | </td> |
| 760 | <td class="left"> |
| 761 | Packed vector of 4 integer values.<br/> |
| 762 | Packed vector of 8 floating-point values.<br/> |
| 763 | Packed vector of 2 unsigned integer values.<br/> |
| 764 | </td> |
| 765 | </tr> |
| 766 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 767 | </div> |
| 768 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 769 | <!-- *********************************************************************** --> |
| 770 | <div class="doc_section"> <a name="constants">Constants</a> </div> |
| 771 | <!-- *********************************************************************** --> |
| 772 | |
| 773 | <div class="doc_text"> |
| 774 | |
| 775 | <p>LLVM has several different basic types of constants. This section describes |
| 776 | them all and their syntax.</p> |
| 777 | |
| 778 | </div> |
| 779 | |
| 780 | <!-- ======================================================================= --> |
| 781 | <div class="doc_subsection"> <a name="simpleconstants">Simple Constants</a> |
| 782 | </div> |
| 783 | |
| 784 | <div class="doc_text"> |
| 785 | |
| 786 | <dl> |
| 787 | <dt><b>Boolean constants</b></dt> |
| 788 | |
| 789 | <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid |
| 790 | constants of the <tt><a href="#t_primitive">bool</a></tt> type. |
| 791 | </dd> |
| 792 | |
| 793 | <dt><b>Integer constants</b></dt> |
| 794 | |
| 795 | <dd>Standard integers (such as '4') are constants of <a |
| 796 | href="#t_integer">integer</a> type. Negative numbers may be used with signed |
| 797 | integer types. |
| 798 | </dd> |
| 799 | |
| 800 | <dt><b>Floating point constants</b></dt> |
| 801 | |
| 802 | <dd>Floating point constants use standard decimal notation (e.g. 123.421), |
| 803 | exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal |
| 804 | notation. etc. Floating point constants have an optional hexadecimal |
| 805 | notation (see below). Floating point constants must have a <a |
| 806 | href="#t_floating">floating point</a> type. </dd> |
| 807 | |
| 808 | <dt><b>Null pointer constants</b></dt> |
| 809 | |
| 810 | <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant, |
| 811 | and must be of <a href="#t_pointer">pointer type</a>.</dd> |
| 812 | |
| 813 | </dl> |
| 814 | |
| 815 | <p>The one non-intuitive notation for constants is the optional hexidecimal form |
| 816 | of floating point constants. For example, the form '<tt>double |
| 817 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double |
| 818 | 4.5e+15</tt>'. The only time hexadecimal floating point constants are required |
| 819 | (and the only time that they are generated by the disassembler) is when an FP |
| 820 | constant has to be emitted that is not representable as a decimal floating point |
| 821 | number exactly. For example, NaN's, infinities, and other special cases are |
| 822 | represented in their IEEE hexadecimal format so that assembly and disassembly do |
| 823 | not cause any bits to change in the constants.</p> |
| 824 | |
| 825 | </div> |
| 826 | |
| 827 | <!-- ======================================================================= --> |
| 828 | <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a> |
| 829 | </div> |
| 830 | |
| 831 | <div class="doc_text"> |
| 832 | |
| 833 | <dl> |
| 834 | <dt><b>Structure constants</b></dt> |
| 835 | |
| 836 | <dd>Structure constants are represented with notation similar to structure |
| 837 | type definitions (a comma separated list of elements, surrounded by braces |
| 838 | (<tt>{}</tt>). For example: "<tt>{ int 4, float 17.0 }</tt>". Structure |
| 839 | constants must have <a href="#t_struct">structure type</a>, and the number and |
| 840 | types of elements must match those specified by the type. |
| 841 | </dd> |
| 842 | |
| 843 | <dt><b>Array constants</b></dt> |
| 844 | |
| 845 | <dd>Array constants are represented with notation similar to array type |
| 846 | definitions (a comma separated list of elements, surrounded by square brackets |
| 847 | (<tt>[]</tt>). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array |
| 848 | constants must have <a href="#t_array">array type</a>, and the number and |
| 849 | types of elements must match those specified by the type. |
| 850 | </dd> |
| 851 | |
| 852 | <dt><b>Packed constants</b></dt> |
| 853 | |
| 854 | <dd>Packed constants are represented with notation similar to packed type |
| 855 | definitions (a comma separated list of elements, surrounded by |
| 856 | less-than/greater-than's (<tt><></tt>). For example: "<tt>< int 42, |
| 857 | int 11, int 74, int 100 ></tt>". Packed constants must have <a |
| 858 | href="#t_packed">packed type</a>, and the number and types of elements must |
| 859 | match those specified by the type. |
| 860 | </dd> |
| 861 | |
| 862 | <dt><b>Zero initialization</b></dt> |
| 863 | |
| 864 | <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a |
| 865 | value to zero of <em>any</em> type, including scalar and aggregate types. |
| 866 | This is often used to avoid having to print large zero initializers (e.g. for |
| 867 | large arrays), and is always exactly equivalent to using explicit zero |
| 868 | initializers. |
| 869 | </dd> |
| 870 | </dl> |
| 871 | |
| 872 | </div> |
| 873 | |
| 874 | <!-- ======================================================================= --> |
| 875 | <div class="doc_subsection"> |
| 876 | <a name="globalconstants">Global Variable and Function Addresses</a> |
| 877 | </div> |
| 878 | |
| 879 | <div class="doc_text"> |
| 880 | |
| 881 | <p>The addresses of <a href="#globalvars">global variables</a> and <a |
| 882 | href="#functionstructure">functions</a> are always implicitly valid (link-time) |
| 883 | constants. These constants explicitly referenced when the <a |
| 884 | href="#identifiers">identifier for the global</a> is used, and always have <a |
| 885 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM |
| 886 | file:</p> |
| 887 | |
| 888 | <pre> |
| 889 | %X = global int 17 |
| 890 | %Y = global int 42 |
| 891 | %Z = global [2 x int*] [ int* %X, int* %Y ] |
| 892 | </pre> |
| 893 | |
| 894 | </div> |
| 895 | |
| 896 | <!-- ======================================================================= --> |
| 897 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a> |
| 898 | </div> |
| 899 | |
| 900 | <div class="doc_text"> |
| 901 | |
| 902 | <p>The string '<tt>undef</tt>' is recognized as a filler that has no specified |
| 903 | value. Undefined values may be of any type, and be used anywhere a constant |
| 904 | is.</p> |
| 905 | |
| 906 | <p>Undefined values are used to indicate the compiler that the program is well |
| 907 | defined no matter what value is used, giving it more freedom.</p> |
| 908 | |
| 909 | </div> |
| 910 | |
| 911 | <!-- ======================================================================= --> |
| 912 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> |
| 913 | </div> |
| 914 | |
| 915 | <div class="doc_text"> |
| 916 | |
| 917 | <p>Constant expressions are used to allow expressions involving other constants |
| 918 | to be used as constants. Constant expressions may be of any <a |
| 919 | href="#t_firstclass">first class</a> type, and may involve any LLVM operation |
| 920 | that does not have side effects (e.g. load and call are not supported). The |
| 921 | following is the syntax for constant expressions:</p> |
| 922 | |
| 923 | <dl> |
| 924 | <dt><b><tt>cast ( CST to TYPE )</tt></b></dt> |
| 925 | |
| 926 | <dd>Cast a constant to another type.</dd> |
| 927 | |
| 928 | <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> |
| 929 | |
| 930 | <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on |
| 931 | constants. As with the <a href="#i_getelementptr">getelementptr</a> |
| 932 | instruction, the index list may have zero or more indexes, which are required |
| 933 | to make sense for the type of "CSTPTR".</dd> |
| 934 | |
| 935 | <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> |
| 936 | |
| 937 | <dd>Perform the specied operation of the LHS and RHS constants. OPCODE may be |
| 938 | any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise |
| 939 | binary</a> operations. The constraints on operands are the same as those for |
| 940 | the corresponding instruction (e.g. no bitwise operations on floating point |
| 941 | are allowed).</dd> |
| 942 | |
| 943 | </dl> |
| 944 | |
| 945 | </div> |
Chris Lattner | 9ee5d22 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 946 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 947 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 948 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> |
| 949 | <!-- *********************************************************************** --> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 950 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 951 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 952 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 953 | <p>The LLVM instruction set consists of several different |
| 954 | classifications of instructions: <a href="#terminators">terminator |
| 955 | instructions</a>, <a href="#binaryops">binary instructions</a>, <a |
| 956 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other |
| 957 | instructions</a>.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 958 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 959 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 960 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 961 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 962 | <div class="doc_subsection"> <a name="terminators">Terminator |
| 963 | Instructions</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 964 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 965 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 966 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 967 | <p>As mentioned <a href="#functionstructure">previously</a>, every |
| 968 | basic block in a program ends with a "Terminator" instruction, which |
| 969 | indicates which block should be executed after the current block is |
| 970 | finished. These terminator instructions typically yield a '<tt>void</tt>' |
| 971 | value: they produce control flow, not values (the one exception being |
| 972 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 973 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 974 | <p>There are five different terminator instructions: the '<a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 975 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' |
| 976 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 977 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a |
| 978 | href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a |
| 979 | href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 980 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 981 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 982 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 983 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 984 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' |
| 985 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 986 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 987 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 988 | <pre> ret <type> <value> <i>; Return a value from a non-void function</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 989 | ret void <i>; Return from void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 990 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 991 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 992 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and a |
| 993 | value) from a function, back to the caller.</p> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 994 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 995 | returns a value and then causes control flow, and one that just causes |
| 996 | control flow to occur.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 997 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 998 | <p>The '<tt>ret</tt>' instruction may return any '<a |
| 999 | href="#t_firstclass">first class</a>' type. Notice that a function is |
| 1000 | not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>' |
| 1001 | instruction inside of the function that returns a value that does not |
| 1002 | match the return type of the function.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1003 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1004 | <p>When the '<tt>ret</tt>' instruction is executed, control flow |
| 1005 | returns back to the calling function's context. If the caller is a "<a |
John Criswell | fa08187 | 2004-06-25 15:16:57 +0000 | [diff] [blame] | 1006 | href="#i_call"><tt>call</tt></a>" instruction, execution continues at |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1007 | the instruction after the call. If the caller was an "<a |
| 1008 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues |
| 1009 | at the beginning "normal" of the destination block. If the instruction |
| 1010 | returns a value, that value shall set the call or invoke instruction's |
| 1011 | return value.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1012 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1013 | <pre> ret int 5 <i>; Return an integer value of 5</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1014 | ret void <i>; Return from a void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1015 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1016 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1017 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1018 | <div class="doc_subsubsection"> <a name="i_br">'<tt>br</tt>' Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1019 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1020 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1021 | <pre> br bool <cond>, label <iftrue>, label <iffalse><br> br label <dest> <i>; Unconditional branch</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1022 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1023 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1024 | <p>The '<tt>br</tt>' instruction is used to cause control flow to |
| 1025 | transfer to a different basic block in the current function. There are |
| 1026 | two forms of this instruction, corresponding to a conditional branch |
| 1027 | and an unconditional branch.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1028 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1029 | <p>The conditional branch form of the '<tt>br</tt>' instruction takes a |
| 1030 | single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The |
| 1031 | unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' |
| 1032 | value as a target.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1033 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1034 | <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>' |
| 1035 | argument is evaluated. If the value is <tt>true</tt>, control flows |
| 1036 | to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>, |
| 1037 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1038 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1039 | <pre>Test:<br> %cond = <a href="#i_setcc">seteq</a> int %a, %b<br> br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a |
| 1040 | href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1041 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1042 | <!-- _______________________________________________________________________ --> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1043 | <div class="doc_subsubsection"> |
| 1044 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> |
| 1045 | </div> |
| 1046 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1047 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1048 | <h5>Syntax:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1049 | |
| 1050 | <pre> |
| 1051 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] |
| 1052 | </pre> |
| 1053 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1054 | <h5>Overview:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1055 | |
| 1056 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of |
| 1057 | several different places. It is a generalization of the '<tt>br</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1058 | instruction, allowing a branch to occur to one of many possible |
| 1059 | destinations.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1060 | |
| 1061 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1062 | <h5>Arguments:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1063 | |
| 1064 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer |
| 1065 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and |
| 1066 | an array of pairs of comparison value constants and '<tt>label</tt>'s. The |
| 1067 | table is not allowed to contain duplicate constant entries.</p> |
| 1068 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1069 | <h5>Semantics:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1070 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1071 | <p>The <tt>switch</tt> instruction specifies a table of values and |
| 1072 | destinations. When the '<tt>switch</tt>' instruction is executed, this |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1073 | table is searched for the given value. If the value is found, control flow is |
| 1074 | transfered to the corresponding destination; otherwise, control flow is |
| 1075 | transfered to the default destination.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1076 | |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1077 | <h5>Implementation:</h5> |
| 1078 | |
| 1079 | <p>Depending on properties of the target machine and the particular |
| 1080 | <tt>switch</tt> instruction, this instruction may be code generated in different |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1081 | ways. For example, it could be generated as a series of chained conditional |
| 1082 | branches or with a lookup table.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1083 | |
| 1084 | <h5>Example:</h5> |
| 1085 | |
| 1086 | <pre> |
| 1087 | <i>; Emulate a conditional br instruction</i> |
| 1088 | %Val = <a href="#i_cast">cast</a> bool %value to int |
| 1089 | switch int %Val, label %truedest [int 0, label %falsedest ] |
| 1090 | |
| 1091 | <i>; Emulate an unconditional br instruction</i> |
| 1092 | switch uint 0, label %dest [ ] |
| 1093 | |
| 1094 | <i>; Implement a jump table:</i> |
| 1095 | switch uint %val, label %otherwise [ uint 0, label %onzero |
| 1096 | uint 1, label %onone |
| 1097 | uint 2, label %ontwo ] |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1098 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1099 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1100 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1101 | <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>' |
| 1102 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1103 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1104 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1105 | <pre> <result> = invoke <ptr to function ty> %<function ptr val>(<function args>)<br> to label <normal label> except label <exception label><br></pre> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1106 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1107 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a |
| 1108 | specified function, with the possibility of control flow transfer to |
| 1109 | either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>. |
| 1110 | If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>" |
| 1111 | instruction, control flow will return to the "normal" label. If the |
| 1112 | callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>" |
| 1113 | instruction, control is interrupted, and continued at the dynamically |
| 1114 | nearest "except" label.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1115 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1116 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1117 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1118 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the |
| 1119 | pointer to function value being invoked. In most cases, this is a |
| 1120 | direct function invocation, but indirect <tt>invoke</tt>s are just as |
| 1121 | possible, branching off an arbitrary pointer to function value. </li> |
| 1122 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer |
| 1123 | to a function to be invoked. </li> |
| 1124 | <li>'<tt>function args</tt>': argument list whose types match the |
| 1125 | function signature argument types. If the function signature indicates |
| 1126 | the function accepts a variable number of arguments, the extra |
| 1127 | arguments can be specified. </li> |
| 1128 | <li>'<tt>normal label</tt>': the label reached when the called |
| 1129 | function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> |
| 1130 | <li>'<tt>exception label</tt>': the label reached when a callee |
| 1131 | returns with the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1132 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1133 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1134 | <p>This instruction is designed to operate as a standard '<tt><a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1135 | href="#i_call">call</a></tt>' instruction in most regards. The |
| 1136 | primary difference is that it establishes an association with a label, |
| 1137 | which is used by the runtime library to unwind the stack.</p> |
| 1138 | <p>This instruction is used in languages with destructors to ensure |
| 1139 | that proper cleanup is performed in the case of either a <tt>longjmp</tt> |
| 1140 | or a thrown exception. Additionally, this is important for |
| 1141 | implementation of '<tt>catch</tt>' clauses in high-level languages that |
| 1142 | support them.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1143 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1144 | <pre> %retval = invoke int %Test(int 15)<br> to label %Continue<br> except label %TestCleanup <i>; {int}:retval set</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1145 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1146 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1147 | |
| 1148 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1149 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1150 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1151 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' |
| 1152 | Instruction</a> </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1153 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1154 | <div class="doc_text"> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1155 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1156 | <h5>Syntax:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1157 | <pre> |
| 1158 | unwind |
| 1159 | </pre> |
| 1160 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1161 | <h5>Overview:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1162 | |
| 1163 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow |
| 1164 | at the first callee in the dynamic call stack which used an <a |
| 1165 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is |
| 1166 | primarily used to implement exception handling.</p> |
| 1167 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1168 | <h5>Semantics:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1169 | |
| 1170 | <p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to |
| 1171 | immediately halt. The dynamic call stack is then searched for the first <a |
| 1172 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found, |
| 1173 | execution continues at the "exceptional" destination block specified by the |
| 1174 | <tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the |
| 1175 | dynamic call chain, undefined behavior results.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1176 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1177 | |
| 1178 | <!-- _______________________________________________________________________ --> |
| 1179 | |
| 1180 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' |
| 1181 | Instruction</a> </div> |
| 1182 | |
| 1183 | <div class="doc_text"> |
| 1184 | |
| 1185 | <h5>Syntax:</h5> |
| 1186 | <pre> |
| 1187 | unreachable |
| 1188 | </pre> |
| 1189 | |
| 1190 | <h5>Overview:</h5> |
| 1191 | |
| 1192 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics. This |
| 1193 | instruction is used to inform the optimizer that a particular portion of the |
| 1194 | code is not reachable. This can be used to indicate that the code after a |
| 1195 | no-return function cannot be reached, and other facts.</p> |
| 1196 | |
| 1197 | <h5>Semantics:</h5> |
| 1198 | |
| 1199 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> |
| 1200 | </div> |
| 1201 | |
| 1202 | |
| 1203 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1204 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1205 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1206 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1207 | <p>Binary operators are used to do most of the computation in a |
| 1208 | program. They require two operands, execute an operation on them, and |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1209 | produce a single value. Although, that single value might represent |
| 1210 | multiple data, as is the case with the <a href="#t_packed">packed</a> data type. |
| 1211 | The result value of a binary operator is not |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1212 | necessarily the same type as its operands.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1213 | <p>There are several different binary operators:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1214 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1215 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1216 | <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>' |
| 1217 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1218 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1219 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1220 | <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1221 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1222 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1223 | <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1224 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1225 | <p>The two arguments to the '<tt>add</tt>' instruction must be either <a |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1226 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values. |
| 1227 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1228 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1229 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1230 | <p>The value produced is the integer or floating point sum of the two |
| 1231 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1232 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1233 | <pre> <result> = add int 4, %var <i>; yields {int}:result = 4 + %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1234 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1235 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1236 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1237 | <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>' |
| 1238 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1239 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1240 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1241 | <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1242 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1243 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1244 | <p>The '<tt>sub</tt>' instruction returns the difference of its two |
| 1245 | operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1246 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>' |
| 1247 | instruction present in most other intermediate representations.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1248 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1249 | <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1250 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1251 | values. |
| 1252 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1253 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1254 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1255 | <p>The value produced is the integer or floating point difference of |
| 1256 | the two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1257 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1258 | <pre> <result> = sub int 4, %var <i>; yields {int}:result = 4 - %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1259 | <result> = sub int 0, %val <i>; yields {int}:result = -%var</i> |
| 1260 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1261 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1262 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1263 | <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>' |
| 1264 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1265 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1266 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1267 | <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1268 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1269 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1270 | <p>The '<tt>mul</tt>' instruction returns the product of its two |
| 1271 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1272 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1273 | <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1274 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1275 | values. |
| 1276 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1277 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1278 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1279 | <p>The value produced is the integer or floating point product of the |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1280 | two operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1281 | <p>There is no signed vs unsigned multiplication. The appropriate |
| 1282 | action is taken based on the type of the operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1283 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1284 | <pre> <result> = mul int 4, %var <i>; yields {int}:result = 4 * %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1285 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1286 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1287 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1288 | <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>' |
| 1289 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1290 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1291 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1292 | <pre> <result> = div <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1293 | </pre> |
| 1294 | <h5>Overview:</h5> |
| 1295 | <p>The '<tt>div</tt>' instruction returns the quotient of its two |
| 1296 | operands.</p> |
| 1297 | <h5>Arguments:</h5> |
| 1298 | <p>The two arguments to the '<tt>div</tt>' instruction must be either <a |
| 1299 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1300 | values. |
| 1301 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1302 | Both arguments must have identical types.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1303 | <h5>Semantics:</h5> |
| 1304 | <p>The value produced is the integer or floating point quotient of the |
| 1305 | two operands.</p> |
| 1306 | <h5>Example:</h5> |
| 1307 | <pre> <result> = div int 4, %var <i>; yields {int}:result = 4 / %var</i> |
| 1308 | </pre> |
| 1309 | </div> |
| 1310 | <!-- _______________________________________________________________________ --> |
| 1311 | <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>' |
| 1312 | Instruction</a> </div> |
| 1313 | <div class="doc_text"> |
| 1314 | <h5>Syntax:</h5> |
| 1315 | <pre> <result> = rem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1316 | </pre> |
| 1317 | <h5>Overview:</h5> |
| 1318 | <p>The '<tt>rem</tt>' instruction returns the remainder from the |
| 1319 | division of its two operands.</p> |
| 1320 | <h5>Arguments:</h5> |
| 1321 | <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a |
| 1322 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1323 | values. |
| 1324 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1325 | Both arguments must have identical types.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1326 | <h5>Semantics:</h5> |
| 1327 | <p>This returns the <i>remainder</i> of a division (where the result |
| 1328 | has the same sign as the divisor), not the <i>modulus</i> (where the |
| 1329 | result has the same sign as the dividend) of a value. For more |
| 1330 | information about the difference, see: <a |
| 1331 | href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The |
| 1332 | Math Forum</a>.</p> |
| 1333 | <h5>Example:</h5> |
| 1334 | <pre> <result> = rem int 4, %var <i>; yields {int}:result = 4 % %var</i> |
| 1335 | </pre> |
| 1336 | </div> |
| 1337 | <!-- _______________________________________________________________________ --> |
| 1338 | <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>' |
| 1339 | Instructions</a> </div> |
| 1340 | <div class="doc_text"> |
| 1341 | <h5>Syntax:</h5> |
| 1342 | <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1343 | <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1344 | <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1345 | <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1346 | <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1347 | <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1348 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1349 | <h5>Overview:</h5> |
| 1350 | <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean |
| 1351 | value based on a comparison of their two operands.</p> |
| 1352 | <h5>Arguments:</h5> |
| 1353 | <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must |
| 1354 | be of <a href="#t_firstclass">first class</a> type (it is not possible |
| 1355 | to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' |
| 1356 | or '<tt>void</tt>' values, etc...). Both arguments must have identical |
| 1357 | types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1358 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1359 | <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1360 | value if both operands are equal.<br> |
| 1361 | The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1362 | value if both operands are unequal.<br> |
| 1363 | The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1364 | value if the first operand is less than the second operand.<br> |
| 1365 | The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1366 | value if the first operand is greater than the second operand.<br> |
| 1367 | The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1368 | value if the first operand is less than or equal to the second operand.<br> |
| 1369 | The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1370 | value if the first operand is greater than or equal to the second |
| 1371 | operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1372 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1373 | <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1374 | <result> = setne float 4, 5 <i>; yields {bool}:result = true</i> |
| 1375 | <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i> |
| 1376 | <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1377 | <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i> |
| 1378 | <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1379 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1380 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1381 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1382 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary |
| 1383 | Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1384 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1385 | <p>Bitwise binary operators are used to do various forms of |
| 1386 | bit-twiddling in a program. They are generally very efficient |
| 1387 | instructions, and can commonly be strength reduced from other |
| 1388 | instructions. They require two operands, execute an operation on them, |
| 1389 | and produce a single value. The resulting value of the bitwise binary |
| 1390 | operators is always the same type as its first operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1391 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1392 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1393 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' |
| 1394 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1395 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1396 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1397 | <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1398 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1399 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1400 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of |
| 1401 | its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1402 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1403 | <p>The two arguments to the '<tt>and</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1404 | href="#t_integral">integral</a> values. Both arguments must have |
| 1405 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1406 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1407 | <p>The truth table used for the '<tt>and</tt>' instruction is:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1408 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1409 | <div style="align: center"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1410 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1411 | <tbody> |
| 1412 | <tr> |
| 1413 | <td>In0</td> |
| 1414 | <td>In1</td> |
| 1415 | <td>Out</td> |
| 1416 | </tr> |
| 1417 | <tr> |
| 1418 | <td>0</td> |
| 1419 | <td>0</td> |
| 1420 | <td>0</td> |
| 1421 | </tr> |
| 1422 | <tr> |
| 1423 | <td>0</td> |
| 1424 | <td>1</td> |
| 1425 | <td>0</td> |
| 1426 | </tr> |
| 1427 | <tr> |
| 1428 | <td>1</td> |
| 1429 | <td>0</td> |
| 1430 | <td>0</td> |
| 1431 | </tr> |
| 1432 | <tr> |
| 1433 | <td>1</td> |
| 1434 | <td>1</td> |
| 1435 | <td>1</td> |
| 1436 | </tr> |
| 1437 | </tbody> |
| 1438 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1439 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1440 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1441 | <pre> <result> = and int 4, %var <i>; yields {int}:result = 4 & %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1442 | <result> = and int 15, 40 <i>; yields {int}:result = 8</i> |
| 1443 | <result> = and int 4, 8 <i>; yields {int}:result = 0</i> |
| 1444 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1445 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1446 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1447 | <div class="doc_subsubsection"> <a name="i_or">'<tt>or</tt>' Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1448 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1449 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1450 | <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1451 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1452 | <h5>Overview:</h5> |
| 1453 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive |
| 1454 | or of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1455 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1456 | <p>The two arguments to the '<tt>or</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1457 | href="#t_integral">integral</a> values. Both arguments must have |
| 1458 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1459 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1460 | <p>The truth table used for the '<tt>or</tt>' instruction is:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1461 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1462 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1463 | <table border="1" cellspacing="0" cellpadding="4"> |
| 1464 | <tbody> |
| 1465 | <tr> |
| 1466 | <td>In0</td> |
| 1467 | <td>In1</td> |
| 1468 | <td>Out</td> |
| 1469 | </tr> |
| 1470 | <tr> |
| 1471 | <td>0</td> |
| 1472 | <td>0</td> |
| 1473 | <td>0</td> |
| 1474 | </tr> |
| 1475 | <tr> |
| 1476 | <td>0</td> |
| 1477 | <td>1</td> |
| 1478 | <td>1</td> |
| 1479 | </tr> |
| 1480 | <tr> |
| 1481 | <td>1</td> |
| 1482 | <td>0</td> |
| 1483 | <td>1</td> |
| 1484 | </tr> |
| 1485 | <tr> |
| 1486 | <td>1</td> |
| 1487 | <td>1</td> |
| 1488 | <td>1</td> |
| 1489 | </tr> |
| 1490 | </tbody> |
| 1491 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1492 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1493 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1494 | <pre> <result> = or int 4, %var <i>; yields {int}:result = 4 | %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1495 | <result> = or int 15, 40 <i>; yields {int}:result = 47</i> |
| 1496 | <result> = or int 4, 8 <i>; yields {int}:result = 12</i> |
| 1497 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1498 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1499 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1500 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' |
| 1501 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1502 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1503 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1504 | <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1505 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1506 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1507 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive |
| 1508 | or of its two operands. The <tt>xor</tt> is used to implement the |
| 1509 | "one's complement" operation, which is the "~" operator in C.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1510 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1511 | <p>The two arguments to the '<tt>xor</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1512 | href="#t_integral">integral</a> values. Both arguments must have |
| 1513 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1514 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1515 | <p>The truth table used for the '<tt>xor</tt>' instruction is:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1516 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1517 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1518 | <table border="1" cellspacing="0" cellpadding="4"> |
| 1519 | <tbody> |
| 1520 | <tr> |
| 1521 | <td>In0</td> |
| 1522 | <td>In1</td> |
| 1523 | <td>Out</td> |
| 1524 | </tr> |
| 1525 | <tr> |
| 1526 | <td>0</td> |
| 1527 | <td>0</td> |
| 1528 | <td>0</td> |
| 1529 | </tr> |
| 1530 | <tr> |
| 1531 | <td>0</td> |
| 1532 | <td>1</td> |
| 1533 | <td>1</td> |
| 1534 | </tr> |
| 1535 | <tr> |
| 1536 | <td>1</td> |
| 1537 | <td>0</td> |
| 1538 | <td>1</td> |
| 1539 | </tr> |
| 1540 | <tr> |
| 1541 | <td>1</td> |
| 1542 | <td>1</td> |
| 1543 | <td>0</td> |
| 1544 | </tr> |
| 1545 | </tbody> |
| 1546 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1547 | </div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1548 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1549 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1550 | <pre> <result> = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1551 | <result> = xor int 15, 40 <i>; yields {int}:result = 39</i> |
| 1552 | <result> = xor int 4, 8 <i>; yields {int}:result = 12</i> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1553 | <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1554 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1555 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1556 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1557 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' |
| 1558 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1559 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1560 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1561 | <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1562 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1563 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1564 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to |
| 1565 | the left a specified number of bits.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1566 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1567 | <p>The first argument to the '<tt>shl</tt>' instruction must be an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1568 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' |
| 1569 | type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1570 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1571 | <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1572 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1573 | <pre> <result> = shl int 4, ubyte %var <i>; yields {int}:result = 4 << %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1574 | <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i> |
| 1575 | <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i> |
| 1576 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1577 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1578 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1579 | <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>' |
| 1580 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1581 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1582 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1583 | <pre> <result> = shr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1584 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1585 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1586 | <p>The '<tt>shr</tt>' instruction returns the first operand shifted to |
| 1587 | the right a specified number of bits.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1588 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1589 | <p>The first argument to the '<tt>shr</tt>' instruction must be an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1590 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' |
| 1591 | type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1592 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1593 | <p>If the first argument is a <a href="#t_signed">signed</a> type, the |
| 1594 | most significant bit is duplicated in the newly free'd bit positions. |
| 1595 | If the first argument is unsigned, zero bits shall fill the empty |
| 1596 | positions.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1597 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1598 | <pre> <result> = shr int 4, ubyte %var <i>; yields {int}:result = 4 >> %var</i> |
Chris Lattner | 8c6bb90 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1599 | <result> = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1600 | <result> = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i> |
Chris Lattner | 8c6bb90 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1601 | <result> = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i> |
| 1602 | <result> = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1603 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1604 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1605 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1606 | <div class="doc_subsection"> <a name="memoryops">Memory Access |
| 1607 | Operations</a></div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1608 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1609 | <p>A key design point of an SSA-based representation is how it |
| 1610 | represents memory. In LLVM, no memory locations are in SSA form, which |
| 1611 | makes things very simple. This section describes how to read, write, |
| 1612 | allocate and free memory in LLVM.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1613 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1614 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1615 | <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>' |
| 1616 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1617 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1618 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1619 | <pre> <result> = malloc <type>, uint <NumElements> <i>; yields {type*}:result</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1620 | <result> = malloc <type> <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1621 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1622 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1623 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system |
| 1624 | heap and returns a pointer to it.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1625 | <h5>Arguments:</h5> |
John Criswell | 6e4ca61 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 1626 | <p>The '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
| 1627 | bytes of memory from the operating system and returns a pointer of the |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1628 | appropriate type to the program. The second form of the instruction is |
| 1629 | a shorter version of the first instruction that defaults to allocating |
| 1630 | one element.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1631 | <p>'<tt>type</tt>' must be a sized type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1632 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1633 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and |
| 1634 | a pointer is returned.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1635 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1636 | <pre> %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1637 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1638 | %size = <a |
| 1639 | href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1640 | %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i> |
| 1641 | %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1642 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1643 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1644 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1645 | <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>' |
| 1646 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1647 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1648 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1649 | <pre> free <type> <value> <i>; yields {void}</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1650 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1651 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1652 | <p>The '<tt>free</tt>' instruction returns memory back to the unused |
| 1653 | memory heap, to be reallocated in the future.</p> |
| 1654 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1655 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1656 | <p>'<tt>value</tt>' shall be a pointer value that points to a value |
| 1657 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' |
| 1658 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1659 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1660 | <p>Access to the memory pointed to by the pointer is not longer defined |
| 1661 | after this instruction executes.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1662 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1663 | <pre> %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1664 | free [4 x ubyte]* %array |
| 1665 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1666 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1667 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1668 | <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>' |
| 1669 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1670 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1671 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1672 | <pre> <result> = alloca <type>, uint <NumElements> <i>; yields {type*}:result</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1673 | <result> = alloca <type> <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1674 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1675 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1676 | <p>The '<tt>alloca</tt>' instruction allocates memory on the current |
| 1677 | stack frame of the procedure that is live until the current function |
| 1678 | returns to its caller.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1679 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1680 | <p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
| 1681 | bytes of memory on the runtime stack, returning a pointer of the |
| 1682 | appropriate type to the program. The second form of the instruction is |
| 1683 | a shorter version of the first that defaults to allocating one element.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1684 | <p>'<tt>type</tt>' may be any sized type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1685 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1686 | <p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d |
| 1687 | memory is automatically released when the function returns. The '<tt>alloca</tt>' |
| 1688 | instruction is commonly used to represent automatic variables that must |
| 1689 | have an address available. When the function returns (either with the <tt><a |
| 1690 | href="#i_ret">ret</a></tt> or <tt><a href="#i_invoke">invoke</a></tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1691 | instructions), the memory is reclaimed.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1692 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1693 | <pre> %ptr = alloca int <i>; yields {int*}:ptr</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1694 | %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1695 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1696 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1697 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1698 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' |
| 1699 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1700 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1701 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1702 | <pre> <result> = load <ty>* <pointer><br> <result> = volatile load <ty>* <pointer><br></pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1703 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1704 | <p>The '<tt>load</tt>' instruction is used to read from memory.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1705 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1706 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory |
| 1707 | address to load from. The pointer must point to a <a |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 1708 | href="#t_firstclass">first class</a> type. If the <tt>load</tt> is |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1709 | marked as <tt>volatile</tt> then the optimizer is not allowed to modify |
| 1710 | the number or order of execution of this <tt>load</tt> with other |
| 1711 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> |
| 1712 | instructions. </p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1713 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1714 | <p>The location of memory pointed to is loaded.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1715 | <h5>Examples:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1716 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 1717 | <a |
| 1718 | href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1719 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 1720 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1721 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1722 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1723 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' |
| 1724 | Instruction</a> </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1725 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1726 | <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | f065107 | 2003-09-08 18:27:49 +0000 | [diff] [blame] | 1727 | volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1728 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1729 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1730 | <p>The '<tt>store</tt>' instruction is used to write to memory.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1731 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1732 | <p>There are two arguments to the '<tt>store</tt>' instruction: a value |
| 1733 | to store and an address to store it into. The type of the '<tt><pointer></tt>' |
| 1734 | operand must be a pointer to the type of the '<tt><value></tt>' |
| 1735 | operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the |
| 1736 | optimizer is not allowed to modify the number or order of execution of |
| 1737 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a |
| 1738 | href="#i_store">store</a></tt> instructions.</p> |
| 1739 | <h5>Semantics:</h5> |
| 1740 | <p>The contents of memory are updated to contain '<tt><value></tt>' |
| 1741 | at the location specified by the '<tt><pointer></tt>' operand.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1742 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1743 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 1744 | <a |
| 1745 | href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1746 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 1747 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1748 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1749 | <div class="doc_subsubsection"> |
| 1750 | <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> |
| 1751 | </div> |
| 1752 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1753 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1754 | <h5>Syntax:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1755 | <pre> |
| 1756 | <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}* |
| 1757 | </pre> |
| 1758 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1759 | <h5>Overview:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1760 | |
| 1761 | <p> |
| 1762 | The '<tt>getelementptr</tt>' instruction is used to get the address of a |
| 1763 | subelement of an aggregate data structure.</p> |
| 1764 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1765 | <h5>Arguments:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1766 | |
| 1767 | <p>This instruction takes a list of integer constants that indicate what |
| 1768 | elements of the aggregate object to index to. The actual types of the arguments |
| 1769 | provided depend on the type of the first pointer argument. The |
| 1770 | '<tt>getelementptr</tt>' instruction is used to index down through the type |
| 1771 | levels of a structure. When indexing into a structure, only <tt>uint</tt> |
| 1772 | integer constants are allowed. When indexing into an array or pointer |
| 1773 | <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p> |
| 1774 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1775 | <p>For example, let's consider a C code fragment and how it gets |
| 1776 | compiled to LLVM:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1777 | |
| 1778 | <pre> |
| 1779 | struct RT { |
| 1780 | char A; |
| 1781 | int B[10][20]; |
| 1782 | char C; |
| 1783 | }; |
| 1784 | struct ST { |
| 1785 | int X; |
| 1786 | double Y; |
| 1787 | struct RT Z; |
| 1788 | }; |
| 1789 | |
| 1790 | int *foo(struct ST *s) { |
| 1791 | return &s[1].Z.B[5][13]; |
| 1792 | } |
| 1793 | </pre> |
| 1794 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1795 | <p>The LLVM code generated by the GCC frontend is:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1796 | |
| 1797 | <pre> |
| 1798 | %RT = type { sbyte, [10 x [20 x int]], sbyte } |
| 1799 | %ST = type { int, double, %RT } |
| 1800 | |
Brian Gaeke | 7283e7c | 2004-07-02 21:08:14 +0000 | [diff] [blame] | 1801 | implementation |
| 1802 | |
| 1803 | int* %foo(%ST* %s) { |
| 1804 | entry: |
| 1805 | %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1806 | ret int* %reg |
| 1807 | } |
| 1808 | </pre> |
| 1809 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1810 | <h5>Semantics:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1811 | |
| 1812 | <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 1813 | on the pointer type that is being index into. <a href="#t_pointer">Pointer</a> |
| 1814 | and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>, |
| 1815 | <tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1816 | types require <tt>uint</tt> <b>constants</b>.</p> |
| 1817 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1818 | <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>' |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1819 | type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT |
| 1820 | }</tt>' type, a structure. The second index indexes into the third element of |
| 1821 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]], |
| 1822 | sbyte }</tt>' type, another structure. The third index indexes into the second |
| 1823 | element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an |
| 1824 | array. The two dimensions of the array are subscripted into, yielding an |
| 1825 | '<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction return a pointer |
| 1826 | to this element, thus computing a value of '<tt>int*</tt>' type.</p> |
| 1827 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1828 | <p>Note that it is perfectly legal to index partially through a |
| 1829 | structure, returning a pointer to an inner element. Because of this, |
| 1830 | the LLVM code for the given testcase is equivalent to:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1831 | |
| 1832 | <pre> |
| 1833 | int* "foo"(%ST* %s) { |
| 1834 | %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i> |
| 1835 | %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i> |
| 1836 | %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i> |
| 1837 | %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i> |
| 1838 | %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i> |
| 1839 | ret int* %t5 |
| 1840 | } |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1841 | </pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1842 | <h5>Example:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 1843 | <pre> |
| 1844 | <i>; yields [12 x ubyte]*:aptr</i> |
| 1845 | %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1 |
| 1846 | </pre> |
| 1847 | |
| 1848 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1849 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1850 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1851 | <div class="doc_text"> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 1852 | <p>The instructions in this category are the "miscellaneous" |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1853 | instructions, which defy better classification.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1854 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1855 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1856 | <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>' |
| 1857 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1858 | <div class="doc_text"> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1859 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1860 | <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1861 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1862 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in |
| 1863 | the SSA graph representing the function.</p> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1864 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1865 | <p>The type of the incoming values are specified with the first type |
| 1866 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs |
| 1867 | as arguments, with one pair for each predecessor basic block of the |
| 1868 | current block. Only values of <a href="#t_firstclass">first class</a> |
| 1869 | type may be used as the value arguments to the PHI node. Only labels |
| 1870 | may be used as the label arguments.</p> |
| 1871 | <p>There must be no non-phi instructions between the start of a basic |
| 1872 | block and the PHI instructions: i.e. PHI instructions must be first in |
| 1873 | a basic block.</p> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1874 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1875 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the |
| 1876 | value specified by the parameter, depending on which basic block we |
| 1877 | came from in the last <a href="#terminators">terminator</a> instruction.</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1878 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1879 | <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> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1880 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1881 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1882 | <!-- _______________________________________________________________________ --> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1883 | <div class="doc_subsubsection"> |
| 1884 | <a name="i_cast">'<tt>cast .. to</tt>' Instruction</a> |
| 1885 | </div> |
| 1886 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1887 | <div class="doc_text"> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1888 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1889 | <h5>Syntax:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1890 | |
| 1891 | <pre> |
| 1892 | <result> = cast <ty> <value> to <ty2> <i>; yields ty2</i> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1893 | </pre> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1894 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1895 | <h5>Overview:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1896 | |
| 1897 | <p> |
| 1898 | The '<tt>cast</tt>' instruction is used as the primitive means to convert |
| 1899 | integers to floating point, change data type sizes, and break type safety (by |
| 1900 | casting pointers). |
| 1901 | </p> |
| 1902 | |
| 1903 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1904 | <h5>Arguments:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1905 | |
| 1906 | <p> |
| 1907 | The '<tt>cast</tt>' instruction takes a value to cast, which must be a first |
| 1908 | class value, and a type to cast it to, which must also be a <a |
| 1909 | href="#t_firstclass">first class</a> type. |
| 1910 | </p> |
| 1911 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1912 | <h5>Semantics:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1913 | |
| 1914 | <p> |
| 1915 | This instruction follows the C rules for explicit casts when determining how the |
| 1916 | data being cast must change to fit in its new container. |
| 1917 | </p> |
| 1918 | |
| 1919 | <p> |
| 1920 | When casting to bool, any value that would be considered true in the context of |
| 1921 | a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' values, |
| 1922 | all else are '<tt>false</tt>'. |
| 1923 | </p> |
| 1924 | |
| 1925 | <p> |
| 1926 | When extending an integral value from a type of one signness to another (for |
| 1927 | example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value is sign-extended if the |
| 1928 | <b>source</b> value is signed, and zero-extended if the source value is |
| 1929 | unsigned. <tt>bool</tt> values are always zero extended into either zero or |
| 1930 | one. |
| 1931 | </p> |
| 1932 | |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1933 | <h5>Example:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1934 | |
| 1935 | <pre> |
| 1936 | %X = cast int 257 to ubyte <i>; yields ubyte:1</i> |
Chris Lattner | 7bae395 | 2002-06-25 18:03:17 +0000 | [diff] [blame] | 1937 | %Y = cast int 123 to bool <i>; yields bool:true</i> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1938 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1939 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 1940 | |
| 1941 | <!-- _______________________________________________________________________ --> |
| 1942 | <div class="doc_subsubsection"> |
| 1943 | <a name="i_select">'<tt>select</tt>' Instruction</a> |
| 1944 | </div> |
| 1945 | |
| 1946 | <div class="doc_text"> |
| 1947 | |
| 1948 | <h5>Syntax:</h5> |
| 1949 | |
| 1950 | <pre> |
| 1951 | <result> = select bool <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i> |
| 1952 | </pre> |
| 1953 | |
| 1954 | <h5>Overview:</h5> |
| 1955 | |
| 1956 | <p> |
| 1957 | The '<tt>select</tt>' instruction is used to choose one value based on a |
| 1958 | condition, without branching. |
| 1959 | </p> |
| 1960 | |
| 1961 | |
| 1962 | <h5>Arguments:</h5> |
| 1963 | |
| 1964 | <p> |
| 1965 | The '<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. |
| 1966 | </p> |
| 1967 | |
| 1968 | <h5>Semantics:</h5> |
| 1969 | |
| 1970 | <p> |
| 1971 | If the boolean condition evaluates to true, the instruction returns the first |
| 1972 | value argument, otherwise it returns the second value argument. |
| 1973 | </p> |
| 1974 | |
| 1975 | <h5>Example:</h5> |
| 1976 | |
| 1977 | <pre> |
| 1978 | %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i> |
| 1979 | </pre> |
| 1980 | </div> |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1986 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1987 | <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>' |
| 1988 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1989 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1990 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1991 | <pre> <result> = call <ty>* <fnptrval>(<param list>)<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1992 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1993 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1994 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1995 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1996 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1997 | <li> |
| 1998 | <p>'<tt>ty</tt>': shall be the signature of the pointer to function |
| 1999 | value being invoked. The argument types must match the types implied |
| 2000 | by this signature.</p> |
| 2001 | </li> |
| 2002 | <li> |
| 2003 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a |
| 2004 | function to be invoked. In most cases, this is a direct function |
| 2005 | invocation, but indirect <tt>call</tt>s are just as possible, |
| 2006 | calling an arbitrary pointer to function values.</p> |
| 2007 | </li> |
| 2008 | <li> |
| 2009 | <p>'<tt>function args</tt>': argument list whose types match the |
| 2010 | function signature argument types. If the function signature |
| 2011 | indicates the function accepts a variable number of arguments, the |
| 2012 | extra arguments can be specified.</p> |
| 2013 | </li> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2014 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2015 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2016 | <p>The '<tt>call</tt>' instruction is used to cause control flow to |
| 2017 | transfer to a specified function, with its incoming arguments bound to |
| 2018 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' |
| 2019 | instruction in the called function, control flow continues with the |
| 2020 | instruction after the function call, and the return value of the |
| 2021 | function is bound to the result argument. This is a simpler case of |
| 2022 | the <a href="#i_invoke">invoke</a> instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2023 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2024 | <pre> %retval = call int %test(int %argc)<br> call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42);<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2025 | </div> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2026 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2027 | <!-- _______________________________________________________________________ --> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2028 | <div class="doc_subsubsection"> |
| 2029 | <a name="i_vanext">'<tt>vanext</tt>' Instruction</a> |
| 2030 | </div> |
| 2031 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2032 | <div class="doc_text"> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2033 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2034 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2035 | |
| 2036 | <pre> |
| 2037 | <resultarglist> = vanext <va_list> <arglist>, <argty> |
| 2038 | </pre> |
| 2039 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2040 | <h5>Overview:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2041 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2042 | <p>The '<tt>vanext</tt>' instruction is used to access arguments passed |
| 2043 | through the "variable argument" area of a function call. It is used to |
| 2044 | implement the <tt>va_arg</tt> macro in C.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2045 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2046 | <h5>Arguments:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2047 | |
| 2048 | <p>This instruction takes a <tt>va_list</tt> value and the type of the |
| 2049 | argument. It returns another <tt>va_list</tt>. The actual type of |
| 2050 | <tt>va_list</tt> may be defined differently for different targets. Most targets |
| 2051 | use a <tt>va_list</tt> type of <tt>sbyte*</tt> or some other pointer type.</p> |
| 2052 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2053 | <h5>Semantics:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2054 | |
| 2055 | <p>The '<tt>vanext</tt>' instruction advances the specified <tt>va_list</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2056 | past an argument of the specified type. In conjunction with the <a |
| 2057 | href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement |
| 2058 | the <tt>va_arg</tt> macro available in C. For more information, see |
| 2059 | the variable argument handling <a href="#int_varargs">Intrinsic |
| 2060 | Functions</a>.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2061 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2062 | <p>It is legal for this instruction to be called in a function which |
| 2063 | does not take a variable number of arguments, for example, the <tt>vfprintf</tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2064 | function.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2065 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2066 | <p><tt>vanext</tt> is an LLVM instruction instead of an <a |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2067 | href="#intrinsics">intrinsic function</a> because it takes a type as an |
| 2068 | argument. The type refers to the current argument in the <tt>va_list</tt>, it |
| 2069 | tells the compiler how far on the stack it needs to advance to find the next |
| 2070 | argument</p> |
| 2071 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2072 | <h5>Example:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2073 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2074 | <p>See the <a href="#int_varargs">variable argument processing</a> |
| 2075 | section.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2076 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2077 | </div> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2078 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2079 | <!-- _______________________________________________________________________ --> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2080 | <div class="doc_subsubsection"> |
| 2081 | <a name="i_vaarg">'<tt>vaarg</tt>' Instruction</a> |
| 2082 | </div> |
| 2083 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2084 | <div class="doc_text"> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2085 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2086 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2087 | |
| 2088 | <pre> |
| 2089 | <resultval> = vaarg <va_list> <arglist>, <argty> |
| 2090 | </pre> |
| 2091 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2092 | <h5>Overview:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2093 | |
| 2094 | <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed through |
| 2095 | the "variable argument" area of a function call. It is used to implement the |
| 2096 | <tt>va_arg</tt> macro in C.</p> |
| 2097 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2098 | <h5>Arguments:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2099 | |
| 2100 | <p>This instruction takes a <tt>va_list</tt> value and the type of the |
| 2101 | argument. It returns a value of the specified argument type. Again, the actual |
| 2102 | type of <tt>va_list</tt> is target specific.</p> |
| 2103 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2104 | <h5>Semantics:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2105 | |
| 2106 | <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified type from |
| 2107 | the specified <tt>va_list</tt>. In conjunction with the <a |
| 2108 | href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to implement the |
| 2109 | <tt>va_arg</tt> macro available in C. For more information, see the variable |
| 2110 | argument handling <a href="#int_varargs">Intrinsic Functions</a>.</p> |
| 2111 | |
| 2112 | <p>It is legal for this instruction to be called in a function which does not |
| 2113 | take a variable number of arguments, for example, the <tt>vfprintf</tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2114 | function.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2115 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2116 | <p><tt>vaarg</tt> is an LLVM instruction instead of an <a |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2117 | href="#intrinsics">intrinsic function</a> because it takes an type as an |
| 2118 | argument.</p> |
| 2119 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 2120 | <h5>Example:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2121 | |
| 2122 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> |
| 2123 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2124 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2125 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2126 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2127 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> |
| 2128 | <!-- *********************************************************************** --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2129 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2130 | <div class="doc_text"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2131 | |
| 2132 | <p>LLVM supports the notion of an "intrinsic function". These functions have |
| 2133 | well known names and semantics, and are required to follow certain |
| 2134 | restrictions. Overall, these instructions represent an extension mechanism for |
| 2135 | the LLVM language that does not require changing all of the transformations in |
| 2136 | LLVM to add to the language (or the bytecode reader/writer, the parser, |
| 2137 | etc...).</p> |
| 2138 | |
| 2139 | <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this |
| 2140 | prefix is reserved in LLVM for intrinsic names, thus functions may not be named |
| 2141 | this. Intrinsic functions must always be external functions: you cannot define |
| 2142 | the body of intrinsic functions. Intrinsic functions may only be used in call |
| 2143 | or invoke instructions: it is illegal to take the address of an intrinsic |
| 2144 | function. Additionally, because intrinsic functions are part of the LLVM |
| 2145 | language, it is required that they all be documented here if any are added.</p> |
| 2146 | |
| 2147 | |
| 2148 | <p> |
| 2149 | Adding an intrinsic to LLVM is straight-forward if it is possible to express the |
| 2150 | concept in LLVM directly (ie, code generator support is not _required_). To do |
| 2151 | this, extend the default implementation of the IntrinsicLowering class to handle |
| 2152 | the intrinsic. Code generators use this class to lower intrinsics they do not |
| 2153 | understand to raw LLVM instructions that they do. |
| 2154 | </p> |
| 2155 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2156 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2157 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2158 | <!-- ======================================================================= --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2159 | <div class="doc_subsection"> |
| 2160 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> |
| 2161 | </div> |
| 2162 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2163 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2164 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2165 | <p>Variable argument support is defined in LLVM with the <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2166 | href="#i_vanext"><tt>vanext</tt></a> instruction and these three |
| 2167 | intrinsic functions. These functions are related to the similarly |
| 2168 | named macros defined in the <tt><stdarg.h></tt> header file.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2169 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2170 | <p>All of these functions operate on arguments that use a |
| 2171 | target-specific value type "<tt>va_list</tt>". The LLVM assembly |
| 2172 | language reference manual does not define what this type is, so all |
| 2173 | transformations should be prepared to handle intrinsics with any type |
| 2174 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2175 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2176 | <p>This example shows how the <a href="#i_vanext"><tt>vanext</tt></a> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2177 | instruction and the variable argument handling intrinsic functions are |
| 2178 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2179 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2180 | <pre> |
| 2181 | int %test(int %X, ...) { |
| 2182 | ; Initialize variable argument processing |
| 2183 | %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>() |
| 2184 | |
| 2185 | ; Read a single integer argument |
| 2186 | %tmp = vaarg sbyte* %ap, int |
| 2187 | |
| 2188 | ; Advance to the next argument |
| 2189 | %ap2 = vanext sbyte* %ap, int |
| 2190 | |
| 2191 | ; Demonstrate usage of llvm.va_copy and llvm.va_end |
| 2192 | %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2) |
| 2193 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq) |
| 2194 | |
| 2195 | ; Stop processing of arguments. |
| 2196 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2) |
| 2197 | ret int %tmp |
| 2198 | } |
| 2199 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2200 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2201 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2202 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2203 | <div class="doc_subsubsection"> |
| 2204 | <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> |
| 2205 | </div> |
| 2206 | |
| 2207 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2208 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2209 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2210 | <pre> call <va_list> ()* %llvm.va_start()<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2211 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2212 | <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt> |
| 2213 | for subsequent use by the variable argument intrinsics.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2214 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2215 | <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2216 | macro available in C. In a target-dependent way, it initializes and |
| 2217 | returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt> |
| 2218 | will produce the first variable argument passed to the function. Unlike |
| 2219 | the C <tt>va_start</tt> macro, this intrinsic does not need to know the |
| 2220 | last argument of the function, the compiler can figure that out.</p> |
| 2221 | <p>Note that this intrinsic function is only legal to be called from |
| 2222 | within the body of a variable argument function.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2223 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2224 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2225 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2226 | <div class="doc_subsubsection"> |
| 2227 | <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> |
| 2228 | </div> |
| 2229 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2230 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2231 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2232 | <pre> call void (<va_list>)* %llvm.va_end(<va_list> <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2233 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2234 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt> |
| 2235 | which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt> |
| 2236 | or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2237 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2238 | <p>The argument is a <tt>va_list</tt> to destroy.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2239 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2240 | <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2241 | macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>. |
| 2242 | Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a |
| 2243 | href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly |
| 2244 | with calls to <tt>llvm.va_end</tt>.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2245 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2246 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2247 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2248 | <div class="doc_subsubsection"> |
| 2249 | <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> |
| 2250 | </div> |
| 2251 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2252 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2253 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2254 | <h5>Syntax:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2255 | |
| 2256 | <pre> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 2257 | call <va_list> (<va_list>)* %llvm.va_copy(<va_list> <destarglist>) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2258 | </pre> |
| 2259 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2260 | <h5>Overview:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2261 | |
| 2262 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position |
| 2263 | from the source argument list to the destination argument list.</p> |
| 2264 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2265 | <h5>Arguments:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2266 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2267 | <p>The argument is the <tt>va_list</tt> to copy.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2268 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 2269 | <h5>Semantics:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2270 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2271 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2272 | macro available in C. In a target-dependent way, it copies the source |
| 2273 | <tt>va_list</tt> element into the returned list. This intrinsic is necessary |
Chris Lattner | fcd3725 | 2004-06-21 22:52:48 +0000 | [diff] [blame] | 2274 | because the <tt><a href="#i_va_start">llvm.va_start</a></tt> intrinsic may be |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2275 | arbitrarily complex and require memory allocation, for example.</p> |
| 2276 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2277 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2278 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2279 | <!-- ======================================================================= --> |
| 2280 | <div class="doc_subsection"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 2281 | <a name="int_gc">Accurate Garbage Collection Intrinsics</a> |
| 2282 | </div> |
| 2283 | |
| 2284 | <div class="doc_text"> |
| 2285 | |
| 2286 | <p> |
| 2287 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage |
| 2288 | Collection</a> requires the implementation and generation of these intrinsics. |
| 2289 | These intrinsics allow identification of <a href="#i_gcroot">GC roots on the |
| 2290 | stack</a>, as well as garbage collector implementations that require <a |
| 2291 | href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers. |
| 2292 | Front-ends for type-safe garbage collected languages should generate these |
| 2293 | intrinsics to make use of the LLVM garbage collectors. For more details, see <a |
| 2294 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. |
| 2295 | </p> |
| 2296 | </div> |
| 2297 | |
| 2298 | <!-- _______________________________________________________________________ --> |
| 2299 | <div class="doc_subsubsection"> |
| 2300 | <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> |
| 2301 | </div> |
| 2302 | |
| 2303 | <div class="doc_text"> |
| 2304 | |
| 2305 | <h5>Syntax:</h5> |
| 2306 | |
| 2307 | <pre> |
| 2308 | call void (<ty>**, <ty2>*)* %llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata) |
| 2309 | </pre> |
| 2310 | |
| 2311 | <h5>Overview:</h5> |
| 2312 | |
| 2313 | <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existance of a GC root to |
| 2314 | the code generator, and allows some metadata to be associated with it.</p> |
| 2315 | |
| 2316 | <h5>Arguments:</h5> |
| 2317 | |
| 2318 | <p>The first argument specifies the address of a stack object that contains the |
| 2319 | root pointer. The second pointer (which must be either a constant or a global |
| 2320 | value address) contains the meta-data to be associated with the root.</p> |
| 2321 | |
| 2322 | <h5>Semantics:</h5> |
| 2323 | |
| 2324 | <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc" |
| 2325 | location. At compile-time, the code generator generates information to allow |
| 2326 | the runtime to find the pointer at GC safe points. |
| 2327 | </p> |
| 2328 | |
| 2329 | </div> |
| 2330 | |
| 2331 | |
| 2332 | <!-- _______________________________________________________________________ --> |
| 2333 | <div class="doc_subsubsection"> |
| 2334 | <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> |
| 2335 | </div> |
| 2336 | |
| 2337 | <div class="doc_text"> |
| 2338 | |
| 2339 | <h5>Syntax:</h5> |
| 2340 | |
| 2341 | <pre> |
| 2342 | call sbyte* (sbyte**)* %llvm.gcread(sbyte** %Ptr) |
| 2343 | </pre> |
| 2344 | |
| 2345 | <h5>Overview:</h5> |
| 2346 | |
| 2347 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap |
| 2348 | locations, allowing garbage collector implementations that require read |
| 2349 | barriers.</p> |
| 2350 | |
| 2351 | <h5>Arguments:</h5> |
| 2352 | |
| 2353 | <p>The argument is the address to read from, which should be an address |
| 2354 | allocated from the garbage collector.</p> |
| 2355 | |
| 2356 | <h5>Semantics:</h5> |
| 2357 | |
| 2358 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load |
| 2359 | instruction, but may be replaced with substantially more complex code by the |
| 2360 | garbage collector runtime, as needed.</p> |
| 2361 | |
| 2362 | </div> |
| 2363 | |
| 2364 | |
| 2365 | <!-- _______________________________________________________________________ --> |
| 2366 | <div class="doc_subsubsection"> |
| 2367 | <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> |
| 2368 | </div> |
| 2369 | |
| 2370 | <div class="doc_text"> |
| 2371 | |
| 2372 | <h5>Syntax:</h5> |
| 2373 | |
| 2374 | <pre> |
| 2375 | call void (sbyte*, sbyte**)* %llvm.gcwrite(sbyte* %P1, sbyte** %P2) |
| 2376 | </pre> |
| 2377 | |
| 2378 | <h5>Overview:</h5> |
| 2379 | |
| 2380 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap |
| 2381 | locations, allowing garbage collector implementations that require write |
| 2382 | barriers (such as generational or reference counting collectors).</p> |
| 2383 | |
| 2384 | <h5>Arguments:</h5> |
| 2385 | |
| 2386 | <p>The first argument is the reference to store, and the second is the heap |
| 2387 | location to store to.</p> |
| 2388 | |
| 2389 | <h5>Semantics:</h5> |
| 2390 | |
| 2391 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store |
| 2392 | instruction, but may be replaced with substantially more complex code by the |
| 2393 | garbage collector runtime, as needed.</p> |
| 2394 | |
| 2395 | </div> |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | <!-- ======================================================================= --> |
| 2400 | <div class="doc_subsection"> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2401 | <a name="int_codegen">Code Generator Intrinsics</a> |
| 2402 | </div> |
| 2403 | |
| 2404 | <div class="doc_text"> |
| 2405 | <p> |
| 2406 | These intrinsics are provided by LLVM to expose special features that may only |
| 2407 | be implemented with code generator support. |
| 2408 | </p> |
| 2409 | |
| 2410 | </div> |
| 2411 | |
| 2412 | <!-- _______________________________________________________________________ --> |
| 2413 | <div class="doc_subsubsection"> |
| 2414 | <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> |
| 2415 | </div> |
| 2416 | |
| 2417 | <div class="doc_text"> |
| 2418 | |
| 2419 | <h5>Syntax:</h5> |
| 2420 | <pre> |
| 2421 | call void* ()* %llvm.returnaddress(uint <level>) |
| 2422 | </pre> |
| 2423 | |
| 2424 | <h5>Overview:</h5> |
| 2425 | |
| 2426 | <p> |
| 2427 | The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value |
| 2428 | indicating the return address of the current function or one of its callers. |
| 2429 | </p> |
| 2430 | |
| 2431 | <h5>Arguments:</h5> |
| 2432 | |
| 2433 | <p> |
| 2434 | The argument to this intrinsic indicates which function to return the address |
| 2435 | for. Zero indicates the calling function, one indicates its caller, etc. The |
| 2436 | argument is <b>required</b> to be a constant integer value. |
| 2437 | </p> |
| 2438 | |
| 2439 | <h5>Semantics:</h5> |
| 2440 | |
| 2441 | <p> |
| 2442 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating |
| 2443 | the return address of the specified call frame, or zero if it cannot be |
| 2444 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 2445 | for arguments other than zero, so it should only be used for debugging purposes. |
| 2446 | </p> |
| 2447 | |
| 2448 | <p> |
| 2449 | Note that calling this intrinsic does not prevent function inlining or other |
| 2450 | aggressive transformations, so the value returned may not that of the obvious |
| 2451 | source-language caller. |
| 2452 | </p> |
| 2453 | </div> |
| 2454 | |
| 2455 | |
| 2456 | <!-- _______________________________________________________________________ --> |
| 2457 | <div class="doc_subsubsection"> |
| 2458 | <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> |
| 2459 | </div> |
| 2460 | |
| 2461 | <div class="doc_text"> |
| 2462 | |
| 2463 | <h5>Syntax:</h5> |
| 2464 | <pre> |
| 2465 | call void* ()* %llvm.frameaddress(uint <level>) |
| 2466 | </pre> |
| 2467 | |
| 2468 | <h5>Overview:</h5> |
| 2469 | |
| 2470 | <p> |
| 2471 | The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame |
| 2472 | pointer value for the specified stack frame. |
| 2473 | </p> |
| 2474 | |
| 2475 | <h5>Arguments:</h5> |
| 2476 | |
| 2477 | <p> |
| 2478 | The argument to this intrinsic indicates which function to return the frame |
| 2479 | pointer for. Zero indicates the calling function, one indicates its caller, |
| 2480 | etc. The argument is <b>required</b> to be a constant integer value. |
| 2481 | </p> |
| 2482 | |
| 2483 | <h5>Semantics:</h5> |
| 2484 | |
| 2485 | <p> |
| 2486 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating |
| 2487 | the frame address of the specified call frame, or zero if it cannot be |
| 2488 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 2489 | for arguments other than zero, so it should only be used for debugging purposes. |
| 2490 | </p> |
| 2491 | |
| 2492 | <p> |
| 2493 | Note that calling this intrinsic does not prevent function inlining or other |
| 2494 | aggressive transformations, so the value returned may not that of the obvious |
| 2495 | source-language caller. |
| 2496 | </p> |
| 2497 | </div> |
| 2498 | |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2499 | <!-- ======================================================================= --> |
| 2500 | <div class="doc_subsection"> |
| 2501 | <a name="int_os">Operating System Intrinsics</a> |
| 2502 | </div> |
| 2503 | |
| 2504 | <div class="doc_text"> |
| 2505 | <p> |
| 2506 | These intrinsics are provided by LLVM to support the implementation of |
| 2507 | operating system level code. |
| 2508 | </p> |
| 2509 | |
| 2510 | </div> |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2511 | |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2512 | <!-- _______________________________________________________________________ --> |
| 2513 | <div class="doc_subsubsection"> |
| 2514 | <a name="i_readport">'<tt>llvm.readport</tt>' Intrinsic</a> |
| 2515 | </div> |
| 2516 | |
| 2517 | <div class="doc_text"> |
| 2518 | |
| 2519 | <h5>Syntax:</h5> |
| 2520 | <pre> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2521 | call <integer type> (<integer type>)* %llvm.readport (<integer type> <address>) |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2522 | </pre> |
| 2523 | |
| 2524 | <h5>Overview:</h5> |
| 2525 | |
| 2526 | <p> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2527 | The '<tt>llvm.readport</tt>' intrinsic reads data from the specified hardware |
| 2528 | I/O port. |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2529 | </p> |
| 2530 | |
| 2531 | <h5>Arguments:</h5> |
| 2532 | |
| 2533 | <p> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2534 | The argument to this intrinsic indicates the hardware I/O address from which |
| 2535 | to read the data. The address is in the hardware I/O address namespace (as |
| 2536 | opposed to being a memory location for memory mapped I/O). |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2537 | </p> |
| 2538 | |
| 2539 | <h5>Semantics:</h5> |
| 2540 | |
| 2541 | <p> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2542 | The '<tt>llvm.readport</tt>' intrinsic reads data from the hardware I/O port |
| 2543 | specified by <i>address</i> and returns the value. The address and return |
| 2544 | value must be integers, but the size is dependent upon the platform upon which |
| 2545 | the program is code generated. For example, on x86, the address must be an |
| 2546 | unsigned 16 bit value, and the return value must be 8, 16, or 32 bits. |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2547 | </p> |
| 2548 | |
| 2549 | </div> |
| 2550 | |
| 2551 | <!-- _______________________________________________________________________ --> |
| 2552 | <div class="doc_subsubsection"> |
| 2553 | <a name="i_writeport">'<tt>llvm.writeport</tt>' Intrinsic</a> |
| 2554 | </div> |
| 2555 | |
| 2556 | <div class="doc_text"> |
| 2557 | |
| 2558 | <h5>Syntax:</h5> |
| 2559 | <pre> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame^] | 2560 | call void (<integer type>, <integer type>)* |
| 2561 | %llvm.writeport (<integer type> <value>, |
| 2562 | <integer type> <address>) |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2563 | </pre> |
| 2564 | |
| 2565 | <h5>Overview:</h5> |
| 2566 | |
| 2567 | <p> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2568 | The '<tt>llvm.writeport</tt>' intrinsic writes data to the specified hardware |
| 2569 | I/O port. |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2570 | </p> |
| 2571 | |
| 2572 | <h5>Arguments:</h5> |
| 2573 | |
| 2574 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2575 | The first argument is the value to write to the I/O port. |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2576 | </p> |
| 2577 | |
| 2578 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2579 | The second argument indicates the hardware I/O address to which data should be |
| 2580 | written. The address is in the hardware I/O address namespace (as opposed to |
| 2581 | being a memory location for memory mapped I/O). |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2582 | </p> |
| 2583 | |
| 2584 | <h5>Semantics:</h5> |
| 2585 | |
| 2586 | <p> |
| 2587 | The '<tt>llvm.writeport</tt>' intrinsic writes <i>value</i> to the I/O port |
| 2588 | specified by <i>address</i>. The address and value must be integers, but the |
| 2589 | size is dependent upon the platform upon which the program is code generated. |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 2590 | For example, on x86, the address must be an unsigned 16 bit value, and the |
| 2591 | value written must be 8, 16, or 32 bits in length. |
John Criswell | cfd3bac | 2004-04-09 15:23:37 +0000 | [diff] [blame] | 2592 | </p> |
| 2593 | |
| 2594 | </div> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2595 | |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2596 | <!-- _______________________________________________________________________ --> |
| 2597 | <div class="doc_subsubsection"> |
| 2598 | <a name="i_readio">'<tt>llvm.readio</tt>' Intrinsic</a> |
| 2599 | </div> |
| 2600 | |
| 2601 | <div class="doc_text"> |
| 2602 | |
| 2603 | <h5>Syntax:</h5> |
| 2604 | <pre> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2605 | call <result> (<ty>*)* %llvm.readio (<ty> * <pointer>) |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2606 | </pre> |
| 2607 | |
| 2608 | <h5>Overview:</h5> |
| 2609 | |
| 2610 | <p> |
| 2611 | The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O |
| 2612 | address. |
| 2613 | </p> |
| 2614 | |
| 2615 | <h5>Arguments:</h5> |
| 2616 | |
| 2617 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2618 | The argument to this intrinsic is a pointer indicating the memory address from |
| 2619 | which to read the data. The data must be a |
| 2620 | <a href="#t_firstclass">first class</a> type. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2621 | </p> |
| 2622 | |
| 2623 | <h5>Semantics:</h5> |
| 2624 | |
| 2625 | <p> |
| 2626 | The '<tt>llvm.readio</tt>' intrinsic reads data from a memory mapped I/O |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2627 | location specified by <i>pointer</i> and returns the value. The argument must |
| 2628 | be a pointer, and the return value must be a |
| 2629 | <a href="#t_firstclass">first class</a> type. However, certain architectures |
| 2630 | may not support I/O on all first class types. For example, 32 bit processors |
| 2631 | may only support I/O on data types that are 32 bits or less. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2632 | </p> |
| 2633 | |
| 2634 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2635 | This intrinsic enforces an in-order memory model for llvm.readio and |
| 2636 | llvm.writeio calls on machines that use dynamic scheduling. Dynamically |
| 2637 | scheduled processors may execute loads and stores out of order, re-ordering at |
| 2638 | run time accesses to memory mapped I/O registers. Using these intrinsics |
| 2639 | ensures that accesses to memory mapped I/O registers occur in program order. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2640 | </p> |
| 2641 | |
| 2642 | </div> |
| 2643 | |
| 2644 | <!-- _______________________________________________________________________ --> |
| 2645 | <div class="doc_subsubsection"> |
| 2646 | <a name="i_writeio">'<tt>llvm.writeio</tt>' Intrinsic</a> |
| 2647 | </div> |
| 2648 | |
| 2649 | <div class="doc_text"> |
| 2650 | |
| 2651 | <h5>Syntax:</h5> |
| 2652 | <pre> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2653 | call void (<ty1>, <ty2>*)* %llvm.writeio (<ty1> <value>, <ty2> * <pointer>) |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2654 | </pre> |
| 2655 | |
| 2656 | <h5>Overview:</h5> |
| 2657 | |
| 2658 | <p> |
| 2659 | The '<tt>llvm.writeio</tt>' intrinsic writes data to the specified memory |
| 2660 | mapped I/O address. |
| 2661 | </p> |
| 2662 | |
| 2663 | <h5>Arguments:</h5> |
| 2664 | |
| 2665 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2666 | The first argument is the value to write to the memory mapped I/O location. |
| 2667 | The second argument is a pointer indicating the memory address to which the |
| 2668 | data should be written. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2669 | </p> |
| 2670 | |
| 2671 | <h5>Semantics:</h5> |
| 2672 | |
| 2673 | <p> |
| 2674 | The '<tt>llvm.writeio</tt>' intrinsic writes <i>value</i> to the memory mapped |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2675 | I/O address specified by <i>pointer</i>. The value must be a |
| 2676 | <a href="#t_firstclass">first class</a> type. However, certain architectures |
| 2677 | may not support I/O on all first class types. For example, 32 bit processors |
| 2678 | may only support I/O on data types that are 32 bits or less. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2679 | </p> |
| 2680 | |
| 2681 | <p> |
John Criswell | 96db6fc | 2004-04-12 16:33:19 +0000 | [diff] [blame] | 2682 | This intrinsic enforces an in-order memory model for llvm.readio and |
| 2683 | llvm.writeio calls on machines that use dynamic scheduling. Dynamically |
| 2684 | scheduled processors may execute loads and stores out of order, re-ordering at |
| 2685 | run time accesses to memory mapped I/O registers. Using these intrinsics |
| 2686 | ensures that accesses to memory mapped I/O registers occur in program order. |
John Criswell | 183402a | 2004-04-12 15:02:16 +0000 | [diff] [blame] | 2687 | </p> |
| 2688 | |
| 2689 | </div> |
| 2690 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2691 | <!-- ======================================================================= --> |
| 2692 | <div class="doc_subsection"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2693 | <a name="int_libc">Standard C Library Intrinsics</a> |
| 2694 | </div> |
| 2695 | |
| 2696 | <div class="doc_text"> |
| 2697 | <p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2698 | LLVM provides intrinsics for a few important standard C library functions. |
| 2699 | These intrinsics allow source-language front-ends to pass information about the |
| 2700 | alignment of the pointer arguments to the code generator, providing opportunity |
| 2701 | for more efficient code generation. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2702 | </p> |
| 2703 | |
| 2704 | </div> |
| 2705 | |
| 2706 | <!-- _______________________________________________________________________ --> |
| 2707 | <div class="doc_subsubsection"> |
| 2708 | <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> |
| 2709 | </div> |
| 2710 | |
| 2711 | <div class="doc_text"> |
| 2712 | |
| 2713 | <h5>Syntax:</h5> |
| 2714 | <pre> |
| 2715 | call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* <dest>, sbyte* <src>, |
| 2716 | uint <len>, uint <align>) |
| 2717 | </pre> |
| 2718 | |
| 2719 | <h5>Overview:</h5> |
| 2720 | |
| 2721 | <p> |
| 2722 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source |
| 2723 | location to the destination location. |
| 2724 | </p> |
| 2725 | |
| 2726 | <p> |
| 2727 | Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic |
| 2728 | does not return a value, and takes an extra alignment argument. |
| 2729 | </p> |
| 2730 | |
| 2731 | <h5>Arguments:</h5> |
| 2732 | |
| 2733 | <p> |
| 2734 | The first argument is a pointer to the destination, the second is a pointer to |
| 2735 | the source. The third argument is an (arbitrarily sized) integer argument |
| 2736 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 2737 | of the source and destination locations. |
| 2738 | </p> |
| 2739 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 2740 | <p> |
| 2741 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 2742 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 2743 | and that both the source and destination pointers are aligned to that boundary. |
| 2744 | </p> |
| 2745 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 2746 | <h5>Semantics:</h5> |
| 2747 | |
| 2748 | <p> |
| 2749 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source |
| 2750 | location to the destination location, which are not allowed to overlap. It |
| 2751 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 2752 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 2753 | be set to 0 or 1. |
| 2754 | </p> |
| 2755 | </div> |
| 2756 | |
| 2757 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 2758 | <!-- _______________________________________________________________________ --> |
| 2759 | <div class="doc_subsubsection"> |
| 2760 | <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> |
| 2761 | </div> |
| 2762 | |
| 2763 | <div class="doc_text"> |
| 2764 | |
| 2765 | <h5>Syntax:</h5> |
| 2766 | <pre> |
| 2767 | call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* <dest>, sbyte* <src>, |
| 2768 | uint <len>, uint <align>) |
| 2769 | </pre> |
| 2770 | |
| 2771 | <h5>Overview:</h5> |
| 2772 | |
| 2773 | <p> |
| 2774 | The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source |
| 2775 | location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>' |
| 2776 | intrinsic but allows the two memory locations to overlap. |
| 2777 | </p> |
| 2778 | |
| 2779 | <p> |
| 2780 | Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic |
| 2781 | does not return a value, and takes an extra alignment argument. |
| 2782 | </p> |
| 2783 | |
| 2784 | <h5>Arguments:</h5> |
| 2785 | |
| 2786 | <p> |
| 2787 | The first argument is a pointer to the destination, the second is a pointer to |
| 2788 | the source. The third argument is an (arbitrarily sized) integer argument |
| 2789 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 2790 | of the source and destination locations. |
| 2791 | </p> |
| 2792 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 2793 | <p> |
| 2794 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 2795 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 2796 | and that both the source and destination pointers are aligned to that boundary. |
| 2797 | </p> |
| 2798 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 2799 | <h5>Semantics:</h5> |
| 2800 | |
| 2801 | <p> |
| 2802 | The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source |
| 2803 | location to the destination location, which may overlap. It |
| 2804 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 2805 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 2806 | be set to 0 or 1. |
| 2807 | </p> |
| 2808 | </div> |
| 2809 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2810 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 2811 | <!-- _______________________________________________________________________ --> |
| 2812 | <div class="doc_subsubsection"> |
| 2813 | <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a> |
| 2814 | </div> |
| 2815 | |
| 2816 | <div class="doc_text"> |
| 2817 | |
| 2818 | <h5>Syntax:</h5> |
| 2819 | <pre> |
| 2820 | call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* <dest>, ubyte <val>, |
| 2821 | uint <len>, uint <align>) |
| 2822 | </pre> |
| 2823 | |
| 2824 | <h5>Overview:</h5> |
| 2825 | |
| 2826 | <p> |
| 2827 | The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular |
| 2828 | byte value. |
| 2829 | </p> |
| 2830 | |
| 2831 | <p> |
| 2832 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic |
| 2833 | does not return a value, and takes an extra alignment argument. |
| 2834 | </p> |
| 2835 | |
| 2836 | <h5>Arguments:</h5> |
| 2837 | |
| 2838 | <p> |
| 2839 | The first argument is a pointer to the destination to fill, the second is the |
| 2840 | byte value to fill it with, the third argument is an (arbitrarily sized) integer |
| 2841 | argument specifying the number of bytes to fill, and the fourth argument is the |
| 2842 | known alignment of destination location. |
| 2843 | </p> |
| 2844 | |
| 2845 | <p> |
| 2846 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 2847 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 2848 | and that the destination pointer is aligned to that boundary. |
| 2849 | </p> |
| 2850 | |
| 2851 | <h5>Semantics:</h5> |
| 2852 | |
| 2853 | <p> |
| 2854 | The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the |
| 2855 | destination location. If the argument is known to be aligned to some boundary, |
| 2856 | this can be specified as the fourth argument, otherwise it should be set to 0 or |
| 2857 | 1. |
| 2858 | </p> |
| 2859 | </div> |
| 2860 | |
| 2861 | |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 2862 | <!-- _______________________________________________________________________ --> |
| 2863 | <div class="doc_subsubsection"> |
Alkis Evlogimenos | 26bbe93 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 2864 | <a name="i_isunordered">'<tt>llvm.isunordered</tt>' Intrinsic</a> |
| 2865 | </div> |
| 2866 | |
| 2867 | <div class="doc_text"> |
| 2868 | |
| 2869 | <h5>Syntax:</h5> |
| 2870 | <pre> |
| 2871 | call bool (<float or double>, <float or double>)* %llvm.isunordered(<float or double> Val1, |
| 2872 | <float or double> Val2) |
| 2873 | </pre> |
| 2874 | |
| 2875 | <h5>Overview:</h5> |
| 2876 | |
| 2877 | <p> |
| 2878 | The '<tt>llvm.isunordered</tt>' intrinsic returns true if either or both of the |
| 2879 | specified floating point values is a NAN. |
| 2880 | </p> |
| 2881 | |
| 2882 | <h5>Arguments:</h5> |
| 2883 | |
| 2884 | <p> |
| 2885 | The arguments are floating point numbers of the same type. |
| 2886 | </p> |
| 2887 | |
| 2888 | <h5>Semantics:</h5> |
| 2889 | |
| 2890 | <p> |
| 2891 | If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise |
| 2892 | false. |
| 2893 | </p> |
| 2894 | </div> |
| 2895 | |
| 2896 | |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 2897 | |
| 2898 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2899 | <!-- ======================================================================= --> |
| 2900 | <div class="doc_subsection"> |
| 2901 | <a name="int_debugger">Debugger Intrinsics</a> |
| 2902 | </div> |
| 2903 | |
| 2904 | <div class="doc_text"> |
| 2905 | <p> |
| 2906 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), |
| 2907 | are described in the <a |
| 2908 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level |
| 2909 | Debugging</a> document. |
| 2910 | </p> |
| 2911 | </div> |
| 2912 | |
| 2913 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2914 | <!-- *********************************************************************** --> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2915 | <hr> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2916 | <address> |
| 2917 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 2918 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 2919 | <a href="http://validator.w3.org/check/referer"><img |
| 2920 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a> |
| 2921 | |
| 2922 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
| 2923 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br> |
| 2924 | Last modified: $Date$ |
| 2925 | </address> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2926 | </body> |
| 2927 | </html> |