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