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