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