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