Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2 | <html> |
| 3 | <head> |
| 4 | <title>LLVM Assembly Language Reference Manual</title> |
| 5 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
| 6 | </head> |
| 7 | <body> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 8 | <div class="doc_title"> LLVM Language Reference Manual </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 10 | <li><a href="#abstract">Abstract</a></li> |
| 11 | <li><a href="#introduction">Introduction</a></li> |
| 12 | <li><a href="#identifiers">Identifiers</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 13 | <li><a href="#typesystem">Type System</a> |
| 14 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 15 | <li><a href="#t_primitive">Primitive Types</a> |
| 16 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 17 | <li><a href="#t_classifications">Type Classifications</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 18 | </ol> |
| 19 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 20 | <li><a href="#t_derived">Derived Types</a> |
| 21 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 22 | <li><a href="#t_array">Array Type</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 23 | <li><a href="#t_function">Function Type</a></li> |
| 24 | <li><a href="#t_pointer">Pointer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 25 | <li><a href="#t_struct">Structure Type</a></li> |
| 26 | <!-- <li><a href="#t_packed" >Packed Type</a> --> |
| 27 | </ol> |
| 28 | </li> |
| 29 | </ol> |
| 30 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 31 | <li><a href="#highlevel">High Level Structure</a> |
| 32 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 33 | <li><a href="#modulestructure">Module Structure</a></li> |
| 34 | <li><a href="#globalvars">Global Variables</a></li> |
| 35 | <li><a href="#functionstructure">Function Structure</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 36 | </ol> |
| 37 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 38 | <li><a href="#instref">Instruction Reference</a> |
| 39 | <ol> |
| 40 | <li><a href="#terminators">Terminator Instructions</a> |
| 41 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 42 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> |
| 43 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 44 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> |
| 45 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 46 | <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li> |
| 47 | </ol> |
| 48 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 49 | <li><a href="#binaryops">Binary Operations</a> |
| 50 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 51 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> |
| 52 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> |
| 53 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> |
| 54 | <li><a href="#i_div">'<tt>div</tt>' Instruction</a></li> |
| 55 | <li><a href="#i_rem">'<tt>rem</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 56 | <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] | 57 | </ol> |
| 58 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 59 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> |
| 60 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 61 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 62 | <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 63 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> |
| 64 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> |
| 65 | <li><a href="#i_shr">'<tt>shr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 66 | </ol> |
| 67 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 68 | <li><a href="#memoryops">Memory Access Operations</a> |
| 69 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 70 | <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li> |
| 71 | <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li> |
| 72 | <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li> |
| 73 | <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li> |
| 74 | <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li> |
| 75 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> |
| 76 | </ol> |
| 77 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 78 | <li><a href="#otherops">Other Operations</a> |
| 79 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 80 | <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 81 | <li><a href="#i_cast">'<tt>cast .. to</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 82 | <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 83 | <li><a href="#i_vanext">'<tt>vanext</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 84 | <li><a href="#i_vaarg">'<tt>vaarg</tt>' Instruction</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 85 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 86 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 87 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 88 | </li> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 89 | <li><a href="#intrinsics">Intrinsic Functions</a> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 90 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 91 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> |
| 92 | <ol> |
| 93 | <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> |
| 94 | <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li> |
| 95 | <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li> |
| 96 | </ol> |
| 97 | </li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 98 | <li><a href="#int_codegen">Code Generator Intrinsics</a> |
| 99 | <ol> |
| 100 | <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> |
| 101 | <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li> |
| 102 | </ol> |
| 103 | </li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 104 | <li><a href="#int_libc">Standard C Library Intrinsics</a> |
| 105 | <ol> |
| 106 | <li><a href="#i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a></li> |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 107 | <li><a href="#i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a></li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 108 | <li><a href="#i_memset">'<tt>llvm.memset</tt>' Intrinsic</a></li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 109 | </ol> |
| 110 | </li> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 111 | <li><a href="#int_debugger">Debugger intrinsics</a> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 112 | </ol> |
| 113 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 114 | </ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 115 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 116 | <p><b>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
| 117 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></b></p> |
| 118 | <p> </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 119 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 120 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 121 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 122 | <!-- *********************************************************************** --> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 123 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 124 | <p>This document is a reference manual for the LLVM assembly language. |
| 125 | LLVM is an SSA based representation that provides type safety, |
| 126 | low-level operations, flexibility, and the capability of representing |
| 127 | 'all' high-level languages cleanly. It is the common code |
| 128 | representation used throughout all phases of the LLVM compilation |
| 129 | strategy.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 130 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 131 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 132 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> |
| 133 | <!-- *********************************************************************** --> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 134 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 135 | <p>The LLVM code representation is designed to be used in three |
| 136 | different forms: as an in-memory compiler IR, as an on-disk bytecode |
| 137 | representation (suitable for fast loading by a Just-In-Time compiler), |
| 138 | and as a human readable assembly language representation. This allows |
| 139 | LLVM to provide a powerful intermediate representation for efficient |
| 140 | compiler transformations and analysis, while providing a natural means |
| 141 | to debug and visualize the transformations. The three different forms |
| 142 | of LLVM are all equivalent. This document describes the human readable |
| 143 | representation and notation.</p> |
| 144 | <p>The LLVM representation aims to be a light-weight and low-level |
| 145 | while being expressive, typed, and extensible at the same time. It |
| 146 | aims to be a "universal IR" of sorts, by being at a low enough level |
| 147 | that high-level ideas may be cleanly mapped to it (similar to how |
| 148 | microprocessors are "universal IR's", allowing many source languages to |
| 149 | be mapped to them). By providing type information, LLVM can be used as |
| 150 | the target of optimizations: for example, through pointer analysis, it |
| 151 | can be proven that a C automatic variable is never accessed outside of |
| 152 | the current function... allowing it to be promoted to a simple SSA |
| 153 | value instead of a memory location.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 154 | </div> |
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_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 157 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 158 | <p>It is important to note that this document describes 'well formed' |
| 159 | LLVM assembly language. There is a difference between what the parser |
| 160 | accepts and what is considered 'well formed'. For example, the |
| 161 | following instruction is syntactically okay, but not well formed:</p> |
| 162 | <pre> %x = <a href="#i_add">add</a> int 1, %x<br></pre> |
| 163 | <p>...because the definition of <tt>%x</tt> does not dominate all of |
| 164 | its uses. The LLVM infrastructure provides a verification pass that may |
| 165 | be used to verify that an LLVM module is well formed. This pass is |
| 166 | automatically run by the parser after parsing input assembly, and by |
| 167 | the optimizer before it outputs bytecode. The violations pointed out |
| 168 | by the verifier pass indicate bugs in transformation passes or input to |
| 169 | the parser.</p> |
| 170 | <!-- Describe the typesetting conventions here. --> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 171 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 172 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 173 | <!-- *********************************************************************** --> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 174 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 175 | <p>LLVM uses three different forms of identifiers, for different |
| 176 | purposes:</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 177 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 178 | <li>Numeric constants are represented as you would expect: 12, -3 |
| 179 | 123.421, etc. Floating point constants have an optional hexidecimal |
| 180 | notation.</li> |
| 181 | <li>Named values are represented as a string of characters with a '%' |
| 182 | prefix. For example, %foo, %DivisionByZero, |
| 183 | %a.really.long.identifier. The actual regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. |
| 184 | Identifiers which require other characters in their names can be |
| 185 | surrounded with quotes. In this way, anything except a <tt>"</tt> |
| 186 | character can be used in a name.</li> |
| 187 | <li>Unnamed values are represented as an unsigned numeric value with |
| 188 | a '%' prefix. For example, %12, %2, %44.</li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 189 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 190 | <p>LLVM requires the values start with a '%' sign for two reasons: |
| 191 | Compilers don't need to worry about name clashes with reserved words, |
| 192 | and the set of reserved words may be expanded in the future without |
| 193 | penalty. Additionally, unnamed identifiers allow a compiler to quickly |
| 194 | come up with a temporary variable without having to avoid symbol table |
| 195 | conflicts.</p> |
| 196 | <p>Reserved words in LLVM are very similar to reserved words in other |
| 197 | languages. There are keywords for different opcodes ('<tt><a |
| 198 | href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a |
| 199 | href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a |
| 200 | href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', |
| 201 | etc...), and others. These reserved words cannot conflict with |
| 202 | variable names, because none of them start with a '%' character.</p> |
| 203 | <p>Here is an example of LLVM code to multiply the integer variable '<tt>%X</tt>' |
| 204 | by 8:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 205 | <p>The easy way:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 206 | <pre> %result = <a href="#i_mul">mul</a> uint %X, 8<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 207 | <p>After strength reduction:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 208 | <pre> %result = <a href="#i_shl">shl</a> uint %X, ubyte 3<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 209 | <p>And the hard way:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 210 | <pre> <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i> |
| 211 | <a |
| 212 | href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i> |
| 213 | %result = <a |
| 214 | href="#i_add">add</a> uint %1, %1<br></pre> |
| 215 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several |
| 216 | important lexical features of LLVM:</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 217 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 218 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end |
| 219 | of line.</li> |
| 220 | <li>Unnamed temporaries are created when the result of a computation |
| 221 | is not assigned to a named value.</li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 222 | <li>Unnamed temporaries are numbered sequentially</li> |
| 223 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 224 | <p>...and it also show a convention that we follow in this document. |
| 225 | When demonstrating instructions, we will follow an instruction with a |
| 226 | comment that defines the type and name of value produced. Comments are |
| 227 | shown in italic text.</p> |
| 228 | <p>The one non-intuitive notation for constants is the optional |
| 229 | hexidecimal form of floating point constants. For example, the form '<tt>double |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 230 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 231 | 4.5e+15</tt>' which is also supported by the parser. The only time |
| 232 | hexadecimal floating point constants are useful (and the only time that |
| 233 | they are generated by the disassembler) is when an FP constant has to |
| 234 | be emitted that is not representable as a decimal floating point number |
| 235 | exactly. For example, NaN's, infinities, and other special cases are |
| 236 | represented in their IEEE hexadecimal format so that assembly and |
| 237 | disassembly do not cause any bits to change in the constants.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 238 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 239 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 240 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> |
| 241 | <!-- *********************************************************************** --> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 242 | <div class="doc_text"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 243 | <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] | 244 | intermediate representation. Being typed enables a number of |
| 245 | optimizations to be performed on the IR directly, without having to do |
| 246 | extra analyses on the side before the transformation. A strong type |
| 247 | system makes it easier to read the generated code and enables novel |
| 248 | analyses and transformations that are not feasible to perform on normal |
| 249 | three address code representations.</p> |
Chris Lattner | 7bae395 | 2002-06-25 18:03:17 +0000 | [diff] [blame] | 250 | <!-- The written form for the type system was heavily influenced by the |
| 251 | syntactic problems with types in the C language<sup><a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 252 | href="#rw_stroustrup">1</a></sup>.<p> --> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 253 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 254 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 255 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 256 | <p>The primitive types are the fundemental building blocks of the LLVM |
| 257 | system. The current set of primitive types are as follows:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 258 | <p> |
| 259 | <table border="0" align="center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 260 | <tbody> |
| 261 | <tr> |
| 262 | <td> |
| 263 | <table border="1" cellspacing="0" cellpadding="4" align="center"> |
| 264 | <tbody> |
| 265 | <tr> |
| 266 | <td><tt>void</tt></td> |
| 267 | <td>No value</td> |
| 268 | </tr> |
| 269 | <tr> |
| 270 | <td><tt>ubyte</tt></td> |
| 271 | <td>Unsigned 8 bit value</td> |
| 272 | </tr> |
| 273 | <tr> |
| 274 | <td><tt>ushort</tt></td> |
| 275 | <td>Unsigned 16 bit value</td> |
| 276 | </tr> |
| 277 | <tr> |
| 278 | <td><tt>uint</tt></td> |
| 279 | <td>Unsigned 32 bit value</td> |
| 280 | </tr> |
| 281 | <tr> |
| 282 | <td><tt>ulong</tt></td> |
| 283 | <td>Unsigned 64 bit value</td> |
| 284 | </tr> |
| 285 | <tr> |
| 286 | <td><tt>float</tt></td> |
| 287 | <td>32 bit floating point value</td> |
| 288 | </tr> |
| 289 | <tr> |
| 290 | <td><tt>label</tt></td> |
| 291 | <td>Branch destination</td> |
| 292 | </tr> |
| 293 | </tbody> |
| 294 | </table> |
| 295 | </td> |
| 296 | <td valign="top"> |
| 297 | <table border="1" cellspacing="0" cellpadding="4" align="center""> |
| 298 | <tbody> |
| 299 | <tr> |
| 300 | <td><tt>bool</tt></td> |
| 301 | <td>True or False value</td> |
| 302 | </tr> |
| 303 | <tr> |
| 304 | <td><tt>sbyte</tt></td> |
| 305 | <td>Signed 8 bit value</td> |
| 306 | </tr> |
| 307 | <tr> |
| 308 | <td><tt>short</tt></td> |
| 309 | <td>Signed 16 bit value</td> |
| 310 | </tr> |
| 311 | <tr> |
| 312 | <td><tt>int</tt></td> |
| 313 | <td>Signed 32 bit value</td> |
| 314 | </tr> |
| 315 | <tr> |
| 316 | <td><tt>long</tt></td> |
| 317 | <td>Signed 64 bit value</td> |
| 318 | </tr> |
| 319 | <tr> |
| 320 | <td><tt>double</tt></td> |
| 321 | <td>64 bit floating point value</td> |
| 322 | </tr> |
| 323 | </tbody> |
| 324 | </table> |
| 325 | </td> |
| 326 | </tr> |
| 327 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 328 | </table> |
| 329 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 330 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 331 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 332 | <div class="doc_subsubsection"> <a name="t_classifications">Type |
| 333 | Classifications</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 334 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 335 | <p>These different primitive types fall into a few useful |
| 336 | classifications:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 337 | <p> |
| 338 | <table border="1" cellspacing="0" cellpadding="4" align="center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 339 | <tbody> |
| 340 | <tr> |
| 341 | <td><a name="t_signed">signed</a></td> |
| 342 | <td><tt>sbyte, short, int, long, float, double</tt></td> |
| 343 | </tr> |
| 344 | <tr> |
| 345 | <td><a name="t_unsigned">unsigned</a></td> |
| 346 | <td><tt>ubyte, ushort, uint, ulong</tt></td> |
| 347 | </tr> |
| 348 | <tr> |
| 349 | <td><a name="t_integer">integer</a></td> |
| 350 | <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td> |
| 351 | </tr> |
| 352 | <tr> |
| 353 | <td><a name="t_integral">integral</a></td> |
| 354 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td> |
| 355 | </tr> |
| 356 | <tr> |
| 357 | <td><a name="t_floating">floating point</a></td> |
| 358 | <td><tt>float, double</tt></td> |
| 359 | </tr> |
| 360 | <tr> |
| 361 | <td><a name="t_firstclass">first class</a></td> |
| 362 | <td><tt>bool, ubyte, sbyte, ushort, short,<br> |
| 363 | uint, int, ulong, long, float, double, <a href="#t_pointer">pointer</a></tt></td> |
| 364 | </tr> |
| 365 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 366 | </table> |
| 367 | </p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 368 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the |
| 369 | most important. Values of these types are the only ones which can be |
| 370 | produced by instructions, passed as arguments, or used as operands to |
| 371 | instructions. This means that all structures and arrays must be |
| 372 | manipulated either by pointer or by component.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 373 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 374 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 375 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 376 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 377 | <p>The real power in LLVM comes from the derived types in the system. |
| 378 | This is what allows a programmer to represent arrays, functions, |
| 379 | pointers, and other useful types. Note that these derived types may be |
| 380 | recursive: For example, it is possible to have a two dimensional array.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 381 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 382 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 383 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 384 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 385 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 386 | <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] | 387 | sequentially in memory. The array type requires a size (number of |
| 388 | elements) and an underlying data type.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 389 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 390 | <pre> [<# elements> x <elementtype>]<br></pre> |
| 391 | <p>The number of elements is a constant integer value, elementtype may |
| 392 | be any type with a size.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 393 | <h5>Examples:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 394 | <p> <tt>[40 x int ]</tt>: Array of 40 integer values.<br> |
| 395 | <tt>[41 x int ]</tt>: Array of 41 integer values.<br> |
| 396 | <tt>[40 x uint]</tt>: Array of 40 unsigned integer values.</p> |
| 397 | <p> </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 398 | <p>Here are some examples of multidimensional arrays:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 399 | <p> |
| 400 | <table border="0" cellpadding="0" cellspacing="0"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 401 | <tbody> |
| 402 | <tr> |
| 403 | <td><tt>[3 x [4 x int]]</tt></td> |
| 404 | <td>: 3x4 array integer values.</td> |
| 405 | </tr> |
| 406 | <tr> |
| 407 | <td><tt>[12 x [10 x float]]</tt></td> |
| 408 | <td>: 12x10 array of single precision floating point values.</td> |
| 409 | </tr> |
| 410 | <tr> |
| 411 | <td><tt>[2 x [3 x [4 x uint]]]</tt></td> |
| 412 | <td>: 2x3x4 array of unsigned integer values.</td> |
| 413 | </tr> |
| 414 | </tbody> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 415 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 416 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 417 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 418 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 419 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 420 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 421 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 422 | <p>The function type can be thought of as a function signature. It |
| 423 | consists of a return type and a list of formal parameter types. |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 424 | Function types are usually used to build virtual function tables |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 425 | (which are structures of pointers to functions), for indirect function |
| 426 | calls, and when defining a function.</p> |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 427 | <p> |
| 428 | The return type of a function type cannot be an aggregate type. |
| 429 | </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 430 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 431 | <pre> <returntype> (<parameter list>)<br></pre> |
| 432 | <p>Where '<tt><parameter list></tt>' is a comma-separated list of |
| 433 | type specifiers. Optionally, the parameter list may include a type <tt>...</tt>, |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 434 | which indicates that the function takes a variable number of arguments. |
| 435 | Variable argument functions can access their arguments with the <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 436 | href="#int_varargs">variable argument handling intrinsic</a> functions.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 437 | <h5>Examples:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 438 | <p> |
| 439 | <table border="0" cellpadding="0" cellspacing="0"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 440 | <tbody> |
| 441 | <tr> |
| 442 | <td><tt>int (int)</tt></td> |
| 443 | <td>: function taking an <tt>int</tt>, returning an <tt>int</tt></td> |
| 444 | </tr> |
| 445 | <tr> |
| 446 | <td><tt>float (int, int *) *</tt></td> |
| 447 | <td>: <a href="#t_pointer">Pointer</a> to a function that takes |
| 448 | an <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>, |
| 449 | returning <tt>float</tt>.</td> |
| 450 | </tr> |
| 451 | <tr> |
| 452 | <td><tt>int (sbyte *, ...)</tt></td> |
| 453 | <td>: A vararg function that takes at least one <a |
| 454 | href="#t_pointer">pointer</a> to <tt>sbyte</tt> (signed char in C), |
| 455 | which returns an integer. This is the signature for <tt>printf</tt> |
| 456 | in LLVM.</td> |
| 457 | </tr> |
| 458 | </tbody> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 459 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 460 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 461 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 462 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 463 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 464 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 465 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 466 | <p>The structure type is used to represent a collection of data members |
| 467 | together in memory. The packing of the field types is defined to match |
| 468 | the ABI of the underlying processor. The elements of a structure may |
| 469 | be any type that has a size.</p> |
| 470 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 471 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 472 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 473 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 474 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 475 | <pre> { <type list> }<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 476 | <h5>Examples:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 477 | <p> |
| 478 | <table border="0" cellpadding="0" cellspacing="0"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 479 | <tbody> |
| 480 | <tr> |
| 481 | <td><tt>{ int, int, int }</tt></td> |
| 482 | <td>: a triple of three <tt>int</tt> values</td> |
| 483 | </tr> |
| 484 | <tr> |
| 485 | <td><tt>{ float, int (int) * }</tt></td> |
| 486 | <td>: A pair, where the first element is a <tt>float</tt> and the |
| 487 | second element is a <a href="#t_pointer">pointer</a> to a <a |
| 488 | href="t_function">function</a> that takes an <tt>int</tt>, returning |
| 489 | an <tt>int</tt>.</td> |
| 490 | </tr> |
| 491 | </tbody> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 492 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 493 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 494 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 495 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 496 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 497 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 498 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 499 | <p>As in many languages, the pointer type represents a pointer or |
| 500 | reference to another object, which must live in memory.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 501 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 502 | <pre> <type> *<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 503 | <h5>Examples:</h5> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 504 | <p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 505 | <table border="0" cellpadding="0" cellspacing="0"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 506 | <tbody> |
| 507 | <tr> |
| 508 | <td><tt>[4x int]*</tt></td> |
| 509 | <td>: <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> |
| 510 | of four <tt>int</tt> values</td> |
| 511 | </tr> |
| 512 | <tr> |
| 513 | <td><tt>int (int *) *</tt></td> |
| 514 | <td>: A <a href="#t_pointer">pointer</a> to a <a |
| 515 | href="t_function">function</a> that takes an <tt>int</tt>, returning |
| 516 | an <tt>int</tt>.</td> |
| 517 | </tr> |
| 518 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 519 | </table> |
| 520 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 521 | </div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 522 | <!-- _______________________________________________________________________ --><!-- |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 523 | <div class="doc_subsubsection"> |
| 524 | <a name="t_packed">Packed Type</a> |
| 525 | </div> |
| 526 | |
| 527 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 528 | |
| 529 | Mention/decide that packed types work with saturation or not. Maybe have a packed+saturated type in addition to just a packed type.<p> |
| 530 | |
| 531 | Packed types should be 'nonsaturated' because standard data types are not saturated. Maybe have a saturated packed type?<p> |
| 532 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 533 | </div> |
| 534 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 535 | --><!-- *********************************************************************** --> |
| 536 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> |
| 537 | <!-- *********************************************************************** --><!-- ======================================================================= --> |
| 538 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 539 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 540 | <p>LLVM programs are composed of "Module"s, each of which is a |
| 541 | translation unit of the input programs. Each module consists of |
| 542 | functions, global variables, and symbol table entries. Modules may be |
| 543 | combined together with the LLVM linker, which merges function (and |
| 544 | global variable) definitions, resolves forward declarations, and merges |
| 545 | symbol table entries. Here is an example of the "hello world" module:</p> |
| 546 | <pre><i>; Declare the string constant as a global constant...</i> |
| 547 | <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a |
| 548 | href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 549 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 550 | <i>; External declaration of the puts function</i> |
| 551 | <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 552 | |
| 553 | <i>; Definition of main function</i> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 554 | int %main() { <i>; int()* </i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 555 | <i>; Convert [13x sbyte]* to sbyte *...</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 556 | %cast210 = <a |
| 557 | href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 558 | |
| 559 | <i>; Call puts function to write out the string to stdout...</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 560 | <a |
| 561 | href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i> |
| 562 | <a |
| 563 | href="#i_ret">ret</a> int 0<br>}<br></pre> |
| 564 | <p>This example is made up of a <a href="#globalvars">global variable</a> |
| 565 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" |
| 566 | function, and a <a href="#functionstructure">function definition</a> |
| 567 | for "<tt>main</tt>".</p> |
| 568 | <a name="linkage"> In general, a module is made up of a list of global |
| 569 | values, where both functions and global variables are global values. |
| 570 | Global values are represented by a pointer to a memory location (in |
| 571 | this case, a pointer to an array of char, and a pointer to a function), |
| 572 | and have one of the following linkage types:</a> |
| 573 | <p> </p> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 574 | <dl> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 575 | <a name="linkage_internal"> <dt><tt><b>internal</b></tt> </dt> |
| 576 | <dd>Global values with internal linkage are only directly accessible |
| 577 | by objects in the current module. In particular, linking code into a |
| 578 | module with an internal global value may cause the internal to be |
| 579 | renamed as necessary to avoid collisions. Because the symbol is |
| 580 | internal to the module, all references can be updated. This |
| 581 | corresponds to the notion of the '<tt>static</tt>' keyword in C, or the |
| 582 | idea of "anonymous namespaces" in C++. |
| 583 | <p> </p> |
| 584 | </dd> |
| 585 | </a><a name="linkage_linkonce"> <dt><tt><b>linkonce</b></tt>: </dt> |
| 586 | <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> |
| 587 | linkage, with the twist that linking together two modules defining the |
| 588 | same <tt>linkonce</tt> globals will cause one of the globals to be |
| 589 | discarded. This is typically used to implement inline functions. |
| 590 | Unreferenced <tt>linkonce</tt> globals are allowed to be discarded. |
| 591 | <p> </p> |
| 592 | </dd> |
| 593 | </a><a name="linkage_weak"> <dt><tt><b>weak</b></tt>: </dt> |
| 594 | <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> |
| 595 | linkage, except that unreferenced <tt>weak</tt> globals may not be |
| 596 | discarded. This is used to implement constructs in C such as "<tt>int |
| 597 | X;</tt>" at global scope. |
| 598 | <p> </p> |
| 599 | </dd> |
| 600 | </a><a name="linkage_appending"> <dt><tt><b>appending</b></tt>: </dt> |
| 601 | <dd>"<tt>appending</tt>" linkage may only be applied to global |
| 602 | variables of pointer to array type. When two global variables with |
| 603 | appending linkage are linked together, the two global arrays are |
| 604 | appended together. This is the LLVM, typesafe, equivalent of having |
| 605 | the system linker append together "sections" with identical names when |
| 606 | .o files are linked. |
| 607 | <p> </p> |
| 608 | </dd> |
| 609 | </a><a name="linkage_external"> <dt><tt><b>externally visible</b></tt>:</dt> |
| 610 | <dd>If none of the above identifiers are used, the global is |
| 611 | externally visible, meaning that it participates in linkage and can be |
| 612 | used to resolve external symbol references. |
| 613 | <p> </p> |
| 614 | </dd> |
| 615 | </a> |
| 616 | </dl> |
| 617 | <p> </p> |
| 618 | <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>" |
| 619 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" |
| 620 | variable and was linked with this one, one of the two would be renamed, |
| 621 | preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are |
| 622 | external (i.e., lacking any linkage declarations), they are accessible |
| 623 | outside of the current module. It is illegal for a function <i>declaration</i> |
| 624 | to have any linkage type other than "externally visible".</a></p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 625 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 626 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 627 | <div class="doc_subsection"> <a name="globalvars">Global Variables</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 628 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 629 | <p>Global variables define regions of memory allocated at compilation |
| 630 | time instead of run-time. Global variables may optionally be |
| 631 | initialized. A variable may be defined as a global "constant", which |
| 632 | indicates that the contents of the variable will never be modified |
| 633 | (opening options for optimization). Constants must always have an |
| 634 | initial value.</p> |
| 635 | <p>As SSA values, global variables define pointer values that are in |
| 636 | scope (i.e. they dominate) for all basic blocks in the program. Global |
| 637 | variables always define a pointer to their "content" type because they |
| 638 | describe a region of memory, and all memory objects in LLVM are |
| 639 | accessed through pointers.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 640 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 641 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 642 | <div class="doc_subsection"> <a name="functionstructure">Functions</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 643 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 644 | <p>LLVM function definitions are composed of a (possibly empty) |
| 645 | argument list, an opening curly brace, a list of basic blocks, and a |
| 646 | closing curly brace. LLVM function declarations are defined with the "<tt>declare</tt>" |
| 647 | keyword, a function name, and a function signature.</p> |
| 648 | <p>A function definition contains a list of basic blocks, forming the |
| 649 | CFG for the function. Each basic block may optionally start with a |
| 650 | label (giving the basic block a symbol table entry), contains a list of |
| 651 | instructions, and ends with a <a href="#terminators">terminator</a> |
| 652 | instruction (such as a branch or function return).</p> |
| 653 | <p>The first basic block in program is special in two ways: it is |
| 654 | immediately executed on entrance to the function, and it is not allowed |
| 655 | to have predecessor basic blocks (i.e. there can not be any branches to |
| 656 | the entry block of a function). Because the block can have no |
| 657 | predecessors, it also cannot have any <a href="#i_phi">PHI nodes</a>.</p> |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 658 | <p> |
| 659 | LLVM functions are identified by their name and type signature. Hence, two |
| 660 | functions with the same name but different parameter lists or return values |
| 661 | are considered different functions, and LLVM will resolves references to each |
| 662 | appropriately. |
| 663 | </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 664 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 665 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 666 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> |
| 667 | <!-- *********************************************************************** --> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 668 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 669 | <p>The LLVM instruction set consists of several different |
| 670 | classifications of instructions: <a href="#terminators">terminator |
| 671 | instructions</a>, <a href="#binaryops">binary instructions</a>, <a |
| 672 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other |
| 673 | instructions</a>.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 674 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 675 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 676 | <div class="doc_subsection"> <a name="terminators">Terminator |
| 677 | Instructions</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 678 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 679 | <p>As mentioned <a href="#functionstructure">previously</a>, every |
| 680 | basic block in a program ends with a "Terminator" instruction, which |
| 681 | indicates which block should be executed after the current block is |
| 682 | finished. These terminator instructions typically yield a '<tt>void</tt>' |
| 683 | value: they produce control flow, not values (the one exception being |
| 684 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 685 | <p>There are five different terminator instructions: the '<a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 686 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' |
| 687 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, |
| 688 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, and the '<a |
| 689 | href="#i_unwind"><tt>unwind</tt></a>' instruction.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 690 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 691 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 692 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' |
| 693 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 694 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 695 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 696 | <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] | 697 | ret void <i>; Return from void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 698 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 699 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 700 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and a |
| 701 | value) from a function, back to the caller.</p> |
| 702 | <p>There are two forms of the '<tt>ret</tt>' instructruction: one that |
| 703 | returns a value and then causes control flow, and one that just causes |
| 704 | control flow to occur.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 705 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 706 | <p>The '<tt>ret</tt>' instruction may return any '<a |
| 707 | href="#t_firstclass">first class</a>' type. Notice that a function is |
| 708 | not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>' |
| 709 | instruction inside of the function that returns a value that does not |
| 710 | match the return type of the function.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 711 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 712 | <p>When the '<tt>ret</tt>' instruction is executed, control flow |
| 713 | returns back to the calling function's context. If the caller is a "<a |
| 714 | href="#i_call"><tt>call</tt></a> instruction, execution continues at |
| 715 | the instruction after the call. If the caller was an "<a |
| 716 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues |
| 717 | at the beginning "normal" of the destination block. If the instruction |
| 718 | returns a value, that value shall set the call or invoke instruction's |
| 719 | return value.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 720 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 721 | <pre> ret int 5 <i>; Return an integer value of 5</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 722 | ret void <i>; Return from a void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 723 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 724 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 725 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 726 | <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] | 727 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 728 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 729 | <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] | 730 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 731 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 732 | <p>The '<tt>br</tt>' instruction is used to cause control flow to |
| 733 | transfer to a different basic block in the current function. There are |
| 734 | two forms of this instruction, corresponding to a conditional branch |
| 735 | and an unconditional branch.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 736 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 737 | <p>The conditional branch form of the '<tt>br</tt>' instruction takes a |
| 738 | single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The |
| 739 | unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' |
| 740 | value as a target.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 741 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 742 | <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>' |
| 743 | argument is evaluated. If the value is <tt>true</tt>, control flows |
| 744 | to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>, |
| 745 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 746 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 747 | <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 |
| 748 | 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] | 749 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 750 | <!-- _______________________________________________________________________ --> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 751 | <div class="doc_subsubsection"> |
| 752 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> |
| 753 | </div> |
| 754 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 755 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 756 | <h5>Syntax:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 757 | |
| 758 | <pre> |
| 759 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] |
| 760 | </pre> |
| 761 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 762 | <h5>Overview:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 763 | |
| 764 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of |
| 765 | several different places. It is a generalization of the '<tt>br</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 766 | instruction, allowing a branch to occur to one of many possible |
| 767 | destinations.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 768 | |
| 769 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 770 | <h5>Arguments:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 771 | |
| 772 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer |
| 773 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and |
| 774 | an array of pairs of comparison value constants and '<tt>label</tt>'s. The |
| 775 | table is not allowed to contain duplicate constant entries.</p> |
| 776 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 777 | <h5>Semantics:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 778 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 779 | <p>The <tt>switch</tt> instruction specifies a table of values and |
| 780 | destinations. When the '<tt>switch</tt>' instruction is executed, this |
| 781 | table is searched for the given value. If the value is found, the |
| 782 | corresponding destination is branched to, otherwise the default value |
| 783 | it transfered to.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 784 | |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame^] | 785 | <h5>Implementation:</h5> |
| 786 | |
| 787 | <p>Depending on properties of the target machine and the particular |
| 788 | <tt>switch</tt> instruction, this instruction may be code generated in different |
| 789 | ways, for example as a series of chained conditional branches, or with a lookup |
| 790 | table.</p> |
| 791 | |
| 792 | <h5>Example:</h5> |
| 793 | |
| 794 | <pre> |
| 795 | <i>; Emulate a conditional br instruction</i> |
| 796 | %Val = <a href="#i_cast">cast</a> bool %value to int |
| 797 | switch int %Val, label %truedest [int 0, label %falsedest ] |
| 798 | |
| 799 | <i>; Emulate an unconditional br instruction</i> |
| 800 | switch uint 0, label %dest [ ] |
| 801 | |
| 802 | <i>; Implement a jump table:</i> |
| 803 | switch uint %val, label %otherwise [ uint 0, label %onzero |
| 804 | uint 1, label %onone |
| 805 | uint 2, label %ontwo ] |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 806 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 807 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 808 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 809 | <div class="doc_subsubsection"> <a name="i_invoke">'<tt>invoke</tt>' |
| 810 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 811 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 812 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 813 | <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] | 814 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 815 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a |
| 816 | specified function, with the possibility of control flow transfer to |
| 817 | either the '<tt>normal</tt>' <tt>label</tt> label or the '<tt>exception</tt>'<tt>label</tt>. |
| 818 | If the callee function returns with the "<tt><a href="#i_ret">ret</a></tt>" |
| 819 | instruction, control flow will return to the "normal" label. If the |
| 820 | callee (or any indirect callees) returns with the "<a href="#i_unwind"><tt>unwind</tt></a>" |
| 821 | instruction, control is interrupted, and continued at the dynamically |
| 822 | nearest "except" label.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 823 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 824 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 825 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 826 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the |
| 827 | pointer to function value being invoked. In most cases, this is a |
| 828 | direct function invocation, but indirect <tt>invoke</tt>s are just as |
| 829 | possible, branching off an arbitrary pointer to function value. </li> |
| 830 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer |
| 831 | to a function to be invoked. </li> |
| 832 | <li>'<tt>function args</tt>': argument list whose types match the |
| 833 | function signature argument types. If the function signature indicates |
| 834 | the function accepts a variable number of arguments, the extra |
| 835 | arguments can be specified. </li> |
| 836 | <li>'<tt>normal label</tt>': the label reached when the called |
| 837 | function executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> |
| 838 | <li>'<tt>exception label</tt>': the label reached when a callee |
| 839 | 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] | 840 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 841 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 842 | <p>This instruction is designed to operate as a standard '<tt><a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 843 | href="#i_call">call</a></tt>' instruction in most regards. The |
| 844 | primary difference is that it establishes an association with a label, |
| 845 | which is used by the runtime library to unwind the stack.</p> |
| 846 | <p>This instruction is used in languages with destructors to ensure |
| 847 | that proper cleanup is performed in the case of either a <tt>longjmp</tt> |
| 848 | or a thrown exception. Additionally, this is important for |
| 849 | implementation of '<tt>catch</tt>' clauses in high-level languages that |
| 850 | support them.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 851 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 852 | <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] | 853 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 854 | </div> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 855 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 856 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' |
| 857 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 858 | <div class="doc_text"> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 859 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 860 | <pre> unwind<br></pre> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 861 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 862 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing |
| 863 | control flow at the first callee in the dynamic call stack which used |
| 864 | an <a href="#i_invoke"><tt>invoke</tt></a> instruction to perform the |
| 865 | call. This is primarily used to implement exception handling.</p> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 866 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 867 | <p>The '<tt>unwind</tt>' intrinsic causes execution of the current |
| 868 | function to immediately halt. The dynamic call stack is then searched |
| 869 | for the first <a href="#i_invoke"><tt>invoke</tt></a> instruction on |
| 870 | the call stack. Once found, execution continues at the "exceptional" |
| 871 | destination block specified by the <tt>invoke</tt> instruction. If |
| 872 | there is no <tt>invoke</tt> instruction in the dynamic call chain, |
| 873 | undefined behavior results.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 874 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 875 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 876 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 877 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 878 | <p>Binary operators are used to do most of the computation in a |
| 879 | program. They require two operands, execute an operation on them, and |
| 880 | produce a single value. The result value of a binary operator is not |
| 881 | necessarily the same type as its operands.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 882 | <p>There are several different binary operators:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 883 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 884 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 885 | <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>' |
| 886 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 887 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 888 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 889 | <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 890 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 891 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 892 | <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] | 893 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 894 | <p>The two arguments to the '<tt>add</tt>' instruction must be either <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 895 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
| 896 | values. Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 897 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 898 | <p>The value produced is the integer or floating point sum of the two |
| 899 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 900 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 901 | <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] | 902 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 903 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 904 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 905 | <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>' |
| 906 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 907 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 908 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 909 | <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 910 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 911 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 912 | <p>The '<tt>sub</tt>' instruction returns the difference of its two |
| 913 | operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 914 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>' |
| 915 | instruction present in most other intermediate representations.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 916 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 917 | <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] | 918 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
| 919 | values. Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 920 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 921 | <p>The value produced is the integer or floating point difference of |
| 922 | the two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 923 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 924 | <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] | 925 | <result> = sub int 0, %val <i>; yields {int}:result = -%var</i> |
| 926 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 927 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 928 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 929 | <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>' |
| 930 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 931 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 932 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 933 | <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 934 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 935 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 936 | <p>The '<tt>mul</tt>' instruction returns the product of its two |
| 937 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 938 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 939 | <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] | 940 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
| 941 | values. Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 942 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 943 | <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] | 944 | two operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 945 | <p>There is no signed vs unsigned multiplication. The appropriate |
| 946 | action is taken based on the type of the operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 947 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 948 | <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] | 949 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 950 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 951 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 952 | <div class="doc_subsubsection"> <a name="i_div">'<tt>div</tt>' |
| 953 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 954 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 955 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 956 | <pre> <result> = div <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 957 | </pre> |
| 958 | <h5>Overview:</h5> |
| 959 | <p>The '<tt>div</tt>' instruction returns the quotient of its two |
| 960 | operands.</p> |
| 961 | <h5>Arguments:</h5> |
| 962 | <p>The two arguments to the '<tt>div</tt>' instruction must be either <a |
| 963 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
| 964 | values. Both arguments must have identical types.</p> |
| 965 | <h5>Semantics:</h5> |
| 966 | <p>The value produced is the integer or floating point quotient of the |
| 967 | two operands.</p> |
| 968 | <h5>Example:</h5> |
| 969 | <pre> <result> = div int 4, %var <i>; yields {int}:result = 4 / %var</i> |
| 970 | </pre> |
| 971 | </div> |
| 972 | <!-- _______________________________________________________________________ --> |
| 973 | <div class="doc_subsubsection"> <a name="i_rem">'<tt>rem</tt>' |
| 974 | Instruction</a> </div> |
| 975 | <div class="doc_text"> |
| 976 | <h5>Syntax:</h5> |
| 977 | <pre> <result> = rem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 978 | </pre> |
| 979 | <h5>Overview:</h5> |
| 980 | <p>The '<tt>rem</tt>' instruction returns the remainder from the |
| 981 | division of its two operands.</p> |
| 982 | <h5>Arguments:</h5> |
| 983 | <p>The two arguments to the '<tt>rem</tt>' instruction must be either <a |
| 984 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
| 985 | values. Both arguments must have identical types.</p> |
| 986 | <h5>Semantics:</h5> |
| 987 | <p>This returns the <i>remainder</i> of a division (where the result |
| 988 | has the same sign as the divisor), not the <i>modulus</i> (where the |
| 989 | result has the same sign as the dividend) of a value. For more |
| 990 | information about the difference, see: <a |
| 991 | href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The |
| 992 | Math Forum</a>.</p> |
| 993 | <h5>Example:</h5> |
| 994 | <pre> <result> = rem int 4, %var <i>; yields {int}:result = 4 % %var</i> |
| 995 | </pre> |
| 996 | </div> |
| 997 | <!-- _______________________________________________________________________ --> |
| 998 | <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>' |
| 999 | Instructions</a> </div> |
| 1000 | <div class="doc_text"> |
| 1001 | <h5>Syntax:</h5> |
| 1002 | <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1003 | <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1004 | <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1005 | <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1006 | <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1007 | <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1008 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1009 | <h5>Overview:</h5> |
| 1010 | <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean |
| 1011 | value based on a comparison of their two operands.</p> |
| 1012 | <h5>Arguments:</h5> |
| 1013 | <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must |
| 1014 | be of <a href="#t_firstclass">first class</a> type (it is not possible |
| 1015 | to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' |
| 1016 | or '<tt>void</tt>' values, etc...). Both arguments must have identical |
| 1017 | types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1018 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1019 | <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1020 | value if both operands are equal.<br> |
| 1021 | The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1022 | value if both operands are unequal.<br> |
| 1023 | The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1024 | value if the first operand is less than the second operand.<br> |
| 1025 | The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1026 | value if the first operand is greater than the second operand.<br> |
| 1027 | The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1028 | value if the first operand is less than or equal to the second operand.<br> |
| 1029 | The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1030 | value if the first operand is greater than or equal to the second |
| 1031 | operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1032 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1033 | <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1034 | <result> = setne float 4, 5 <i>; yields {bool}:result = true</i> |
| 1035 | <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i> |
| 1036 | <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1037 | <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i> |
| 1038 | <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1039 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1040 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1041 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1042 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary |
| 1043 | Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1044 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1045 | <p>Bitwise binary operators are used to do various forms of |
| 1046 | bit-twiddling in a program. They are generally very efficient |
| 1047 | instructions, and can commonly be strength reduced from other |
| 1048 | instructions. They require two operands, execute an operation on them, |
| 1049 | and produce a single value. The resulting value of the bitwise binary |
| 1050 | operators is always the same type as its first operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1051 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1052 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1053 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' |
| 1054 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1055 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1056 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1057 | <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1058 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1059 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1060 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of |
| 1061 | its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1062 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1063 | <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] | 1064 | href="#t_integral">integral</a> values. Both arguments must have |
| 1065 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1066 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1067 | <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] | 1068 | <p> </p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1069 | <center> |
| 1070 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1071 | <tbody> |
| 1072 | <tr> |
| 1073 | <td>In0</td> |
| 1074 | <td>In1</td> |
| 1075 | <td>Out</td> |
| 1076 | </tr> |
| 1077 | <tr> |
| 1078 | <td>0</td> |
| 1079 | <td>0</td> |
| 1080 | <td>0</td> |
| 1081 | </tr> |
| 1082 | <tr> |
| 1083 | <td>0</td> |
| 1084 | <td>1</td> |
| 1085 | <td>0</td> |
| 1086 | </tr> |
| 1087 | <tr> |
| 1088 | <td>1</td> |
| 1089 | <td>0</td> |
| 1090 | <td>0</td> |
| 1091 | </tr> |
| 1092 | <tr> |
| 1093 | <td>1</td> |
| 1094 | <td>1</td> |
| 1095 | <td>1</td> |
| 1096 | </tr> |
| 1097 | </tbody> |
| 1098 | </table> |
| 1099 | </center> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1100 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1101 | <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] | 1102 | <result> = and int 15, 40 <i>; yields {int}:result = 8</i> |
| 1103 | <result> = and int 4, 8 <i>; yields {int}:result = 0</i> |
| 1104 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1105 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1106 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1107 | <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] | 1108 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1109 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1110 | <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1111 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1112 | <h5>Overview:</h5> |
| 1113 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive |
| 1114 | or of its two operands.</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>The two arguments to the '<tt>or</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1117 | href="#t_integral">integral</a> values. Both arguments must have |
| 1118 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1119 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1120 | <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] | 1121 | <p> </p> |
| 1122 | <center> |
| 1123 | <table border="1" cellspacing="0" cellpadding="4"> |
| 1124 | <tbody> |
| 1125 | <tr> |
| 1126 | <td>In0</td> |
| 1127 | <td>In1</td> |
| 1128 | <td>Out</td> |
| 1129 | </tr> |
| 1130 | <tr> |
| 1131 | <td>0</td> |
| 1132 | <td>0</td> |
| 1133 | <td>0</td> |
| 1134 | </tr> |
| 1135 | <tr> |
| 1136 | <td>0</td> |
| 1137 | <td>1</td> |
| 1138 | <td>1</td> |
| 1139 | </tr> |
| 1140 | <tr> |
| 1141 | <td>1</td> |
| 1142 | <td>0</td> |
| 1143 | <td>1</td> |
| 1144 | </tr> |
| 1145 | <tr> |
| 1146 | <td>1</td> |
| 1147 | <td>1</td> |
| 1148 | <td>1</td> |
| 1149 | </tr> |
| 1150 | </tbody> |
| 1151 | </table> |
| 1152 | </center> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1153 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1154 | <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] | 1155 | <result> = or int 15, 40 <i>; yields {int}:result = 47</i> |
| 1156 | <result> = or int 4, 8 <i>; yields {int}:result = 12</i> |
| 1157 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1158 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1159 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1160 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' |
| 1161 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1162 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1163 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1164 | <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1165 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1166 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1167 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive |
| 1168 | or of its two operands. The <tt>xor</tt> is used to implement the |
| 1169 | "one's complement" operation, which is the "~" operator in C.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1170 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1171 | <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] | 1172 | href="#t_integral">integral</a> values. Both arguments must have |
| 1173 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1174 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1175 | <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] | 1176 | <p> </p> |
| 1177 | <center> |
| 1178 | <table border="1" cellspacing="0" cellpadding="4"> |
| 1179 | <tbody> |
| 1180 | <tr> |
| 1181 | <td>In0</td> |
| 1182 | <td>In1</td> |
| 1183 | <td>Out</td> |
| 1184 | </tr> |
| 1185 | <tr> |
| 1186 | <td>0</td> |
| 1187 | <td>0</td> |
| 1188 | <td>0</td> |
| 1189 | </tr> |
| 1190 | <tr> |
| 1191 | <td>0</td> |
| 1192 | <td>1</td> |
| 1193 | <td>1</td> |
| 1194 | </tr> |
| 1195 | <tr> |
| 1196 | <td>1</td> |
| 1197 | <td>0</td> |
| 1198 | <td>1</td> |
| 1199 | </tr> |
| 1200 | <tr> |
| 1201 | <td>1</td> |
| 1202 | <td>1</td> |
| 1203 | <td>0</td> |
| 1204 | </tr> |
| 1205 | </tbody> |
| 1206 | </table> |
| 1207 | </center> |
| 1208 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1209 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1210 | <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] | 1211 | <result> = xor int 15, 40 <i>; yields {int}:result = 39</i> |
| 1212 | <result> = xor int 4, 8 <i>; yields {int}:result = 12</i> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1213 | <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1214 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1215 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1216 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1217 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' |
| 1218 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1219 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1220 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1221 | <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1222 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1223 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1224 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to |
| 1225 | the left a specified number of bits.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1226 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1227 | <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] | 1228 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' |
| 1229 | type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1230 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1231 | <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] | 1232 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1233 | <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] | 1234 | <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i> |
| 1235 | <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i> |
| 1236 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1237 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1238 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1239 | <div class="doc_subsubsection"> <a name="i_shr">'<tt>shr</tt>' |
| 1240 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1241 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1242 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1243 | <pre> <result> = shr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1244 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1245 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1246 | <p>The '<tt>shr</tt>' instruction returns the first operand shifted to |
| 1247 | the right a specified number of bits.</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 first argument to the '<tt>shr</tt>' instruction must be an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1250 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' |
| 1251 | type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1252 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1253 | <p>If the first argument is a <a href="#t_signed">signed</a> type, the |
| 1254 | most significant bit is duplicated in the newly free'd bit positions. |
| 1255 | If the first argument is unsigned, zero bits shall fill the empty |
| 1256 | positions.</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> = shr int 4, ubyte %var <i>; yields {int}:result = 4 >> %var</i> |
Chris Lattner | 8c6bb90 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1259 | <result> = shr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1260 | <result> = shr int 4, ubyte 2 <i>; yields {int}:result = 1</i> |
Chris Lattner | 8c6bb90 | 2003-06-18 21:30:51 +0000 | [diff] [blame] | 1261 | <result> = shr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i> |
| 1262 | <result> = shr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1263 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1264 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1265 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1266 | <div class="doc_subsection"> <a name="memoryops">Memory Access |
| 1267 | Operations</a></div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1268 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1269 | <p>A key design point of an SSA-based representation is how it |
| 1270 | represents memory. In LLVM, no memory locations are in SSA form, which |
| 1271 | makes things very simple. This section describes how to read, write, |
| 1272 | allocate and free memory in LLVM.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1273 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1274 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1275 | <div class="doc_subsubsection"> <a name="i_malloc">'<tt>malloc</tt>' |
| 1276 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1277 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1278 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1279 | <pre> <result> = malloc <type>, uint <NumElements> <i>; yields {type*}:result</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1280 | <result> = malloc <type> <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1281 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1282 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1283 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system |
| 1284 | heap and returns a pointer to it.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1285 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1286 | <p>The the '<tt>malloc</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
| 1287 | bytes of memory from the operating system, and returns a pointer of the |
| 1288 | appropriate type to the program. The second form of the instruction is |
| 1289 | a shorter version of the first instruction that defaults to allocating |
| 1290 | one element.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1291 | <p>'<tt>type</tt>' must be a sized type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1292 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1293 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and |
| 1294 | a pointer is returned.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1295 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1296 | <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] | 1297 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1298 | %size = <a |
| 1299 | 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] | 1300 | %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i> |
| 1301 | %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] | 1302 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1303 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1304 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1305 | <div class="doc_subsubsection"> <a name="i_free">'<tt>free</tt>' |
| 1306 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1307 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1308 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1309 | <pre> free <type> <value> <i>; yields {void}</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1310 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1311 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1312 | <p>The '<tt>free</tt>' instruction returns memory back to the unused |
| 1313 | memory heap, to be reallocated in the future.</p> |
| 1314 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1315 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1316 | <p>'<tt>value</tt>' shall be a pointer value that points to a value |
| 1317 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' |
| 1318 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1319 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1320 | <p>Access to the memory pointed to by the pointer is not longer defined |
| 1321 | after this instruction executes.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1322 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1323 | <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] | 1324 | free [4 x ubyte]* %array |
| 1325 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1326 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1327 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1328 | <div class="doc_subsubsection"> <a name="i_alloca">'<tt>alloca</tt>' |
| 1329 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1330 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1331 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1332 | <pre> <result> = alloca <type>, uint <NumElements> <i>; yields {type*}:result</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1333 | <result> = alloca <type> <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1334 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1335 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1336 | <p>The '<tt>alloca</tt>' instruction allocates memory on the current |
| 1337 | stack frame of the procedure that is live until the current function |
| 1338 | returns to its caller.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1339 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1340 | <p>The the '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
| 1341 | bytes of memory on the runtime stack, returning a pointer of the |
| 1342 | appropriate type to the program. The second form of the instruction is |
| 1343 | 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] | 1344 | <p>'<tt>type</tt>' may be any sized type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1345 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1346 | <p>Memory is allocated, a pointer is returned. '<tt>alloca</tt>'d |
| 1347 | memory is automatically released when the function returns. The '<tt>alloca</tt>' |
| 1348 | instruction is commonly used to represent automatic variables that must |
| 1349 | have an address available. When the function returns (either with the <tt><a |
| 1350 | 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] | 1351 | instructions), the memory is reclaimed.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1352 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1353 | <pre> %ptr = alloca int <i>; yields {int*}:ptr</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1354 | %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1355 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1356 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1357 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1358 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' |
| 1359 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1360 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1361 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1362 | <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] | 1363 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1364 | <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] | 1365 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1366 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory |
| 1367 | address to load from. The pointer must point to a <a |
| 1368 | href="t_firstclass">first class</a> type. If the <tt>load</tt> is |
| 1369 | marked as <tt>volatile</tt> then the optimizer is not allowed to modify |
| 1370 | the number or order of execution of this <tt>load</tt> with other |
| 1371 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> |
| 1372 | instructions. </p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1373 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1374 | <p>The location of memory pointed to is loaded.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1375 | <h5>Examples:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1376 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 1377 | <a |
| 1378 | 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] | 1379 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 1380 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1381 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1382 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1383 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' |
| 1384 | Instruction</a> </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1385 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1386 | <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | f065107 | 2003-09-08 18:27:49 +0000 | [diff] [blame] | 1387 | volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1388 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1389 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1390 | <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] | 1391 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1392 | <p>There are two arguments to the '<tt>store</tt>' instruction: a value |
| 1393 | to store and an address to store it into. The type of the '<tt><pointer></tt>' |
| 1394 | operand must be a pointer to the type of the '<tt><value></tt>' |
| 1395 | operand. If the <tt>store</tt> is marked as <tt>volatile</tt> then the |
| 1396 | optimizer is not allowed to modify the number or order of execution of |
| 1397 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a |
| 1398 | href="#i_store">store</a></tt> instructions.</p> |
| 1399 | <h5>Semantics:</h5> |
| 1400 | <p>The contents of memory are updated to contain '<tt><value></tt>' |
| 1401 | at the location specified by the '<tt><pointer></tt>' operand.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1402 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1403 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 1404 | <a |
| 1405 | 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] | 1406 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 1407 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 1408 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1409 | <div class="doc_subsubsection"> <a name="i_getelementptr">'<tt>getelementptr</tt>' |
| 1410 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1411 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1412 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1413 | <pre> <result> = getelementptr <ty>* <ptrval>{, long <aidx>|, ubyte <sidx>}*<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1414 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1415 | <p>The '<tt>getelementptr</tt>' instruction is used to get the address |
| 1416 | of a subelement of an aggregate data structure.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1417 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1418 | <p>This instruction takes a list of <tt>long</tt> values and <tt>ubyte</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1419 | constants that indicate what form of addressing to perform. The actual |
| 1420 | types of the arguments provided depend on the type of the first pointer |
| 1421 | argument. The '<tt>getelementptr</tt>' instruction is used to index |
| 1422 | down through the type levels of a structure.</p> |
| 1423 | <p>For example, let's consider a C code fragment and how it gets |
| 1424 | compiled to LLVM:</p> |
| 1425 | <pre>struct RT {<br> char A;<br> int B[10][20];<br> char C;<br>};<br>struct ST {<br> int X;<br> double Y;<br> struct RT Z;<br>};<br><br>int *foo(struct ST *s) {<br> return &s[1].Z.B[5][13];<br>}<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1426 | <p>The LLVM code generated by the GCC frontend is:</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1427 | <pre>%RT = type { sbyte, [10 x [20 x int]], sbyte }<br>%ST = type { int, double, %RT }<br><br>int* "foo"(%ST* %s) {<br> %reg = getelementptr %ST* %s, long 1, ubyte 2, ubyte 1, long 5, long 13<br> ret int* %reg<br>}<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1428 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1429 | <p>The index types specified for the '<tt>getelementptr</tt>' |
| 1430 | instruction depend on the pointer type that is being index into. <a |
| 1431 | href="t_pointer">Pointer</a> and <a href="t_array">array</a> types |
| 1432 | require '<tt>long</tt>' values, and <a href="t_struct">structure</a> |
| 1433 | types require '<tt>ubyte</tt>' <b>constants</b>.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1434 | <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1435 | type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, |
| 1436 | double, %RT }</tt>' type, a structure. The second index indexes into |
| 1437 | the third element of the structure, yielding a '<tt>%RT</tt>' = '<tt>{ |
| 1438 | sbyte, [10 x [20 x int]], sbyte }</tt>' type, another structure. The |
| 1439 | third index indexes into the second element of the structure, yielding |
| 1440 | a '<tt>[10 x [20 x int]]</tt>' type, an array. The two dimensions of |
| 1441 | the array are subscripted into, yielding an '<tt>int</tt>' type. The '<tt>getelementptr</tt>' |
| 1442 | instruction return a pointer to this element, thus yielding a '<tt>int*</tt>' |
| 1443 | type.</p> |
| 1444 | <p>Note that it is perfectly legal to index partially through a |
| 1445 | structure, returning a pointer to an inner element. Because of this, |
| 1446 | the LLVM code for the given testcase is equivalent to:</p> |
| 1447 | <pre>int* "foo"(%ST* %s) {<br> %t1 = getelementptr %ST* %s , long 1 <i>; yields %ST*:%t1</i> |
Chris Lattner | 3dfa10b | 2002-12-13 06:01:21 +0000 | [diff] [blame] | 1448 | %t2 = getelementptr %ST* %t1, long 0, ubyte 2 <i>; yields %RT*:%t2</i> |
| 1449 | %t3 = getelementptr %RT* %t2, long 0, ubyte 1 <i>; yields [10 x [20 x int]]*:%t3</i> |
| 1450 | %t4 = getelementptr [10 x [20 x int]]* %t3, long 0, long 5 <i>; yields [20 x int]*:%t4</i> |
| 1451 | %t5 = getelementptr [20 x int]* %t4, long 0, long 13 <i>; yields int*:%t5</i> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1452 | ret int* %t5 |
| 1453 | } |
| 1454 | </pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1455 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1456 | <pre> <i>; yields [12 x ubyte]*:aptr</i> |
| 1457 | %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, ubyte 1<br></pre> |
| 1458 | <h5> Note To The Novice:</h5> |
| 1459 | When using indexing into global arrays with the '<tt>getelementptr</tt>' |
| 1460 | instruction, you must remember that the </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1461 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1462 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1463 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1464 | <p>The instructions in this catagory are the "miscellaneous" |
| 1465 | instructions, which defy better classification.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1466 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1467 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1468 | <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>' |
| 1469 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1470 | <div class="doc_text"> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1471 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1472 | <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1473 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1474 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in |
| 1475 | the SSA graph representing the function.</p> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1476 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1477 | <p>The type of the incoming values are specified with the first type |
| 1478 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs |
| 1479 | as arguments, with one pair for each predecessor basic block of the |
| 1480 | current block. Only values of <a href="#t_firstclass">first class</a> |
| 1481 | type may be used as the value arguments to the PHI node. Only labels |
| 1482 | may be used as the label arguments.</p> |
| 1483 | <p>There must be no non-phi instructions between the start of a basic |
| 1484 | block and the PHI instructions: i.e. PHI instructions must be first in |
| 1485 | a basic block.</p> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1486 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1487 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the |
| 1488 | value specified by the parameter, depending on which basic block we |
| 1489 | came from in the last <a href="#terminators">terminator</a> instruction.</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1490 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1491 | <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] | 1492 | </div> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1493 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1494 | <div class="doc_subsubsection"> <a name="i_cast">'<tt>cast .. to</tt>' |
| 1495 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1496 | <div class="doc_text"> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1497 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1498 | <pre> <result> = cast <ty> <value> to <ty2> <i>; yields ty2</i> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1499 | </pre> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1500 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1501 | <p>The '<tt>cast</tt>' instruction is used as the primitive means to |
| 1502 | convert integers to floating point, change data type sizes, and break |
| 1503 | type safety (by casting pointers).</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1504 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1505 | <p>The '<tt>cast</tt>' instruction takes a value to cast, which must be |
| 1506 | a first class value, and a type to cast it to, which must also be a <a |
| 1507 | href="#t_firstclass">first class</a> type.</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1508 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1509 | <p>This instruction follows the C rules for explicit casts when |
| 1510 | determining how the data being cast must change to fit in its new |
| 1511 | container.</p> |
| 1512 | <p>When casting to bool, any value that would be considered true in the |
| 1513 | context of a C '<tt>if</tt>' condition is converted to the boolean '<tt>true</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1514 | values, all else are '<tt>false</tt>'.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1515 | <p>When extending an integral value from a type of one signness to |
| 1516 | another (for example '<tt>sbyte</tt>' to '<tt>ulong</tt>'), the value |
| 1517 | is sign-extended if the <b>source</b> value is signed, and |
| 1518 | zero-extended if the source value is unsigned. <tt>bool</tt> values |
| 1519 | are always zero extended into either zero or one.</p> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1520 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1521 | <pre> %X = cast int 257 to ubyte <i>; yields ubyte:1</i> |
Chris Lattner | 7bae395 | 2002-06-25 18:03:17 +0000 | [diff] [blame] | 1522 | %Y = cast int 123 to bool <i>; yields bool:true</i> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1523 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1524 | </div> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 1525 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1526 | <div class="doc_subsubsection"> <a name="i_call">'<tt>call</tt>' |
| 1527 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1528 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1529 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1530 | <pre> <result> = call <ty>* <fnptrval>(<param list>)<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1531 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1532 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1533 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1534 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1535 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1536 | <li> |
| 1537 | <p>'<tt>ty</tt>': shall be the signature of the pointer to function |
| 1538 | value being invoked. The argument types must match the types implied |
| 1539 | by this signature.</p> |
| 1540 | </li> |
| 1541 | <li> |
| 1542 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a |
| 1543 | function to be invoked. In most cases, this is a direct function |
| 1544 | invocation, but indirect <tt>call</tt>s are just as possible, |
| 1545 | calling an arbitrary pointer to function values.</p> |
| 1546 | </li> |
| 1547 | <li> |
| 1548 | <p>'<tt>function args</tt>': argument list whose types match the |
| 1549 | function signature argument types. If the function signature |
| 1550 | indicates the function accepts a variable number of arguments, the |
| 1551 | extra arguments can be specified.</p> |
| 1552 | </li> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1553 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1554 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1555 | <p>The '<tt>call</tt>' instruction is used to cause control flow to |
| 1556 | transfer to a specified function, with its incoming arguments bound to |
| 1557 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' |
| 1558 | instruction in the called function, control flow continues with the |
| 1559 | instruction after the function call, and the return value of the |
| 1560 | function is bound to the result argument. This is a simpler case of |
| 1561 | the <a href="#i_invoke">invoke</a> instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1562 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1563 | <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] | 1564 | </div> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1565 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1566 | <div class="doc_subsubsection"> <a name="i_vanext">'<tt>vanext</tt>' |
| 1567 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1568 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1569 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1570 | <pre> <resultarglist> = vanext <va_list> <arglist>, <argty><br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1571 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1572 | <p>The '<tt>vanext</tt>' instruction is used to access arguments passed |
| 1573 | through the "variable argument" area of a function call. It is used to |
| 1574 | implement the <tt>va_arg</tt> macro in C.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1575 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1576 | <p>This instruction takes a <tt>valist</tt> value and the type of the |
| 1577 | argument. It returns another <tt>valist</tt>.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1578 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1579 | <p>The '<tt>vanext</tt>' instruction advances the specified <tt>valist</tt> |
| 1580 | past an argument of the specified type. In conjunction with the <a |
| 1581 | href="#i_vaarg"><tt>vaarg</tt></a> instruction, it is used to implement |
| 1582 | the <tt>va_arg</tt> macro available in C. For more information, see |
| 1583 | the variable argument handling <a href="#int_varargs">Intrinsic |
| 1584 | Functions</a>.</p> |
| 1585 | <p>It is legal for this instruction to be called in a function which |
| 1586 | 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] | 1587 | function.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1588 | <p><tt>vanext</tt> is an LLVM instruction instead of an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1589 | href="#intrinsics">intrinsic function</a> because it takes an type as |
| 1590 | an argument.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1591 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1592 | <p>See the <a href="#int_varargs">variable argument processing</a> |
| 1593 | section.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1594 | </div> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1595 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1596 | <div class="doc_subsubsection"> <a name="i_vaarg">'<tt>vaarg</tt>' |
| 1597 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1598 | <div class="doc_text"> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1599 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1600 | <pre> <resultval> = vaarg <va_list> <arglist>, <argty><br></pre> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1601 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1602 | <p>The '<tt>vaarg</tt>' instruction is used to access arguments passed |
| 1603 | through the "variable argument" area of a function call. It is used to |
| 1604 | implement the <tt>va_arg</tt> macro in C.</p> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1605 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1606 | <p>This instruction takes a <tt>valist</tt> value and the type of the |
| 1607 | argument. It returns a value of the specified argument type.</p> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1608 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1609 | <p>The '<tt>vaarg</tt>' instruction loads an argument of the specified |
| 1610 | type from the specified <tt>va_list</tt>. In conjunction with the <a |
| 1611 | href="#i_vanext"><tt>vanext</tt></a> instruction, it is used to |
| 1612 | implement the <tt>va_arg</tt> macro available in C. For more |
| 1613 | information, see the variable argument handling <a href="#int_varargs">Intrinsic |
| 1614 | Functions</a>.</p> |
| 1615 | <p>It is legal for this instruction to be called in a function which |
| 1616 | 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] | 1617 | function.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1618 | <p><tt>vaarg</tt> is an LLVM instruction instead of an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1619 | href="#intrinsics">intrinsic function</a> because it takes an type as |
| 1620 | an argument.</p> |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 1621 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1622 | <p>See the <a href="#int_varargs">variable argument processing</a> |
| 1623 | section.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1624 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1625 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1626 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1627 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> |
| 1628 | <!-- *********************************************************************** --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1629 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1630 | <div class="doc_text"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1631 | |
| 1632 | <p>LLVM supports the notion of an "intrinsic function". These functions have |
| 1633 | well known names and semantics, and are required to follow certain |
| 1634 | restrictions. Overall, these instructions represent an extension mechanism for |
| 1635 | the LLVM language that does not require changing all of the transformations in |
| 1636 | LLVM to add to the language (or the bytecode reader/writer, the parser, |
| 1637 | etc...).</p> |
| 1638 | |
| 1639 | <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix, this |
| 1640 | prefix is reserved in LLVM for intrinsic names, thus functions may not be named |
| 1641 | this. Intrinsic functions must always be external functions: you cannot define |
| 1642 | the body of intrinsic functions. Intrinsic functions may only be used in call |
| 1643 | or invoke instructions: it is illegal to take the address of an intrinsic |
| 1644 | function. Additionally, because intrinsic functions are part of the LLVM |
| 1645 | language, it is required that they all be documented here if any are added.</p> |
| 1646 | |
| 1647 | |
| 1648 | <p> |
| 1649 | Adding an intrinsic to LLVM is straight-forward if it is possible to express the |
| 1650 | concept in LLVM directly (ie, code generator support is not _required_). To do |
| 1651 | this, extend the default implementation of the IntrinsicLowering class to handle |
| 1652 | the intrinsic. Code generators use this class to lower intrinsics they do not |
| 1653 | understand to raw LLVM instructions that they do. |
| 1654 | </p> |
| 1655 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1656 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1657 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1658 | <!-- ======================================================================= --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1659 | <div class="doc_subsection"> |
| 1660 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> |
| 1661 | </div> |
| 1662 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1663 | <div class="doc_text"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1664 | <p>Variable argument support is defined in LLVM with the <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1665 | href="#i_vanext"><tt>vanext</tt></a> instruction and these three |
| 1666 | intrinsic functions. These functions are related to the similarly |
| 1667 | named macros defined in the <tt><stdarg.h></tt> header file.</p> |
| 1668 | <p>All of these functions operate on arguments that use a |
| 1669 | target-specific value type "<tt>va_list</tt>". The LLVM assembly |
| 1670 | language reference manual does not define what this type is, so all |
| 1671 | transformations should be prepared to handle intrinsics with any type |
| 1672 | used.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1673 | <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] | 1674 | instruction and the variable argument handling intrinsic functions are |
| 1675 | used.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1676 | <pre> |
| 1677 | int %test(int %X, ...) { |
| 1678 | ; Initialize variable argument processing |
| 1679 | %ap = call sbyte* %<a href="#i_va_start">llvm.va_start</a>() |
| 1680 | |
| 1681 | ; Read a single integer argument |
| 1682 | %tmp = vaarg sbyte* %ap, int |
| 1683 | |
| 1684 | ; Advance to the next argument |
| 1685 | %ap2 = vanext sbyte* %ap, int |
| 1686 | |
| 1687 | ; Demonstrate usage of llvm.va_copy and llvm.va_end |
| 1688 | %aq = call sbyte* %<a href="#i_va_copy">llvm.va_copy</a>(sbyte* %ap2) |
| 1689 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %aq) |
| 1690 | |
| 1691 | ; Stop processing of arguments. |
| 1692 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte* %ap2) |
| 1693 | ret int %tmp |
| 1694 | } |
| 1695 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1696 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1697 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1698 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1699 | <div class="doc_subsubsection"> |
| 1700 | <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> |
| 1701 | </div> |
| 1702 | |
| 1703 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1704 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1705 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1706 | <pre> call va_list ()* %llvm.va_start()<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1707 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1708 | <p>The '<tt>llvm.va_start</tt>' intrinsic returns a new <tt><arglist></tt> |
| 1709 | for subsequent use by the variable argument intrinsics.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1710 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1711 | <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] | 1712 | macro available in C. In a target-dependent way, it initializes and |
| 1713 | returns a <tt>va_list</tt> element, so that the next <tt>vaarg</tt> |
| 1714 | will produce the first variable argument passed to the function. Unlike |
| 1715 | the C <tt>va_start</tt> macro, this intrinsic does not need to know the |
| 1716 | last argument of the function, the compiler can figure that out.</p> |
| 1717 | <p>Note that this intrinsic function is only legal to be called from |
| 1718 | within the body of a variable argument function.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1719 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1720 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1721 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1722 | <div class="doc_subsubsection"> |
| 1723 | <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> |
| 1724 | </div> |
| 1725 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1726 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1727 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1728 | <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] | 1729 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1730 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt> |
| 1731 | which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt> |
| 1732 | 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] | 1733 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1734 | <p>The argument is a <tt>va_list</tt> to destroy.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1735 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1736 | <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] | 1737 | macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>. |
| 1738 | Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a |
| 1739 | href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly |
| 1740 | with calls to <tt>llvm.va_end</tt>.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1741 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1742 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1743 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1744 | <div class="doc_subsubsection"> |
| 1745 | <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> |
| 1746 | </div> |
| 1747 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1748 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1749 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1750 | <pre> call va_list (va_list)* %llvm.va_copy(va_list <destarglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1751 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1752 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument |
| 1753 | position from the source argument list to the destination argument list.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1754 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1755 | <p>The argument is the <tt>va_list</tt> to copy.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 1756 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1757 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1758 | macro available in C. In a target-dependent way, it copies the source <tt>va_list</tt> |
| 1759 | element into the returned list. This intrinsic is necessary because the <tt><a |
| 1760 | href="i_va_start">llvm.va_start</a></tt> intrinsic may be arbitrarily |
| 1761 | complex and require memory allocation, for example.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1762 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1763 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1764 | <!-- ======================================================================= --> |
| 1765 | <div class="doc_subsection"> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 1766 | <a name="int_codegen">Code Generator Intrinsics</a> |
| 1767 | </div> |
| 1768 | |
| 1769 | <div class="doc_text"> |
| 1770 | <p> |
| 1771 | These intrinsics are provided by LLVM to expose special features that may only |
| 1772 | be implemented with code generator support. |
| 1773 | </p> |
| 1774 | |
| 1775 | </div> |
| 1776 | |
| 1777 | <!-- _______________________________________________________________________ --> |
| 1778 | <div class="doc_subsubsection"> |
| 1779 | <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> |
| 1780 | </div> |
| 1781 | |
| 1782 | <div class="doc_text"> |
| 1783 | |
| 1784 | <h5>Syntax:</h5> |
| 1785 | <pre> |
| 1786 | call void* ()* %llvm.returnaddress(uint <level>) |
| 1787 | </pre> |
| 1788 | |
| 1789 | <h5>Overview:</h5> |
| 1790 | |
| 1791 | <p> |
| 1792 | The '<tt>llvm.returnaddress</tt>' intrinsic returns a target-specific value |
| 1793 | indicating the return address of the current function or one of its callers. |
| 1794 | </p> |
| 1795 | |
| 1796 | <h5>Arguments:</h5> |
| 1797 | |
| 1798 | <p> |
| 1799 | The argument to this intrinsic indicates which function to return the address |
| 1800 | for. Zero indicates the calling function, one indicates its caller, etc. The |
| 1801 | argument is <b>required</b> to be a constant integer value. |
| 1802 | </p> |
| 1803 | |
| 1804 | <h5>Semantics:</h5> |
| 1805 | |
| 1806 | <p> |
| 1807 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating |
| 1808 | the return address of the specified call frame, or zero if it cannot be |
| 1809 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 1810 | for arguments other than zero, so it should only be used for debugging purposes. |
| 1811 | </p> |
| 1812 | |
| 1813 | <p> |
| 1814 | Note that calling this intrinsic does not prevent function inlining or other |
| 1815 | aggressive transformations, so the value returned may not that of the obvious |
| 1816 | source-language caller. |
| 1817 | </p> |
| 1818 | </div> |
| 1819 | |
| 1820 | |
| 1821 | <!-- _______________________________________________________________________ --> |
| 1822 | <div class="doc_subsubsection"> |
| 1823 | <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> |
| 1824 | </div> |
| 1825 | |
| 1826 | <div class="doc_text"> |
| 1827 | |
| 1828 | <h5>Syntax:</h5> |
| 1829 | <pre> |
| 1830 | call void* ()* %llvm.frameaddress(uint <level>) |
| 1831 | </pre> |
| 1832 | |
| 1833 | <h5>Overview:</h5> |
| 1834 | |
| 1835 | <p> |
| 1836 | The '<tt>llvm.frameaddress</tt>' intrinsic returns the target-specific frame |
| 1837 | pointer value for the specified stack frame. |
| 1838 | </p> |
| 1839 | |
| 1840 | <h5>Arguments:</h5> |
| 1841 | |
| 1842 | <p> |
| 1843 | The argument to this intrinsic indicates which function to return the frame |
| 1844 | pointer for. Zero indicates the calling function, one indicates its caller, |
| 1845 | etc. The argument is <b>required</b> to be a constant integer value. |
| 1846 | </p> |
| 1847 | |
| 1848 | <h5>Semantics:</h5> |
| 1849 | |
| 1850 | <p> |
| 1851 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating |
| 1852 | the frame address of the specified call frame, or zero if it cannot be |
| 1853 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 1854 | for arguments other than zero, so it should only be used for debugging purposes. |
| 1855 | </p> |
| 1856 | |
| 1857 | <p> |
| 1858 | Note that calling this intrinsic does not prevent function inlining or other |
| 1859 | aggressive transformations, so the value returned may not that of the obvious |
| 1860 | source-language caller. |
| 1861 | </p> |
| 1862 | </div> |
| 1863 | |
| 1864 | |
| 1865 | <!-- ======================================================================= --> |
| 1866 | <div class="doc_subsection"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1867 | <a name="int_libc">Standard C Library Intrinsics</a> |
| 1868 | </div> |
| 1869 | |
| 1870 | <div class="doc_text"> |
| 1871 | <p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 1872 | LLVM provides intrinsics for a few important standard C library functions. |
| 1873 | These intrinsics allow source-language front-ends to pass information about the |
| 1874 | alignment of the pointer arguments to the code generator, providing opportunity |
| 1875 | for more efficient code generation. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1876 | </p> |
| 1877 | |
| 1878 | </div> |
| 1879 | |
| 1880 | <!-- _______________________________________________________________________ --> |
| 1881 | <div class="doc_subsubsection"> |
| 1882 | <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> |
| 1883 | </div> |
| 1884 | |
| 1885 | <div class="doc_text"> |
| 1886 | |
| 1887 | <h5>Syntax:</h5> |
| 1888 | <pre> |
| 1889 | call void (sbyte*, sbyte*, uint, uint)* %llvm.memcpy(sbyte* <dest>, sbyte* <src>, |
| 1890 | uint <len>, uint <align>) |
| 1891 | </pre> |
| 1892 | |
| 1893 | <h5>Overview:</h5> |
| 1894 | |
| 1895 | <p> |
| 1896 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source |
| 1897 | location to the destination location. |
| 1898 | </p> |
| 1899 | |
| 1900 | <p> |
| 1901 | Note that, unlike the standard libc function, the <tt>llvm.memcpy</tt> intrinsic |
| 1902 | does not return a value, and takes an extra alignment argument. |
| 1903 | </p> |
| 1904 | |
| 1905 | <h5>Arguments:</h5> |
| 1906 | |
| 1907 | <p> |
| 1908 | The first argument is a pointer to the destination, the second is a pointer to |
| 1909 | the source. The third argument is an (arbitrarily sized) integer argument |
| 1910 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 1911 | of the source and destination locations. |
| 1912 | </p> |
| 1913 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 1914 | <p> |
| 1915 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 1916 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 1917 | and that both the source and destination pointers are aligned to that boundary. |
| 1918 | </p> |
| 1919 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 1920 | <h5>Semantics:</h5> |
| 1921 | |
| 1922 | <p> |
| 1923 | The '<tt>llvm.memcpy</tt>' intrinsic copies a block of memory from the source |
| 1924 | location to the destination location, which are not allowed to overlap. It |
| 1925 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 1926 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 1927 | be set to 0 or 1. |
| 1928 | </p> |
| 1929 | </div> |
| 1930 | |
| 1931 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 1932 | <!-- _______________________________________________________________________ --> |
| 1933 | <div class="doc_subsubsection"> |
| 1934 | <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> |
| 1935 | </div> |
| 1936 | |
| 1937 | <div class="doc_text"> |
| 1938 | |
| 1939 | <h5>Syntax:</h5> |
| 1940 | <pre> |
| 1941 | call void (sbyte*, sbyte*, uint, uint)* %llvm.memmove(sbyte* <dest>, sbyte* <src>, |
| 1942 | uint <len>, uint <align>) |
| 1943 | </pre> |
| 1944 | |
| 1945 | <h5>Overview:</h5> |
| 1946 | |
| 1947 | <p> |
| 1948 | The '<tt>llvm.memmove</tt>' intrinsic moves a block of memory from the source |
| 1949 | location to the destination location. It is similar to the '<tt>llvm.memcpy</tt>' |
| 1950 | intrinsic but allows the two memory locations to overlap. |
| 1951 | </p> |
| 1952 | |
| 1953 | <p> |
| 1954 | Note that, unlike the standard libc function, the <tt>llvm.memmove</tt> intrinsic |
| 1955 | does not return a value, and takes an extra alignment argument. |
| 1956 | </p> |
| 1957 | |
| 1958 | <h5>Arguments:</h5> |
| 1959 | |
| 1960 | <p> |
| 1961 | The first argument is a pointer to the destination, the second is a pointer to |
| 1962 | the source. The third argument is an (arbitrarily sized) integer argument |
| 1963 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 1964 | of the source and destination locations. |
| 1965 | </p> |
| 1966 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 1967 | <p> |
| 1968 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 1969 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 1970 | and that both the source and destination pointers are aligned to that boundary. |
| 1971 | </p> |
| 1972 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 1973 | <h5>Semantics:</h5> |
| 1974 | |
| 1975 | <p> |
| 1976 | The '<tt>llvm.memmove</tt>' intrinsic copies a block of memory from the source |
| 1977 | location to the destination location, which may overlap. It |
| 1978 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 1979 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 1980 | be set to 0 or 1. |
| 1981 | </p> |
| 1982 | </div> |
| 1983 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 1984 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 1985 | <!-- _______________________________________________________________________ --> |
| 1986 | <div class="doc_subsubsection"> |
| 1987 | <a name="i_memset">'<tt>llvm.memset</tt>' Intrinsic</a> |
| 1988 | </div> |
| 1989 | |
| 1990 | <div class="doc_text"> |
| 1991 | |
| 1992 | <h5>Syntax:</h5> |
| 1993 | <pre> |
| 1994 | call void (sbyte*, ubyte, uint, uint)* %llvm.memset(sbyte* <dest>, ubyte <val>, |
| 1995 | uint <len>, uint <align>) |
| 1996 | </pre> |
| 1997 | |
| 1998 | <h5>Overview:</h5> |
| 1999 | |
| 2000 | <p> |
| 2001 | The '<tt>llvm.memset</tt>' intrinsic fills a block of memory with a particular |
| 2002 | byte value. |
| 2003 | </p> |
| 2004 | |
| 2005 | <p> |
| 2006 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic |
| 2007 | does not return a value, and takes an extra alignment argument. |
| 2008 | </p> |
| 2009 | |
| 2010 | <h5>Arguments:</h5> |
| 2011 | |
| 2012 | <p> |
| 2013 | The first argument is a pointer to the destination to fill, the second is the |
| 2014 | byte value to fill it with, the third argument is an (arbitrarily sized) integer |
| 2015 | argument specifying the number of bytes to fill, and the fourth argument is the |
| 2016 | known alignment of destination location. |
| 2017 | </p> |
| 2018 | |
| 2019 | <p> |
| 2020 | If the call to this intrinisic has an alignment value that is not 0 or 1, then |
| 2021 | the caller guarantees that the size of the copy is a multiple of the alignment |
| 2022 | and that the destination pointer is aligned to that boundary. |
| 2023 | </p> |
| 2024 | |
| 2025 | <h5>Semantics:</h5> |
| 2026 | |
| 2027 | <p> |
| 2028 | The '<tt>llvm.memset</tt>' intrinsic fills "len" bytes of memory starting at the |
| 2029 | destination location. If the argument is known to be aligned to some boundary, |
| 2030 | this can be specified as the fourth argument, otherwise it should be set to 0 or |
| 2031 | 1. |
| 2032 | </p> |
| 2033 | </div> |
| 2034 | |
| 2035 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 2036 | <!-- ======================================================================= --> |
| 2037 | <div class="doc_subsection"> |
| 2038 | <a name="int_debugger">Debugger Intrinsics</a> |
| 2039 | </div> |
| 2040 | |
| 2041 | <div class="doc_text"> |
| 2042 | <p> |
| 2043 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), |
| 2044 | are described in the <a |
| 2045 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level |
| 2046 | Debugging</a> document. |
| 2047 | </p> |
| 2048 | </div> |
| 2049 | |
| 2050 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2051 | <!-- *********************************************************************** --> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2052 | <hr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2053 | <div class="doc_footer"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2054 | <address><a href="mailto:sabre@nondot.org">Chris Lattner</a></address> |
| 2055 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a> <br> |
| 2056 | Last modified: $Date$ </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2057 | </body> |
| 2058 | </html> |