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