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