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