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