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