| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | 
 | 2 |                       "http://www.w3.org/TR/html4/strict.dtd"> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3 | <html> | 
 | 4 | <head> | 
 | 5 |   <title>LLVM Assembly Language Reference Manual</title> | 
| Reid Spencer | 3921c74 | 2004-08-26 20:44:00 +0000 | [diff] [blame] | 6 |   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | 
 | 7 |   <meta name="author" content="Chris Lattner"> | 
 | 8 |   <meta name="description"  | 
 | 9 |   content="LLVM Assembly Language Reference Manual."> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 10 |   <link rel="stylesheet" href="llvm.css" type="text/css"> | 
 | 11 | </head> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 12 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 13 | <body> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 14 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 15 | <div class="doc_title"> LLVM Language Reference Manual </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | <ol> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 17 |   <li><a href="#abstract">Abstract</a></li> | 
 | 18 |   <li><a href="#introduction">Introduction</a></li> | 
 | 19 |   <li><a href="#identifiers">Identifiers</a></li> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 20 |   <li><a href="#highlevel">High Level Structure</a> | 
 | 21 |     <ol> | 
 | 22 |       <li><a href="#modulestructure">Module Structure</a></li> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 23 |       <li><a href="#linkage">Linkage Types</a></li> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 24 |       <li><a href="#callingconv">Calling Conventions</a></li> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 25 |       <li><a href="#globalvars">Global Variables</a></li> | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 26 |       <li><a href="#functionstructure">Functions</a></li> | 
| Anton Korobeynikov | c6c98af | 2007-04-29 18:02:48 +0000 | [diff] [blame] | 27 |       <li><a href="#aliasstructure">Aliases</a> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 28 |       <li><a href="#paramattrs">Parameter Attributes</a></li> | 
| Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 29 |       <li><a href="#gc">Garbage Collector Names</a></li> | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 30 |       <li><a href="#moduleasm">Module-Level Inline Assembly</a></li> | 
| Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 31 |       <li><a href="#datalayout">Data Layout</a></li> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 32 |     </ol> | 
 | 33 |   </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 34 |   <li><a href="#typesystem">Type System</a> | 
 | 35 |     <ol> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 36 |       <li><a href="#t_classifications">Type Classifications</a></li> | 
| Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 37 |       <li><a href="#t_primitive">Primitive Types</a>     | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 38 |         <ol> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 39 |           <li><a href="#t_floating">Floating Point Types</a></li> | 
 | 40 |           <li><a href="#t_void">Void Type</a></li> | 
 | 41 |           <li><a href="#t_label">Label Type</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 42 |         </ol> | 
 | 43 |       </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 |       <li><a href="#t_derived">Derived Types</a> | 
 | 45 |         <ol> | 
| Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 46 |           <li><a href="#t_integer">Integer Type</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 47 |           <li><a href="#t_array">Array Type</a></li> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 48 |           <li><a href="#t_function">Function Type</a></li> | 
 | 49 |           <li><a href="#t_pointer">Pointer Type</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 50 |           <li><a href="#t_struct">Structure Type</a></li> | 
| Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 51 |           <li><a href="#t_pstruct">Packed Structure Type</a></li> | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 52 |           <li><a href="#t_vector">Vector Type</a></li> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 53 |           <li><a href="#t_opaque">Opaque Type</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 54 |         </ol> | 
 | 55 |       </li> | 
 | 56 |     </ol> | 
 | 57 |   </li> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 58 |   <li><a href="#constants">Constants</a> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 59 |     <ol> | 
 | 60 |       <li><a href="#simpleconstants">Simple Constants</a> | 
 | 61 |       <li><a href="#aggregateconstants">Aggregate Constants</a> | 
 | 62 |       <li><a href="#globalconstants">Global Variable and Function Addresses</a> | 
 | 63 |       <li><a href="#undefvalues">Undefined Values</a> | 
 | 64 |       <li><a href="#constantexprs">Constant Expressions</a> | 
 | 65 |     </ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 66 |   </li> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 67 |   <li><a href="#othervalues">Other Values</a> | 
 | 68 |     <ol> | 
 | 69 |       <li><a href="#inlineasm">Inline Assembler Expressions</a> | 
 | 70 |     </ol> | 
 | 71 |   </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 72 |   <li><a href="#instref">Instruction Reference</a> | 
 | 73 |     <ol> | 
 | 74 |       <li><a href="#terminators">Terminator Instructions</a> | 
 | 75 |         <ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 76 |           <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> | 
 | 77 |           <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 78 |           <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> | 
 | 79 |           <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 80 |           <li><a href="#i_unwind">'<tt>unwind</tt>'  Instruction</a></li> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 81 |           <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 82 |         </ol> | 
 | 83 |       </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 84 |       <li><a href="#binaryops">Binary Operations</a> | 
 | 85 |         <ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 86 |           <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> | 
 | 87 |           <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> | 
 | 88 |           <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 89 |           <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li> | 
 | 90 |           <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li> | 
 | 91 |           <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 92 |           <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li> | 
 | 93 |           <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li> | 
 | 94 |           <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 95 |         </ol> | 
 | 96 |       </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 97 |       <li><a href="#bitwiseops">Bitwise Binary Operations</a> | 
 | 98 |         <ol> | 
| Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 99 |           <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> | 
 | 100 |           <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li> | 
 | 101 |           <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 102 |           <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 103 |           <li><a href="#i_or">'<tt>or</tt>'  Instruction</a></li> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 104 |           <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 105 |         </ol> | 
 | 106 |       </li> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 107 |       <li><a href="#vectorops">Vector Operations</a> | 
 | 108 |         <ol> | 
 | 109 |           <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li> | 
 | 110 |           <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li> | 
 | 111 |           <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 112 |         </ol> | 
 | 113 |       </li> | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 114 |       <li><a href="#aggregateops">Aggregate Operations</a> | 
 | 115 |         <ol> | 
 | 116 |           <li><a href="#i_extractvalue">'<tt>extractvalue</tt>' Instruction</a></li> | 
 | 117 |           <li><a href="#i_insertvalue">'<tt>insertvalue</tt>' Instruction</a></li> | 
 | 118 |         </ol> | 
 | 119 |       </li> | 
| Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 120 |       <li><a href="#memoryops">Memory Access and Addressing Operations</a> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 121 |         <ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 122 |           <li><a href="#i_malloc">'<tt>malloc</tt>'   Instruction</a></li> | 
 | 123 |           <li><a href="#i_free">'<tt>free</tt>'     Instruction</a></li> | 
 | 124 |           <li><a href="#i_alloca">'<tt>alloca</tt>'   Instruction</a></li> | 
| Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 125 |          <li><a href="#i_load">'<tt>load</tt>'     Instruction</a></li> | 
 | 126 |          <li><a href="#i_store">'<tt>store</tt>'    Instruction</a></li> | 
 | 127 |          <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 128 |         </ol> | 
 | 129 |       </li> | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 130 |       <li><a href="#convertops">Conversion Operations</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 131 |         <ol> | 
 | 132 |           <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li> | 
 | 133 |           <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li> | 
 | 134 |           <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li> | 
 | 135 |           <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li> | 
 | 136 |           <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 137 |           <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li> | 
 | 138 |           <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li> | 
 | 139 |           <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li> | 
 | 140 |           <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 141 |           <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li> | 
 | 142 |           <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li> | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 143 |           <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 144 |         </ol> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 145 |       <li><a href="#otherops">Other Operations</a> | 
 | 146 |         <ol> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 147 |           <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li> | 
 | 148 |           <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li> | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 149 |           <li><a href="#i_vicmp">'<tt>vicmp</tt>' Instruction</a></li> | 
 | 150 |           <li><a href="#i_vfcmp">'<tt>vfcmp</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 151 |           <li><a href="#i_phi">'<tt>phi</tt>'   Instruction</a></li> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 152 |           <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 153 |           <li><a href="#i_call">'<tt>call</tt>'  Instruction</a></li> | 
| Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 154 |           <li><a href="#i_va_arg">'<tt>va_arg</tt>'  Instruction</a></li> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 155 |           <li><a href="#i_getresult">'<tt>getresult</tt>'  Instruction</a></li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 156 |         </ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 157 |       </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 158 |     </ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 159 |   </li> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 160 |   <li><a href="#intrinsics">Intrinsic Functions</a> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 161 |     <ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 162 |       <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> | 
 | 163 |         <ol> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 164 |           <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> | 
 | 165 |           <li><a href="#int_va_end">'<tt>llvm.va_end</tt>'   Intrinsic</a></li> | 
 | 166 |           <li><a href="#int_va_copy">'<tt>llvm.va_copy</tt>'  Intrinsic</a></li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 167 |         </ol> | 
 | 168 |       </li> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 169 |       <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> | 
 | 170 |         <ol> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 171 |           <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> | 
 | 172 |           <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> | 
 | 173 |           <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 174 |         </ol> | 
 | 175 |       </li> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 176 |       <li><a href="#int_codegen">Code Generator Intrinsics</a> | 
 | 177 |         <ol> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 178 |           <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> | 
 | 179 |           <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>'   Intrinsic</a></li> | 
 | 180 |           <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li> | 
 | 181 |           <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li> | 
 | 182 |           <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li> | 
 | 183 |           <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li> | 
 | 184 |           <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li> | 
| John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 185 |         </ol> | 
 | 186 |       </li> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 187 |       <li><a href="#int_libc">Standard C Library Intrinsics</a> | 
 | 188 |         <ol> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 189 |           <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li> | 
 | 190 |           <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li> | 
 | 191 |           <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li> | 
 | 192 |           <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li> | 
 | 193 |           <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li> | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 194 |           <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li> | 
 | 195 |           <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li> | 
 | 196 |           <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 197 |         </ol> | 
 | 198 |       </li> | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 199 |       <li><a href="#int_manip">Bit Manipulation Intrinsics</a> | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 200 |         <ol> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 201 |           <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li> | 
| Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 202 |           <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li> | 
 | 203 |           <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li> | 
 | 204 |           <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li> | 
| Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 205 |           <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li> | 
 | 206 |           <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li> | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 207 |         </ol> | 
 | 208 |       </li> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 209 |       <li><a href="#int_debugger">Debugger intrinsics</a></li> | 
| Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 210 |       <li><a href="#int_eh">Exception Handling intrinsics</a></li> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 211 |       <li><a href="#int_trampoline">Trampoline Intrinsic</a> | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 212 |         <ol> | 
 | 213 |           <li><a href="#int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a></li> | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 214 |         </ol> | 
 | 215 |       </li> | 
| Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 216 |           <li><a href="#int_atomics">Atomic intrinsics</a> | 
 | 217 |             <ol> | 
| Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 218 |               <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li> | 
 | 219 |               <li><a href="#int_atomic_lcs"><tt>llvm.atomic.lcs</tt></a></li> | 
 | 220 |               <li><a href="#int_atomic_las"><tt>llvm.atomic.las</tt></a></li> | 
 | 221 |               <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li> | 
| Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 222 |             </ol> | 
 | 223 |           </li> | 
| Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 224 |       <li><a href="#int_general">General intrinsics</a> | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 225 |         <ol> | 
| Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 226 |           <li><a href="#int_var_annotation"> | 
| Tanya Lattner | 91d0b88 | 2007-09-22 00:01:26 +0000 | [diff] [blame] | 227 |             <tt>llvm.var.annotation</tt>' Intrinsic</a></li> | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 228 |           <li><a href="#int_annotation"> | 
| Tanya Lattner | 91d0b88 | 2007-09-22 00:01:26 +0000 | [diff] [blame] | 229 |             <tt>llvm.annotation.*</tt>' Intrinsic</a></li> | 
| Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 230 |           <li><a href="#int_trap"> | 
 | 231 |             <tt>llvm.trap</tt>' Intrinsic</a></li> | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 232 |         </ol> | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 233 |       </li> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 234 |     </ol> | 
 | 235 |   </li> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 236 | </ol> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 237 |  | 
 | 238 | <div class="doc_author"> | 
 | 239 |   <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> | 
 | 240 |             and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 241 | </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 242 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 243 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 244 | <div class="doc_section"> <a name="abstract">Abstract </a></div> | 
 | 245 | <!-- *********************************************************************** --> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 246 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 247 | <div class="doc_text"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 248 | <p>This document is a reference manual for the LLVM assembly language.  | 
 | 249 | LLVM is an SSA based representation that provides type safety, | 
 | 250 | low-level operations, flexibility, and the capability of representing | 
 | 251 | 'all' high-level languages cleanly.  It is the common code | 
 | 252 | representation used throughout all phases of the LLVM compilation | 
 | 253 | strategy.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 254 | </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 255 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 256 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 257 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> | 
 | 258 | <!-- *********************************************************************** --> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 259 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 260 | <div class="doc_text"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 261 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 262 | <p>The LLVM code representation is designed to be used in three | 
| Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 263 | different forms: as an in-memory compiler IR, as an on-disk bitcode | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 264 | representation (suitable for fast loading by a Just-In-Time compiler), | 
 | 265 | and as a human readable assembly language representation.  This allows | 
 | 266 | LLVM to provide a powerful intermediate representation for efficient | 
 | 267 | compiler transformations and analysis, while providing a natural means | 
 | 268 | to debug and visualize the transformations.  The three different forms | 
 | 269 | of LLVM are all equivalent.  This document describes the human readable | 
 | 270 | representation and notation.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 271 |  | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 272 | <p>The LLVM representation aims to be light-weight and low-level | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 273 | while being expressive, typed, and extensible at the same time.  It | 
 | 274 | aims to be a "universal IR" of sorts, by being at a low enough level | 
 | 275 | that high-level ideas may be cleanly mapped to it (similar to how | 
 | 276 | microprocessors are "universal IR's", allowing many source languages to | 
 | 277 | be mapped to them).  By providing type information, LLVM can be used as | 
 | 278 | the target of optimizations: for example, through pointer analysis, it | 
 | 279 | can be proven that a C automatic variable is never accessed outside of | 
 | 280 | the current function... allowing it to be promoted to a simple SSA | 
 | 281 | value instead of a memory location.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 282 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 283 | </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 284 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 285 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 286 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 287 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 288 | <div class="doc_text"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 289 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 290 | <p>It is important to note that this document describes 'well formed' | 
 | 291 | LLVM assembly language.  There is a difference between what the parser | 
 | 292 | accepts and what is considered 'well formed'.  For example, the | 
 | 293 | following instruction is syntactically okay, but not well formed:</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 294 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 295 | <div class="doc_code"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 296 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 297 | %x = <a href="#i_add">add</a> i32 1, %x | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 298 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 299 | </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 300 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 301 | <p>...because the definition of <tt>%x</tt> does not dominate all of | 
 | 302 | its uses. The LLVM infrastructure provides a verification pass that may | 
 | 303 | be used to verify that an LLVM module is well formed.  This pass is | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 304 | automatically run by the parser after parsing input assembly and by | 
| Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 305 | the optimizer before it outputs bitcode.  The violations pointed out | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 306 | by the verifier pass indicate bugs in transformation passes or input to | 
 | 307 | the parser.</p> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 308 | </div> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 309 |  | 
| Chris Lattner | cc68939 | 2007-10-03 17:34:29 +0000 | [diff] [blame] | 310 | <!-- Describe the typesetting conventions here. --> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 311 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 312 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 313 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 314 | <!-- *********************************************************************** --> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 315 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 316 | <div class="doc_text"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 317 |  | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 318 |   <p>LLVM identifiers come in two basic types: global and local. Global | 
 | 319 |   identifiers (functions, global variables) begin with the @ character. Local | 
 | 320 |   identifiers (register names, types) begin with the % character. Additionally, | 
 | 321 |   there are three different formats for identifiers, for different purposes: | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 322 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 323 | <ol> | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 324 |   <li>Named values are represented as a string of characters with their prefix. | 
 | 325 |   For example, %foo, @DivisionByZero, %a.really.long.identifier.  The actual | 
 | 326 |   regular expression used is '<tt>[%@][a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 327 |   Identifiers which require other characters in their names can be surrounded | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 328 |   with quotes.  In this way, anything except a <tt>"</tt> character can  | 
 | 329 |   be used in a named value.</li> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 330 |  | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 331 |   <li>Unnamed values are represented as an unsigned numeric value with their | 
 | 332 |   prefix.  For example, %12, @2, %44.</li> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 333 |  | 
| Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 334 |   <li>Constants, which are described in a <a href="#constants">section about | 
 | 335 |   constants</a>, below.</li> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 336 | </ol> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 337 |  | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 338 | <p>LLVM requires that values start with a prefix for two reasons: Compilers | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 339 | don't need to worry about name clashes with reserved words, and the set of | 
 | 340 | reserved words may be expanded in the future without penalty.  Additionally, | 
 | 341 | unnamed identifiers allow a compiler to quickly come up with a temporary | 
 | 342 | variable without having to avoid symbol table conflicts.</p> | 
 | 343 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 344 | <p>Reserved words in LLVM are very similar to reserved words in other | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 345 | languages. There are keywords for different opcodes  | 
 | 346 | ('<tt><a href="#i_add">add</a></tt>',  | 
 | 347 |  '<tt><a href="#i_bitcast">bitcast</a></tt>',  | 
 | 348 |  '<tt><a href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 349 | href="#t_void">void</a></tt>', '<tt><a href="#t_primitive">i32</a></tt>', etc...), | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 350 | and others.  These reserved words cannot conflict with variable names, because | 
| Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 351 | none of them start with a prefix character ('%' or '@').</p> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 352 |  | 
 | 353 | <p>Here is an example of LLVM code to multiply the integer variable | 
 | 354 | '<tt>%X</tt>' by 8:</p> | 
 | 355 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 356 | <p>The easy way:</p> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 357 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 358 | <div class="doc_code"> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 359 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 360 | %result = <a href="#i_mul">mul</a> i32 %X, 8 | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 361 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 362 | </div> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 363 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 364 | <p>After strength reduction:</p> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 365 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 366 | <div class="doc_code"> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 367 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 368 | %result = <a href="#i_shl">shl</a> i32 %X, i8 3 | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 369 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 370 | </div> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 371 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 372 | <p>And the hard way:</p> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 373 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 374 | <div class="doc_code"> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 375 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 376 | <a href="#i_add">add</a> i32 %X, %X           <i>; yields {i32}:%0</i> | 
 | 377 | <a href="#i_add">add</a> i32 %0, %0           <i>; yields {i32}:%1</i> | 
 | 378 | %result = <a href="#i_add">add</a> i32 %1, %1 | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 379 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 380 | </div> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 381 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 382 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several | 
 | 383 | important lexical features of LLVM:</p> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 384 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 385 | <ol> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 386 |  | 
 | 387 |   <li>Comments are delimited with a '<tt>;</tt>' and go until the end of | 
 | 388 |   line.</li> | 
 | 389 |  | 
 | 390 |   <li>Unnamed temporaries are created when the result of a computation is not | 
 | 391 |   assigned to a named value.</li> | 
 | 392 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 393 |   <li>Unnamed temporaries are numbered sequentially</li> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 394 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 395 | </ol> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 396 |  | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 397 | <p>...and it also shows a convention that we follow in this document.  When | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 398 | demonstrating instructions, we will follow an instruction with a comment that | 
 | 399 | defines the type and name of value produced.  Comments are shown in italic | 
 | 400 | text.</p> | 
 | 401 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 402 | </div> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 403 |  | 
 | 404 | <!-- *********************************************************************** --> | 
 | 405 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> | 
 | 406 | <!-- *********************************************************************** --> | 
 | 407 |  | 
 | 408 | <!-- ======================================================================= --> | 
 | 409 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> | 
 | 410 | </div> | 
 | 411 |  | 
 | 412 | <div class="doc_text"> | 
 | 413 |  | 
 | 414 | <p>LLVM programs are composed of "Module"s, each of which is a | 
 | 415 | translation unit of the input programs.  Each module consists of | 
 | 416 | functions, global variables, and symbol table entries.  Modules may be | 
 | 417 | combined together with the LLVM linker, which merges function (and | 
 | 418 | global variable) definitions, resolves forward declarations, and merges | 
 | 419 | symbol table entries. Here is an example of the "hello world" module:</p> | 
 | 420 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 421 | <div class="doc_code"> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 422 | <pre><i>; Declare the string constant as a global constant...</i> | 
| Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 423 | <a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a | 
 | 424 |  href="#globalvars">constant</a> <a href="#t_array">[13 x i8]</a> c"hello world\0A\00"          <i>; [13 x i8]*</i> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 425 |  | 
 | 426 | <i>; External declaration of the puts function</i> | 
| Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 427 | <a href="#functionstructure">declare</a> i32 @puts(i8 *)                                            <i>; i32(i8 *)* </i> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 428 |  | 
 | 429 | <i>; Definition of main function</i> | 
| Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 430 | define i32 @main() {                                                 <i>; i32()* </i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 431 |         <i>; Convert [13x i8 ]* to i8  *...</i> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 432 |         %cast210 = <a | 
| Chris Lattner | 6c0955b | 2007-06-12 17:01:15 +0000 | [diff] [blame] | 433 |  href="#i_getelementptr">getelementptr</a> [13 x i8 ]* @.LC0, i64 0, i64 0 <i>; i8 *</i> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 434 |  | 
 | 435 |         <i>; Call puts function to write out the string to stdout...</i> | 
 | 436 |         <a | 
| Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 437 |  href="#i_call">call</a> i32 @puts(i8 * %cast210)                              <i>; i32</i> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 438 |         <a | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 439 |  href="#i_ret">ret</a> i32 0<br>}<br> | 
 | 440 | </pre> | 
 | 441 | </div> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 442 |  | 
 | 443 | <p>This example is made up of a <a href="#globalvars">global variable</a> | 
 | 444 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" | 
 | 445 | function, and a <a href="#functionstructure">function definition</a> | 
 | 446 | for "<tt>main</tt>".</p> | 
 | 447 |  | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 448 | <p>In general, a module is made up of a list of global values, | 
 | 449 | where both functions and global variables are global values.  Global values are | 
 | 450 | represented by a pointer to a memory location (in this case, a pointer to an | 
 | 451 | array of char, and a pointer to a function), and have one of the following <a | 
 | 452 | href="#linkage">linkage types</a>.</p> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 453 |  | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 454 | </div> | 
 | 455 |  | 
 | 456 | <!-- ======================================================================= --> | 
 | 457 | <div class="doc_subsection"> | 
 | 458 |   <a name="linkage">Linkage Types</a> | 
 | 459 | </div> | 
 | 460 |  | 
 | 461 | <div class="doc_text"> | 
 | 462 |  | 
 | 463 | <p> | 
 | 464 | All Global Variables and Functions have one of the following types of linkage: | 
 | 465 | </p> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 466 |  | 
 | 467 | <dl> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 468 |  | 
| Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 469 |   <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 470 |  | 
 | 471 |   <dd>Global values with internal linkage are only directly accessible by | 
 | 472 |   objects in the current module.  In particular, linking code into a module with | 
 | 473 |   an internal global value may cause the internal to be renamed as necessary to | 
 | 474 |   avoid collisions.  Because the symbol is internal to the module, all | 
 | 475 |   references can be updated.  This corresponds to the notion of the | 
| Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 476 |   '<tt>static</tt>' keyword in C. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 477 |   </dd> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 478 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 479 |   <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 480 |  | 
| Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 481 |   <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of | 
 | 482 |   the same name when linkage occurs.  This is typically used to implement  | 
 | 483 |   inline functions, templates, or other code which must be generated in each  | 
 | 484 |   translation unit that uses it.  Unreferenced <tt>linkonce</tt> globals are  | 
 | 485 |   allowed to be discarded. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 486 |   </dd> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 487 |  | 
| Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 488 |   <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt> | 
 | 489 |  | 
 | 490 |   <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>  | 
 | 491 |   linkage, except that unreferenced <tt>common</tt> globals may not be | 
 | 492 |   discarded.  This is used for globals that may be emitted in multiple  | 
 | 493 |   translation units, but that are not guaranteed to be emitted into every  | 
 | 494 |   translation unit that uses them.  One example of this is tentative | 
 | 495 |   definitions in C, such as "<tt>int X;</tt>" at global scope. | 
 | 496 |   </dd> | 
 | 497 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 498 |   <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 499 |  | 
| Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 500 |   <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except | 
 | 501 |   that some targets may choose to emit different assembly sequences for them  | 
 | 502 |   for target-dependent reasons.  This is used for globals that are declared  | 
 | 503 |   "weak" in C source code. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 504 |   </dd> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 505 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 506 |   <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 507 |  | 
 | 508 |   <dd>"<tt>appending</tt>" linkage may only be applied to global variables of | 
 | 509 |   pointer to array type.  When two global variables with appending linkage are | 
 | 510 |   linked together, the two global arrays are appended together.  This is the | 
 | 511 |   LLVM, typesafe, equivalent of having the system linker append together | 
 | 512 |   "sections" with identical names when .o files are linked. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 513 |   </dd> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 514 |  | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 515 |   <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> | 
 | 516 |   <dd>The semantics of this linkage follow the ELF model: the symbol is weak | 
 | 517 |     until linked, if not linked, the symbol becomes null instead of being an | 
 | 518 |     undefined reference. | 
 | 519 |   </dd> | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 520 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 521 |   <dt><tt><b><a name="linkage_external">externally visible</a></b></tt>:</dt> | 
| Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 522 |  | 
 | 523 |   <dd>If none of the above identifiers are used, the global is externally | 
 | 524 |   visible, meaning that it participates in linkage and can be used to resolve | 
 | 525 |   external symbol references. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 526 |   </dd> | 
| Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 527 | </dl> | 
| Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 528 |  | 
| Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 529 |   <p> | 
 | 530 |   The next two types of linkage are targeted for Microsoft Windows platform | 
 | 531 |   only. They are designed to support importing (exporting) symbols from (to) | 
 | 532 |   DLLs. | 
 | 533 |   </p> | 
 | 534 |  | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 535 |   <dl> | 
| Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 536 |   <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt> | 
 | 537 |  | 
 | 538 |   <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function | 
 | 539 |     or variable via a global pointer to a pointer that is set up by the DLL | 
 | 540 |     exporting the symbol. On Microsoft Windows targets, the pointer name is | 
 | 541 |     formed by combining <code>_imp__</code> and the function or variable name. | 
 | 542 |   </dd> | 
 | 543 |  | 
 | 544 |   <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt> | 
 | 545 |  | 
 | 546 |   <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global | 
 | 547 |     pointer to a pointer in a DLL, so that it can be referenced with the | 
 | 548 |     <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer | 
 | 549 |     name is formed by combining <code>_imp__</code> and the function or variable | 
 | 550 |     name. | 
 | 551 |   </dd> | 
 | 552 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 553 | </dl> | 
 | 554 |  | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 555 | <p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>" | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 556 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" | 
 | 557 | variable and was linked with this one, one of the two would be renamed, | 
 | 558 | preventing a collision.  Since "<tt>main</tt>" and "<tt>puts</tt>" are | 
 | 559 | external (i.e., lacking any linkage declarations), they are accessible | 
| Reid Spencer | ac8d276 | 2007-01-05 00:59:10 +0000 | [diff] [blame] | 560 | outside of the current module.</p> | 
 | 561 | <p>It is illegal for a function <i>declaration</i> | 
 | 562 | to have any linkage type other than "externally visible", <tt>dllimport</tt>, | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 563 | or <tt>extern_weak</tt>.</p> | 
| Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 564 | <p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt> | 
 | 565 | linkages. | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 566 | </div> | 
 | 567 |  | 
 | 568 | <!-- ======================================================================= --> | 
 | 569 | <div class="doc_subsection"> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 570 |   <a name="callingconv">Calling Conventions</a> | 
 | 571 | </div> | 
 | 572 |  | 
 | 573 | <div class="doc_text"> | 
 | 574 |  | 
 | 575 | <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a> | 
 | 576 | and <a href="#i_invoke">invokes</a> can all have an optional calling convention | 
 | 577 | specified for the call.  The calling convention of any pair of dynamic | 
 | 578 | caller/callee must match, or the behavior of the program is undefined.  The | 
 | 579 | following calling conventions are supported by LLVM, and more may be added in | 
 | 580 | the future:</p> | 
 | 581 |  | 
 | 582 | <dl> | 
 | 583 |   <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt> | 
 | 584 |  | 
 | 585 |   <dd>This calling convention (the default if no other calling convention is | 
 | 586 |   specified) matches the target C calling conventions.  This calling convention | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 587 |   supports varargs function calls and tolerates some mismatch in the declared | 
| Reid Spencer | c28d2bc | 2006-12-31 21:30:18 +0000 | [diff] [blame] | 588 |   prototype and implemented declaration of the function (as does normal C).  | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 589 |   </dd> | 
 | 590 |  | 
 | 591 |   <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt> | 
 | 592 |  | 
 | 593 |   <dd>This calling convention attempts to make calls as fast as possible | 
 | 594 |   (e.g. by passing things in registers).  This calling convention allows the | 
 | 595 |   target to use whatever tricks it wants to produce fast code for the target, | 
| Chris Lattner | 8cdc5bc | 2005-05-06 23:08:23 +0000 | [diff] [blame] | 596 |   without having to conform to an externally specified ABI.  Implementations of | 
| Arnold Schwaighofer | 9097d14 | 2008-05-14 09:17:12 +0000 | [diff] [blame] | 597 |   this convention should allow arbitrary | 
 | 598 |   <a href="CodeGenerator.html#tailcallopt">tail call optimization</a> to be | 
 | 599 |   supported.  This calling convention does not support varargs and requires the | 
 | 600 |   prototype of all callees to exactly match the prototype of the function | 
 | 601 |   definition. | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 602 |   </dd> | 
 | 603 |  | 
 | 604 |   <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt> | 
 | 605 |  | 
 | 606 |   <dd>This calling convention attempts to make code in the caller as efficient | 
 | 607 |   as possible under the assumption that the call is not commonly executed.  As | 
 | 608 |   such, these calls often preserve all registers so that the call does not break | 
 | 609 |   any live ranges in the caller side.  This calling convention does not support | 
 | 610 |   varargs and requires the prototype of all callees to exactly match the | 
 | 611 |   prototype of the function definition. | 
 | 612 |   </dd> | 
 | 613 |  | 
| Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 614 |   <dt><b>"<tt>cc <<em>n</em>></tt>" - Numbered convention</b>:</dt> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 615 |  | 
 | 616 |   <dd>Any calling convention may be specified by number, allowing | 
 | 617 |   target-specific calling conventions to be used.  Target specific calling | 
 | 618 |   conventions start at 64. | 
 | 619 |   </dd> | 
| Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 620 | </dl> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 621 |  | 
 | 622 | <p>More calling conventions can be added/defined on an as-needed basis, to | 
 | 623 | support pascal conventions or any other well-known target-independent | 
 | 624 | convention.</p> | 
 | 625 |  | 
 | 626 | </div> | 
 | 627 |  | 
 | 628 | <!-- ======================================================================= --> | 
 | 629 | <div class="doc_subsection"> | 
| Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 630 |   <a name="visibility">Visibility Styles</a> | 
 | 631 | </div> | 
 | 632 |  | 
 | 633 | <div class="doc_text"> | 
 | 634 |  | 
 | 635 | <p> | 
 | 636 | All Global Variables and Functions have one of the following visibility styles: | 
 | 637 | </p> | 
 | 638 |  | 
 | 639 | <dl> | 
 | 640 |   <dt><b>"<tt>default</tt>" - Default style</b>:</dt> | 
 | 641 |  | 
 | 642 |   <dd>On ELF, default visibility means that the declaration is visible to other | 
 | 643 |     modules and, in shared libraries, means that the declared entity may be | 
 | 644 |     overridden. On Darwin, default visibility means that the declaration is | 
 | 645 |     visible to other modules. Default visibility corresponds to "external | 
 | 646 |     linkage" in the language. | 
 | 647 |   </dd> | 
 | 648 |  | 
 | 649 |   <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt> | 
 | 650 |  | 
 | 651 |   <dd>Two declarations of an object with hidden visibility refer to the same | 
 | 652 |     object if they are in the same shared object. Usually, hidden visibility | 
 | 653 |     indicates that the symbol will not be placed into the dynamic symbol table, | 
 | 654 |     so no other module (executable or shared library) can reference it | 
 | 655 |     directly. | 
 | 656 |   </dd> | 
 | 657 |  | 
| Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 658 |   <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt> | 
 | 659 |  | 
 | 660 |   <dd>On ELF, protected visibility indicates that the symbol will be placed in | 
 | 661 |   the dynamic symbol table, but that references within the defining module will | 
 | 662 |   bind to the local symbol. That is, the symbol cannot be overridden by another | 
 | 663 |   module. | 
 | 664 |   </dd> | 
| Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 665 | </dl> | 
 | 666 |  | 
 | 667 | </div> | 
 | 668 |  | 
 | 669 | <!-- ======================================================================= --> | 
 | 670 | <div class="doc_subsection"> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 671 |   <a name="globalvars">Global Variables</a> | 
 | 672 | </div> | 
 | 673 |  | 
 | 674 | <div class="doc_text"> | 
 | 675 |  | 
| Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 676 | <p>Global variables define regions of memory allocated at compilation time | 
| Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 677 | instead of run-time.  Global variables may optionally be initialized, may have | 
| Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 678 | an explicit section to be placed in, and may have an optional explicit alignment | 
 | 679 | specified.  A variable may be defined as "thread_local", which means that it | 
 | 680 | will not be shared by threads (each thread will have a separated copy of the | 
 | 681 | variable).  A variable may be defined as a global "constant," which indicates | 
 | 682 | that the contents of the variable will <b>never</b> be modified (enabling better | 
| Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 683 | optimization, allowing the global data to be placed in the read-only section of | 
 | 684 | an executable, etc).  Note that variables that need runtime initialization | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 685 | cannot be marked "constant" as there is a store to the variable.</p> | 
| Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 686 |  | 
 | 687 | <p> | 
 | 688 | LLVM explicitly allows <em>declarations</em> of global variables to be marked | 
 | 689 | constant, even if the final definition of the global is not.  This capability | 
 | 690 | can be used to enable slightly better optimization of the program, but requires | 
 | 691 | the language definition to guarantee that optimizations based on the | 
 | 692 | 'constantness' are valid for the translation units that do not include the | 
 | 693 | definition. | 
 | 694 | </p> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 695 |  | 
 | 696 | <p>As SSA values, global variables define pointer values that are in | 
 | 697 | scope (i.e. they dominate) all basic blocks in the program.  Global | 
 | 698 | variables always define a pointer to their "content" type because they | 
 | 699 | describe a region of memory, and all memory objects in LLVM are | 
 | 700 | accessed through pointers.</p> | 
 | 701 |  | 
| Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 702 | <p>A global variable may be declared to reside in a target-specifc numbered  | 
 | 703 | address space. For targets that support them, address spaces may affect how | 
 | 704 | optimizations are performed and/or what target instructions are used to access  | 
| Christopher Lamb | d49e18d | 2007-12-12 08:44:39 +0000 | [diff] [blame] | 705 | the variable. The default address space is zero. The address space qualifier  | 
 | 706 | must precede any other attributes.</p> | 
| Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 707 |  | 
| Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 708 | <p>LLVM allows an explicit section to be specified for globals.  If the target | 
 | 709 | supports it, it will emit globals to the section specified.</p> | 
 | 710 |  | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 711 | <p>An explicit alignment may be specified for a global.  If not present, or if | 
 | 712 | the alignment is set to zero, the alignment of the global is set by the target | 
 | 713 | to whatever it feels convenient.  If an explicit alignment is specified, the  | 
 | 714 | global is forced to have at least that much alignment.  All alignments must be | 
 | 715 | a power of 2.</p> | 
 | 716 |  | 
| Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 717 | <p>For example, the following defines a global in a numbered address space with  | 
 | 718 | an initializer, section, and alignment:</p> | 
| Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 719 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 720 | <div class="doc_code"> | 
| Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 721 | <pre> | 
| Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 722 | @G = constant float 1.0 addrspace(5), section "foo", align 4 | 
| Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 723 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 724 | </div> | 
| Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 725 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 726 | </div> | 
 | 727 |  | 
 | 728 |  | 
 | 729 | <!-- ======================================================================= --> | 
 | 730 | <div class="doc_subsection"> | 
 | 731 |   <a name="functionstructure">Functions</a> | 
 | 732 | </div> | 
 | 733 |  | 
 | 734 | <div class="doc_text"> | 
 | 735 |  | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 736 | <p>LLVM function definitions consist of the "<tt>define</tt>" keyord,  | 
 | 737 | an optional <a href="#linkage">linkage type</a>, an optional  | 
| Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 738 | <a href="#visibility">visibility style</a>, an optional  | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 739 | <a href="#callingconv">calling convention</a>, a return type, an optional | 
 | 740 | <a href="#paramattrs">parameter attribute</a> for the return type, a function  | 
 | 741 | name, a (possibly empty) argument list (each with optional  | 
| Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 742 | <a href="#paramattrs">parameter attributes</a>), an optional section, an | 
| Gordon Henriksen | e754abe | 2007-12-10 03:30:21 +0000 | [diff] [blame] | 743 | optional alignment, an optional <a href="#gc">garbage collector name</a>, an | 
| Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 744 | opening curly brace, a list of basic blocks, and a closing curly brace. | 
| Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 745 |  | 
 | 746 | LLVM function declarations consist of the "<tt>declare</tt>" keyword, an | 
 | 747 | optional <a href="#linkage">linkage type</a>, an optional | 
 | 748 | <a href="#visibility">visibility style</a>, an optional  | 
 | 749 | <a href="#callingconv">calling convention</a>, a return type, an optional | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 750 | <a href="#paramattrs">parameter attribute</a> for the return type, a function  | 
| Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 751 | name, a possibly empty list of arguments, an optional alignment, and an optional | 
| Gordon Henriksen | e754abe | 2007-12-10 03:30:21 +0000 | [diff] [blame] | 752 | <a href="#gc">garbage collector name</a>.</p> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 753 |  | 
 | 754 | <p>A function definition contains a list of basic blocks, forming the CFG for | 
 | 755 | the function.  Each basic block may optionally start with a label (giving the | 
 | 756 | basic block a symbol table entry), contains a list of instructions, and ends | 
 | 757 | with a <a href="#terminators">terminator</a> instruction (such as a branch or | 
 | 758 | function return).</p> | 
 | 759 |  | 
| Chris Lattner | 4a3c901 | 2007-06-08 16:52:14 +0000 | [diff] [blame] | 760 | <p>The first basic block in a function is special in two ways: it is immediately | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 761 | executed on entrance to the function, and it is not allowed to have predecessor | 
 | 762 | basic blocks (i.e. there can not be any branches to the entry block of a | 
 | 763 | function).  Because the block can have no predecessors, it also cannot have any | 
 | 764 | <a href="#i_phi">PHI nodes</a>.</p> | 
 | 765 |  | 
| Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 766 | <p>LLVM allows an explicit section to be specified for functions.  If the target | 
 | 767 | supports it, it will emit functions to the section specified.</p> | 
 | 768 |  | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 769 | <p>An explicit alignment may be specified for a function.  If not present, or if | 
 | 770 | the alignment is set to zero, the alignment of the function is set by the target | 
 | 771 | to whatever it feels convenient.  If an explicit alignment is specified, the | 
 | 772 | function is forced to have at least that much alignment.  All alignments must be | 
 | 773 | a power of 2.</p> | 
 | 774 |  | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 775 | </div> | 
 | 776 |  | 
| Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 777 |  | 
 | 778 | <!-- ======================================================================= --> | 
 | 779 | <div class="doc_subsection"> | 
 | 780 |   <a name="aliasstructure">Aliases</a> | 
 | 781 | </div> | 
 | 782 | <div class="doc_text"> | 
 | 783 |   <p>Aliases act as "second name" for the aliasee value (which can be either | 
| Anton Korobeynikov | 726d45c | 2008-03-22 08:36:14 +0000 | [diff] [blame] | 784 |   function, global variable, another alias or bitcast of global value). Aliases | 
 | 785 |   may have an optional <a href="#linkage">linkage type</a>, and an | 
| Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 786 |   optional <a href="#visibility">visibility style</a>.</p> | 
 | 787 |  | 
 | 788 |   <h5>Syntax:</h5> | 
 | 789 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 790 | <div class="doc_code"> | 
| Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 791 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 792 | @<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee> | 
| Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 793 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 794 | </div> | 
| Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 795 |  | 
 | 796 | </div> | 
 | 797 |  | 
 | 798 |  | 
 | 799 |  | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 800 | <!-- ======================================================================= --> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 801 | <div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div> | 
 | 802 | <div class="doc_text"> | 
 | 803 |   <p>The return type and each parameter of a function type may have a set of | 
 | 804 |   <i>parameter attributes</i> associated with them. Parameter attributes are | 
 | 805 |   used to communicate additional information about the result or parameters of | 
| Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 806 |   a function. Parameter attributes are considered to be part of the function, | 
 | 807 |   not of the function type, so functions with different parameter attributes | 
 | 808 |   can have the same function type.</p> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 809 |  | 
| Reid Spencer | 950e9f8 | 2007-01-15 18:27:39 +0000 | [diff] [blame] | 810 |   <p>Parameter attributes are simple keywords that follow the type specified. If | 
 | 811 |   multiple parameter attributes are needed, they are space separated. For  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 812 |   example:</p> | 
 | 813 |  | 
 | 814 | <div class="doc_code"> | 
 | 815 | <pre> | 
| Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 816 | declare i32 @printf(i8* noalias , ...) nounwind | 
 | 817 | declare i32 @atoi(i8*) nounwind readonly | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 818 | </pre> | 
 | 819 | </div> | 
 | 820 |  | 
| Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 821 |   <p>Note that any attributes for the function result (<tt>nounwind</tt>, | 
 | 822 |   <tt>readonly</tt>) come immediately after the argument list.</p> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 823 |  | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 824 |   <p>Currently, only the following parameter attributes are defined:</p> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 825 |   <dl> | 
| Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 826 |     <dt><tt>zeroext</tt></dt> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 827 |     <dd>This indicates that the parameter should be zero extended just before | 
 | 828 |     a call to this function.</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 829 |  | 
| Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 830 |     <dt><tt>signext</tt></dt> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 831 |     <dd>This indicates that the parameter should be sign extended just before | 
 | 832 |     a call to this function.</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 833 |  | 
| Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 834 |     <dt><tt>inreg</tt></dt> | 
 | 835 |     <dd>This indicates that the parameter should be placed in register (if | 
| Anton Korobeynikov | 66a8c8c | 2007-01-28 15:27:21 +0000 | [diff] [blame] | 836 |     possible) during assembling function call. Support for this attribute is | 
 | 837 |     target-specific</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 838 |  | 
 | 839 |     <dt><tt>byval</tt></dt> | 
| Chris Lattner | 0747baa | 2008-01-15 04:34:22 +0000 | [diff] [blame] | 840 |     <dd>This indicates that the pointer parameter should really be passed by | 
 | 841 |     value to the function.  The attribute implies that a hidden copy of the | 
 | 842 |     pointee is made between the caller and the callee, so the callee is unable | 
 | 843 |     to modify the value in the callee.  This attribute is only valid on llvm | 
 | 844 |     pointer arguments.  It is generally used to pass structs and arrays by | 
 | 845 |     value, but is also valid on scalars (even though this is silly).</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 846 |  | 
| Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 847 |     <dt><tt>sret</tt></dt> | 
| Duncan Sands | e26dec6 | 2008-02-18 04:19:38 +0000 | [diff] [blame] | 848 |     <dd>This indicates that the pointer parameter specifies the address of a | 
 | 849 |     structure that is the return value of the function in the source program. | 
| Duncan Sands | b7f0c08 | 2008-03-17 12:17:41 +0000 | [diff] [blame] | 850 |     Loads and stores to the structure are assumed not to trap. | 
| Duncan Sands | e26dec6 | 2008-02-18 04:19:38 +0000 | [diff] [blame] | 851 |     May only be applied to the first parameter.</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 852 |  | 
| Zhou Sheng | febca34 | 2007-06-05 05:28:26 +0000 | [diff] [blame] | 853 |     <dt><tt>noalias</tt></dt> | 
| Owen Anderson | 117bbd3 | 2008-02-18 04:09:01 +0000 | [diff] [blame] | 854 |     <dd>This indicates that the parameter does not alias any global or any other | 
 | 855 |     parameter.  The caller is responsible for ensuring that this is the case, | 
 | 856 |     usually by placing the value in a stack allocation.</dd> | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 857 |  | 
| Reid Spencer | 2dc5201 | 2007-03-22 02:18:56 +0000 | [diff] [blame] | 858 |     <dt><tt>noreturn</tt></dt> | 
 | 859 |     <dd>This function attribute indicates that the function never returns. This | 
 | 860 |     indicates to LLVM that every call to this function should be treated as if | 
 | 861 |     an <tt>unreachable</tt> instruction immediately followed the call.</dd>  | 
| Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 862 |  | 
| Reid Spencer | 6760612 | 2007-03-22 02:02:11 +0000 | [diff] [blame] | 863 |     <dt><tt>nounwind</tt></dt> | 
| Duncan Sands | b7f0c08 | 2008-03-17 12:17:41 +0000 | [diff] [blame] | 864 |     <dd>This function attribute indicates that no exceptions unwind out of the | 
 | 865 |     function.  Usually this is because the function makes no use of exceptions, | 
 | 866 |     but it may also be that the function catches any exceptions thrown when | 
 | 867 |     executing it.</dd> | 
 | 868 |  | 
| Duncan Sands | 50f19f5 | 2007-07-27 19:57:41 +0000 | [diff] [blame] | 869 |     <dt><tt>nest</tt></dt> | 
 | 870 |     <dd>This indicates that the parameter can be excised using the | 
 | 871 |     <a href="#int_trampoline">trampoline intrinsics</a>.</dd> | 
| Duncan Sands | ed4a2f1 | 2007-11-22 20:23:04 +0000 | [diff] [blame] | 872 |     <dt><tt>readonly</tt></dt> | 
| Duncan Sands | f04d584 | 2007-11-14 21:14:02 +0000 | [diff] [blame] | 873 |     <dd>This function attribute indicates that the function has no side-effects | 
| Duncan Sands | ed4a2f1 | 2007-11-22 20:23:04 +0000 | [diff] [blame] | 874 |     except for producing a return value or throwing an exception.  The value | 
 | 875 |     returned must only depend on the function arguments and/or global variables. | 
 | 876 |     It may use values obtained by dereferencing pointers.</dd> | 
 | 877 |     <dt><tt>readnone</tt></dt> | 
 | 878 |     <dd>A <tt>readnone</tt> function has the same restrictions as a <tt>readonly</tt> | 
| Duncan Sands | f04d584 | 2007-11-14 21:14:02 +0000 | [diff] [blame] | 879 |     function, but in addition it is not allowed to dereference any pointer arguments | 
 | 880 |     or global variables. | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 881 |   </dl> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 882 |  | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 883 | </div> | 
 | 884 |  | 
 | 885 | <!-- ======================================================================= --> | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 886 | <div class="doc_subsection"> | 
| Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 887 |   <a name="gc">Garbage Collector Names</a> | 
 | 888 | </div> | 
 | 889 |  | 
 | 890 | <div class="doc_text"> | 
 | 891 | <p>Each function may specify a garbage collector name, which is simply a | 
 | 892 | string.</p> | 
 | 893 |  | 
 | 894 | <div class="doc_code"><pre | 
 | 895 | >define void @f() gc "name" { ...</pre></div> | 
 | 896 |  | 
 | 897 | <p>The compiler declares the supported values of <i>name</i>. Specifying a | 
 | 898 | collector which will cause the compiler to alter its output in order to support | 
 | 899 | the named garbage collection algorithm.</p> | 
 | 900 | </div> | 
 | 901 |  | 
 | 902 | <!-- ======================================================================= --> | 
 | 903 | <div class="doc_subsection"> | 
| Chris Lattner | 1eeeb0c | 2006-04-08 04:40:53 +0000 | [diff] [blame] | 904 |   <a name="moduleasm">Module-Level Inline Assembly</a> | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 905 | </div> | 
 | 906 |  | 
 | 907 | <div class="doc_text"> | 
 | 908 | <p> | 
 | 909 | Modules may contain "module-level inline asm" blocks, which corresponds to the | 
 | 910 | GCC "file scope inline asm" blocks.  These blocks are internally concatenated by | 
 | 911 | LLVM and treated as a single unit, but may be separated in the .ll file if | 
 | 912 | desired.  The syntax is very simple: | 
 | 913 | </p> | 
 | 914 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 915 | <div class="doc_code"> | 
 | 916 | <pre> | 
 | 917 | module asm "inline asm code goes here" | 
 | 918 | module asm "more can go here" | 
 | 919 | </pre> | 
 | 920 | </div> | 
| Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 921 |  | 
 | 922 | <p>The strings can contain any character by escaping non-printable characters. | 
 | 923 |    The escape sequence used is simply "\xx" where "xx" is the two digit hex code | 
 | 924 |    for the number. | 
 | 925 | </p> | 
 | 926 |  | 
 | 927 | <p> | 
 | 928 |   The inline asm code is simply printed to the machine code .s file when | 
 | 929 |   assembly code is generated. | 
 | 930 | </p> | 
 | 931 | </div> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 932 |  | 
| Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 933 | <!-- ======================================================================= --> | 
 | 934 | <div class="doc_subsection"> | 
 | 935 |   <a name="datalayout">Data Layout</a> | 
 | 936 | </div> | 
 | 937 |  | 
 | 938 | <div class="doc_text"> | 
 | 939 | <p>A module may specify a target specific data layout string that specifies how | 
| Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 940 | data is to be laid out in memory. The syntax for the data layout is simply:</p> | 
 | 941 | <pre>    target datalayout = "<i>layout specification</i>"</pre> | 
 | 942 | <p>The <i>layout specification</i> consists of a list of specifications  | 
 | 943 | separated by the minus sign character ('-').  Each specification starts with a  | 
 | 944 | letter and may include other information after the letter to define some  | 
 | 945 | aspect of the data layout.  The specifications accepted are as follows: </p> | 
| Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 946 | <dl> | 
 | 947 |   <dt><tt>E</tt></dt> | 
 | 948 |   <dd>Specifies that the target lays out data in big-endian form. That is, the | 
 | 949 |   bits with the most significance have the lowest address location.</dd> | 
 | 950 |   <dt><tt>e</tt></dt> | 
 | 951 |   <dd>Specifies that hte target lays out data in little-endian form. That is, | 
 | 952 |   the bits with the least significance have the lowest address location.</dd> | 
 | 953 |   <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> | 
 | 954 |   <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and  | 
 | 955 |   <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i> | 
 | 956 |   alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted | 
 | 957 |   too.</dd> | 
 | 958 |   <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> | 
 | 959 |   <dd>This specifies the alignment for an integer type of a given bit | 
 | 960 |   <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd> | 
 | 961 |   <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> | 
 | 962 |   <dd>This specifies the alignment for a vector type of a given bit  | 
 | 963 |   <i>size</i>.</dd> | 
 | 964 |   <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> | 
 | 965 |   <dd>This specifies the alignment for a floating point type of a given bit  | 
 | 966 |   <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64 | 
 | 967 |   (double).</dd> | 
 | 968 |   <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> | 
 | 969 |   <dd>This specifies the alignment for an aggregate type of a given bit | 
 | 970 |   <i>size</i>.</dd> | 
 | 971 | </dl> | 
 | 972 | <p>When constructing the data layout for a given target, LLVM starts with a | 
 | 973 | default set of specifications which are then (possibly) overriden by the | 
 | 974 | specifications in the <tt>datalayout</tt> keyword. The default specifications | 
 | 975 | are given in this list:</p> | 
 | 976 | <ul> | 
 | 977 |   <li><tt>E</tt> - big endian</li> | 
 | 978 |   <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li> | 
 | 979 |   <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li> | 
 | 980 |   <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li> | 
 | 981 |   <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li> | 
 | 982 |   <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li> | 
 | 983 |   <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred | 
 | 984 |   alignment of 64-bits</li> | 
 | 985 |   <li><tt>f32:32:32</tt> - float is 32-bit aligned</li> | 
 | 986 |   <li><tt>f64:64:64</tt> - double is 64-bit aligned</li> | 
 | 987 |   <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li> | 
 | 988 |   <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li> | 
 | 989 |   <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li> | 
 | 990 | </ul> | 
 | 991 | <p>When llvm is determining the alignment for a given type, it uses the  | 
 | 992 | following rules: | 
 | 993 | <ol> | 
 | 994 |   <li>If the type sought is an exact match for one of the specifications, that | 
 | 995 |   specification is used.</li> | 
 | 996 |   <li>If no match is found, and the type sought is an integer type, then the | 
 | 997 |   smallest integer type that is larger than the bitwidth of the sought type is | 
 | 998 |   used. If none of the specifications are larger than the bitwidth then the the | 
 | 999 |   largest integer type is used. For example, given the default specifications | 
 | 1000 |   above, the i7 type will use the alignment of i8 (next largest) while both | 
 | 1001 |   i65 and i256 will use the alignment of i64 (largest specified).</li> | 
 | 1002 |   <li>If no match is found, and the type sought is a vector type, then the | 
 | 1003 |   largest vector type that is smaller than the sought vector type will be used | 
 | 1004 |   as a fall back.  This happens because <128 x double> can be implemented in  | 
 | 1005 |   terms of 64 <2 x double>, for example.</li> | 
 | 1006 | </ol> | 
 | 1007 | </div> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1008 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1009 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1010 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> | 
 | 1011 | <!-- *********************************************************************** --> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1012 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1013 | <div class="doc_text"> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1014 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1015 | <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] | 1016 | intermediate representation.  Being typed enables a number of | 
 | 1017 | optimizations to be performed on the IR directly, without having to do | 
 | 1018 | extra analyses on the side before the transformation.  A strong type | 
 | 1019 | system makes it easier to read the generated code and enables novel | 
 | 1020 | analyses and transformations that are not feasible to perform on normal | 
 | 1021 | three address code representations.</p> | 
| Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1022 |  | 
 | 1023 | </div> | 
 | 1024 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1025 | <!-- ======================================================================= --> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1026 | <div class="doc_subsection"> <a name="t_classifications">Type | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1027 | Classifications</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1028 | <div class="doc_text"> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1029 | <p>The types fall into a few useful | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1030 | classifications:</p> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1031 |  | 
 | 1032 | <table border="1" cellspacing="0" cellpadding="4"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1033 |   <tbody> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1034 |     <tr><th>Classification</th><th>Types</th></tr> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1035 |     <tr> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1036 |       <td><a href="#t_integer">integer</a></td> | 
| Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1037 |       <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1038 |     </tr> | 
 | 1039 |     <tr> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1040 |       <td><a href="#t_floating">floating point</a></td> | 
 | 1041 |       <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1042 |     </tr> | 
 | 1043 |     <tr> | 
 | 1044 |       <td><a name="t_firstclass">first class</a></td> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1045 |       <td><a href="#t_integer">integer</a>, | 
 | 1046 |           <a href="#t_floating">floating point</a>, | 
 | 1047 |           <a href="#t_pointer">pointer</a>, | 
| Dan Gohman | 0066db6 | 2008-06-18 18:42:13 +0000 | [diff] [blame] | 1048 |           <a href="#t_vector">vector</a>, | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 1049 |           <a href="#t_struct">structure</a>, | 
 | 1050 |           <a href="#t_array">array</a>, | 
| Dan Gohman | ade5faa | 2008-05-23 22:50:26 +0000 | [diff] [blame] | 1051 |           <a href="#t_label">label</a>. | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1052 |       </td> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1053 |     </tr> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1054 |     <tr> | 
 | 1055 |       <td><a href="#t_primitive">primitive</a></td> | 
 | 1056 |       <td><a href="#t_label">label</a>, | 
 | 1057 |           <a href="#t_void">void</a>, | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1058 |           <a href="#t_floating">floating point</a>.</td> | 
 | 1059 |     </tr> | 
 | 1060 |     <tr> | 
 | 1061 |       <td><a href="#t_derived">derived</a></td> | 
 | 1062 |       <td><a href="#t_integer">integer</a>, | 
 | 1063 |           <a href="#t_array">array</a>, | 
 | 1064 |           <a href="#t_function">function</a>, | 
 | 1065 |           <a href="#t_pointer">pointer</a>, | 
 | 1066 |           <a href="#t_struct">structure</a>, | 
 | 1067 |           <a href="#t_pstruct">packed structure</a>, | 
 | 1068 |           <a href="#t_vector">vector</a>, | 
 | 1069 |           <a href="#t_opaque">opaque</a>. | 
 | 1070 |     </tr> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1071 |   </tbody> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1072 | </table> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1073 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1074 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the | 
 | 1075 | most important.  Values of these types are the only ones which can be | 
 | 1076 | produced by instructions, passed as arguments, or used as operands to | 
| Dan Gohman | c4b49eb | 2008-05-23 21:53:15 +0000 | [diff] [blame] | 1077 | instructions.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1078 | </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1079 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1080 | <!-- ======================================================================= --> | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1081 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> | 
| Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1082 |  | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1083 | <div class="doc_text"> | 
 | 1084 | <p>The primitive types are the fundamental building blocks of the LLVM | 
 | 1085 | system.</p> | 
 | 1086 |  | 
| Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1087 | </div> | 
 | 1088 |  | 
| Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1089 | <!-- _______________________________________________________________________ --> | 
 | 1090 | <div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div> | 
 | 1091 |  | 
 | 1092 | <div class="doc_text"> | 
 | 1093 |       <table> | 
 | 1094 |         <tbody> | 
 | 1095 |           <tr><th>Type</th><th>Description</th></tr> | 
 | 1096 |           <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr> | 
 | 1097 |           <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr> | 
 | 1098 |           <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr> | 
 | 1099 |           <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr> | 
 | 1100 |           <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr> | 
 | 1101 |         </tbody> | 
 | 1102 |       </table> | 
 | 1103 | </div> | 
 | 1104 |  | 
 | 1105 | <!-- _______________________________________________________________________ --> | 
 | 1106 | <div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div> | 
 | 1107 |  | 
 | 1108 | <div class="doc_text"> | 
 | 1109 | <h5>Overview:</h5> | 
 | 1110 | <p>The void type does not represent any value and has no size.</p> | 
 | 1111 |  | 
 | 1112 | <h5>Syntax:</h5> | 
 | 1113 |  | 
 | 1114 | <pre> | 
 | 1115 |   void | 
 | 1116 | </pre> | 
 | 1117 | </div> | 
 | 1118 |  | 
 | 1119 | <!-- _______________________________________________________________________ --> | 
 | 1120 | <div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div> | 
 | 1121 |  | 
 | 1122 | <div class="doc_text"> | 
 | 1123 | <h5>Overview:</h5> | 
 | 1124 | <p>The label type represents code labels.</p> | 
 | 1125 |  | 
 | 1126 | <h5>Syntax:</h5> | 
 | 1127 |  | 
 | 1128 | <pre> | 
 | 1129 |   label | 
 | 1130 | </pre> | 
 | 1131 | </div> | 
 | 1132 |  | 
 | 1133 |  | 
 | 1134 | <!-- ======================================================================= --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1135 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1136 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1137 | <div class="doc_text"> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1138 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1139 | <p>The real power in LLVM comes from the derived types in the system.  | 
 | 1140 | This is what allows a programmer to represent arrays, functions, | 
 | 1141 | pointers, and other useful types.  Note that these derived types may be | 
 | 1142 | recursive: For example, it is possible to have a two dimensional array.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1143 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1144 | </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1145 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1146 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1147 | <div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div> | 
 | 1148 |  | 
 | 1149 | <div class="doc_text"> | 
 | 1150 |  | 
 | 1151 | <h5>Overview:</h5> | 
 | 1152 | <p>The integer type is a very simple derived type that simply specifies an | 
 | 1153 | arbitrary bit width for the integer type desired. Any bit width from 1 bit to | 
 | 1154 | 2^23-1 (about 8 million) can be specified.</p> | 
 | 1155 |  | 
 | 1156 | <h5>Syntax:</h5> | 
 | 1157 |  | 
 | 1158 | <pre> | 
 | 1159 |   iN | 
 | 1160 | </pre> | 
 | 1161 |  | 
 | 1162 | <p>The number of bits the integer will occupy is specified by the <tt>N</tt> | 
 | 1163 | value.</p> | 
 | 1164 |  | 
 | 1165 | <h5>Examples:</h5> | 
 | 1166 | <table class="layout"> | 
| Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 1167 |   <tbody> | 
 | 1168 |   <tr> | 
 | 1169 |     <td><tt>i1</tt></td> | 
 | 1170 |     <td>a single-bit integer.</td> | 
 | 1171 |   </tr><tr> | 
 | 1172 |     <td><tt>i32</tt></td> | 
 | 1173 |     <td>a 32-bit integer.</td> | 
 | 1174 |   </tr><tr> | 
 | 1175 |     <td><tt>i1942652</tt></td> | 
 | 1176 |     <td>a really big integer of over 1 million bits.</td> | 
| Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1177 |   </tr> | 
| Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 1178 |   </tbody> | 
| Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1179 | </table> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1180 | </div> | 
| Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1181 |  | 
 | 1182 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1183 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1184 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1185 | <div class="doc_text"> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1186 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1187 | <h5>Overview:</h5> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1188 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1189 | <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] | 1190 | sequentially in memory.  The array type requires a size (number of | 
 | 1191 | elements) and an underlying data type.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1192 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1193 | <h5>Syntax:</h5> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1194 |  | 
 | 1195 | <pre> | 
 | 1196 |   [<# elements> x <elementtype>] | 
 | 1197 | </pre> | 
 | 1198 |  | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1199 | <p>The number of elements is a constant integer value; elementtype may | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1200 | be any type with a size.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1201 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1202 | <h5>Examples:</h5> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1203 | <table class="layout"> | 
 | 1204 |   <tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1205 |     <td class="left"><tt>[40 x i32]</tt></td> | 
 | 1206 |     <td class="left">Array of 40 32-bit integer values.</td> | 
 | 1207 |   </tr> | 
 | 1208 |   <tr class="layout"> | 
 | 1209 |     <td class="left"><tt>[41 x i32]</tt></td> | 
 | 1210 |     <td class="left">Array of 41 32-bit integer values.</td> | 
 | 1211 |   </tr> | 
 | 1212 |   <tr class="layout"> | 
 | 1213 |     <td class="left"><tt>[4 x i8]</tt></td> | 
 | 1214 |     <td class="left">Array of 4 8-bit integer values.</td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1215 |   </tr> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1216 | </table> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1217 | <p>Here are some examples of multidimensional arrays:</p> | 
 | 1218 | <table class="layout"> | 
 | 1219 |   <tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1220 |     <td class="left"><tt>[3 x [4 x i32]]</tt></td> | 
 | 1221 |     <td class="left">3x4 array of 32-bit integer values.</td> | 
 | 1222 |   </tr> | 
 | 1223 |   <tr class="layout"> | 
 | 1224 |     <td class="left"><tt>[12 x [10 x float]]</tt></td> | 
 | 1225 |     <td class="left">12x10 array of single precision floating point values.</td> | 
 | 1226 |   </tr> | 
 | 1227 |   <tr class="layout"> | 
 | 1228 |     <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td> | 
 | 1229 |     <td class="left">2x3x4 array of 16-bit integer  values.</td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1230 |   </tr> | 
 | 1231 | </table> | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1232 |  | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1233 | <p>Note that 'variable sized arrays' can be implemented in LLVM with a zero  | 
 | 1234 | length array.  Normally, accesses past the end of an array are undefined in | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1235 | LLVM (e.g. it is illegal to access the 5th element of a 3 element array). | 
 | 1236 | As a special case, however, zero length arrays are recognized to be variable | 
 | 1237 | length.  This allows implementation of 'pascal style arrays' with the  LLVM | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1238 | type "{ i32, [0 x float]}", for example.</p> | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1239 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1240 | </div> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1241 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1242 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1243 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1244 | <div class="doc_text"> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1245 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1246 | <h5>Overview:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1247 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1248 | <p>The function type can be thought of as a function signature.  It | 
| Devang Patel | a582f40 | 2008-03-24 05:35:41 +0000 | [diff] [blame] | 1249 | consists of a return type and a list of formal parameter types. The | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1250 | return type of a function type is a scalar type, a void type, or a struct type.  | 
| Devang Patel | 7a3ad1a | 2008-03-24 20:52:42 +0000 | [diff] [blame] | 1251 | If the return type is a struct type then all struct elements must be of first  | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1252 | class types, and the struct must have at least one element.</p> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1253 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1254 | <h5>Syntax:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1255 |  | 
 | 1256 | <pre> | 
 | 1257 |   <returntype list> (<parameter list>) | 
 | 1258 | </pre> | 
 | 1259 |  | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1260 | <p>...where '<tt><parameter list></tt>' is a comma-separated list of type | 
| Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 1261 | specifiers.  Optionally, the parameter list may include a type <tt>...</tt>, | 
| Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1262 | which indicates that the function takes a variable number of arguments. | 
 | 1263 | Variable argument functions can access their arguments with the <a | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1264 |  href="#int_varargs">variable argument handling intrinsic</a> functions. | 
 | 1265 | '<tt><returntype list></tt>' is a comma-separated list of | 
 | 1266 | <a href="#t_firstclass">first class</a> type specifiers.</p> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1267 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1268 | <h5>Examples:</h5> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1269 | <table class="layout"> | 
 | 1270 |   <tr class="layout"> | 
| Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1271 |     <td class="left"><tt>i32 (i32)</tt></td> | 
 | 1272 |     <td class="left">function taking an <tt>i32</tt>, returning an <tt>i32</tt> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1273 |     </td> | 
| Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1274 |   </tr><tr class="layout"> | 
| Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 1275 |     <td class="left"><tt>float (i16 signext, i32 *) * | 
| Reid Spencer | f17a0b7 | 2006-12-31 07:20:23 +0000 | [diff] [blame] | 1276 |     </tt></td> | 
| Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1277 |     <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes  | 
 | 1278 |       an <tt>i16</tt> that should be sign extended and a  | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1279 |       <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning  | 
| Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1280 |       <tt>float</tt>. | 
 | 1281 |     </td> | 
 | 1282 |   </tr><tr class="layout"> | 
 | 1283 |     <td class="left"><tt>i32 (i8*, ...)</tt></td> | 
 | 1284 |     <td class="left">A vararg function that takes at least one  | 
| Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1285 |       <a href="#t_pointer">pointer</a> to <tt>i8 </tt> (char in C),  | 
| Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1286 |       which returns an integer.  This is the signature for <tt>printf</tt> in  | 
 | 1287 |       LLVM. | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1288 |     </td> | 
| Devang Patel | a582f40 | 2008-03-24 05:35:41 +0000 | [diff] [blame] | 1289 |   </tr><tr class="layout"> | 
 | 1290 |     <td class="left"><tt>{i32, i32} (i32)</tt></td> | 
| Devang Patel | 3a5bff8 | 2008-03-24 18:10:52 +0000 | [diff] [blame] | 1291 |     <td class="left">A function taking an <tt>i32></tt>, returning two  | 
 | 1292 |         <tt> i32 </tt> values as an aggregate of type <tt>{ i32, i32 }</tt> | 
| Devang Patel | a582f40 | 2008-03-24 05:35:41 +0000 | [diff] [blame] | 1293 |     </td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1294 |   </tr> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1295 | </table> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1296 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1297 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1298 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1299 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1300 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1301 | <h5>Overview:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1302 | <p>The structure type is used to represent a collection of data members | 
 | 1303 | together in memory.  The packing of the field types is defined to match | 
 | 1304 | the ABI of the underlying processor.  The elements of a structure may | 
 | 1305 | be any type that has a size.</p> | 
 | 1306 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> | 
 | 1307 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a | 
 | 1308 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' | 
 | 1309 | instruction.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1310 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1311 | <pre>  { <type list> }<br></pre> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1312 | <h5>Examples:</h5> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1313 | <table class="layout"> | 
 | 1314 |   <tr class="layout"> | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1315 |     <td class="left"><tt>{ i32, i32, i32 }</tt></td> | 
 | 1316 |     <td class="left">A triple of three <tt>i32</tt> values</td> | 
 | 1317 |   </tr><tr class="layout"> | 
 | 1318 |     <td class="left"><tt>{ float, i32 (i32) * }</tt></td> | 
 | 1319 |     <td class="left">A pair, where the first element is a <tt>float</tt> and the | 
 | 1320 |       second element is a <a href="#t_pointer">pointer</a> to a | 
 | 1321 |       <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning | 
 | 1322 |       an <tt>i32</tt>.</td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1323 |   </tr> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1324 | </table> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1325 | </div> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1326 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1327 | <!-- _______________________________________________________________________ --> | 
| Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1328 | <div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a> | 
 | 1329 | </div> | 
 | 1330 | <div class="doc_text"> | 
 | 1331 | <h5>Overview:</h5> | 
 | 1332 | <p>The packed structure type is used to represent a collection of data members | 
 | 1333 | together in memory.  There is no padding between fields.  Further, the alignment | 
 | 1334 | of a packed structure is 1 byte.  The elements of a packed structure may | 
 | 1335 | be any type that has a size.</p> | 
 | 1336 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> | 
 | 1337 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a | 
 | 1338 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' | 
 | 1339 | instruction.</p> | 
 | 1340 | <h5>Syntax:</h5> | 
 | 1341 | <pre>  < { <type list> } > <br></pre> | 
 | 1342 | <h5>Examples:</h5> | 
 | 1343 | <table class="layout"> | 
 | 1344 |   <tr class="layout"> | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1345 |     <td class="left"><tt>< { i32, i32, i32 } ></tt></td> | 
 | 1346 |     <td class="left">A triple of three <tt>i32</tt> values</td> | 
 | 1347 |   </tr><tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1348 |   <td class="left"><tt>< { float, i32 (i32)* } ></tt></td> | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1349 |     <td class="left">A pair, where the first element is a <tt>float</tt> and the | 
 | 1350 |       second element is a <a href="#t_pointer">pointer</a> to a | 
 | 1351 |       <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning | 
 | 1352 |       an <tt>i32</tt>.</td> | 
| Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1353 |   </tr> | 
 | 1354 | </table> | 
 | 1355 | </div> | 
 | 1356 |  | 
 | 1357 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1358 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1359 | <div class="doc_text"> | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1360 | <h5>Overview:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1361 | <p>As in many languages, the pointer type represents a pointer or | 
| Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 1362 | reference to another object, which must live in memory. Pointer types may have  | 
 | 1363 | an optional address space attribute defining the target-specific numbered  | 
 | 1364 | address space where the pointed-to object resides. The default address space is  | 
 | 1365 | zero.</p> | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1366 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1367 | <pre>  <type> *<br></pre> | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1368 | <h5>Examples:</h5> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1369 | <table class="layout"> | 
 | 1370 |   <tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1371 |     <td class="left"><tt>[4x i32]*</tt></td> | 
 | 1372 |     <td class="left">A <a href="#t_pointer">pointer</a> to <a | 
 | 1373 |                     href="#t_array">array</a> of four <tt>i32</tt> values.</td> | 
 | 1374 |   </tr> | 
 | 1375 |   <tr class="layout"> | 
 | 1376 |     <td class="left"><tt>i32 (i32 *) *</tt></td> | 
 | 1377 |     <td class="left"> A <a href="#t_pointer">pointer</a> to a <a | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1378 |       href="#t_function">function</a> that takes an <tt>i32*</tt>, returning an | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1379 |       <tt>i32</tt>.</td> | 
 | 1380 |   </tr> | 
 | 1381 |   <tr class="layout"> | 
 | 1382 |     <td class="left"><tt>i32 addrspace(5)*</tt></td> | 
 | 1383 |     <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value | 
 | 1384 |      that resides in address space #5.</td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1385 |   </tr> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1386 | </table> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1387 | </div> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1388 |  | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1389 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1390 | <div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1391 | <div class="doc_text"> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1392 |  | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1393 | <h5>Overview:</h5> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1394 |  | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1395 | <p>A vector type is a simple derived type that represents a vector | 
 | 1396 | of elements.  Vector types are used when multiple primitive data  | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1397 | are operated in parallel using a single instruction (SIMD).  | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1398 | A vector type requires a size (number of | 
| Chris Lattner | b8d172f | 2005-11-10 01:44:22 +0000 | [diff] [blame] | 1399 | elements) and an underlying primitive data type.  Vectors must have a power | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1400 | of two length (1, 2, 4, 8, 16 ...).  Vector types are | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1401 | considered <a href="#t_firstclass">first class</a>.</p> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1402 |  | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1403 | <h5>Syntax:</h5> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1404 |  | 
 | 1405 | <pre> | 
 | 1406 |   < <# elements> x <elementtype> > | 
 | 1407 | </pre> | 
 | 1408 |  | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1409 | <p>The number of elements is a constant integer value; elementtype may | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1410 | be any integer or floating point type.</p> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1411 |  | 
| Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1412 | <h5>Examples:</h5> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1413 |  | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1414 | <table class="layout"> | 
 | 1415 |   <tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1416 |     <td class="left"><tt><4 x i32></tt></td> | 
 | 1417 |     <td class="left">Vector of 4 32-bit integer values.</td> | 
 | 1418 |   </tr> | 
 | 1419 |   <tr class="layout"> | 
 | 1420 |     <td class="left"><tt><8 x float></tt></td> | 
 | 1421 |     <td class="left">Vector of 8 32-bit floating-point values.</td> | 
 | 1422 |   </tr> | 
 | 1423 |   <tr class="layout"> | 
 | 1424 |     <td class="left"><tt><2 x i64></tt></td> | 
 | 1425 |     <td class="left">Vector of 2 64-bit integer values.</td> | 
| Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1426 |   </tr> | 
 | 1427 | </table> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1428 | </div> | 
 | 1429 |  | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1430 | <!-- _______________________________________________________________________ --> | 
 | 1431 | <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div> | 
 | 1432 | <div class="doc_text"> | 
 | 1433 |  | 
 | 1434 | <h5>Overview:</h5> | 
 | 1435 |  | 
 | 1436 | <p>Opaque types are used to represent unknown types in the system.  This | 
| Gordon Henriksen | 8ac04ff | 2007-10-14 00:34:53 +0000 | [diff] [blame] | 1437 | corresponds (for example) to the C notion of a forward declared structure type. | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1438 | In LLVM, opaque types can eventually be resolved to any type (not just a | 
 | 1439 | structure type).</p> | 
 | 1440 |  | 
 | 1441 | <h5>Syntax:</h5> | 
 | 1442 |  | 
 | 1443 | <pre> | 
 | 1444 |   opaque | 
 | 1445 | </pre> | 
 | 1446 |  | 
 | 1447 | <h5>Examples:</h5> | 
 | 1448 |  | 
 | 1449 | <table class="layout"> | 
 | 1450 |   <tr class="layout"> | 
| Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1451 |     <td class="left"><tt>opaque</tt></td> | 
 | 1452 |     <td class="left">An opaque type.</td> | 
| Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1453 |   </tr> | 
 | 1454 | </table> | 
 | 1455 | </div> | 
 | 1456 |  | 
 | 1457 |  | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1458 | <!-- *********************************************************************** --> | 
 | 1459 | <div class="doc_section"> <a name="constants">Constants</a> </div> | 
 | 1460 | <!-- *********************************************************************** --> | 
 | 1461 |  | 
 | 1462 | <div class="doc_text"> | 
 | 1463 |  | 
 | 1464 | <p>LLVM has several different basic types of constants.  This section describes | 
 | 1465 | them all and their syntax.</p> | 
 | 1466 |  | 
 | 1467 | </div> | 
 | 1468 |  | 
 | 1469 | <!-- ======================================================================= --> | 
| Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1470 | <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1471 |  | 
 | 1472 | <div class="doc_text"> | 
 | 1473 |  | 
 | 1474 | <dl> | 
 | 1475 |   <dt><b>Boolean constants</b></dt> | 
 | 1476 |  | 
 | 1477 |   <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1478 |   constants of the <tt><a href="#t_primitive">i1</a></tt> type. | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1479 |   </dd> | 
 | 1480 |  | 
 | 1481 |   <dt><b>Integer constants</b></dt> | 
 | 1482 |  | 
| Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1483 |   <dd>Standard integers (such as '4') are constants of the <a | 
| Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1484 |   href="#t_integer">integer</a> type.  Negative numbers may be used with  | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1485 |   integer types. | 
 | 1486 |   </dd> | 
 | 1487 |  | 
 | 1488 |   <dt><b>Floating point constants</b></dt> | 
 | 1489 |  | 
 | 1490 |   <dd>Floating point constants use standard decimal notation (e.g. 123.421), | 
 | 1491 |   exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 1492 |   notation (see below).  The assembler requires the exact decimal value of | 
 | 1493 |   a floating-point constant.  For example, the assembler accepts 1.25 but | 
 | 1494 |   rejects 1.3 because 1.3 is a repeating decimal in binary.  Floating point | 
 | 1495 |   constants must have a <a href="#t_floating">floating point</a> type. </dd> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1496 |  | 
 | 1497 |   <dt><b>Null pointer constants</b></dt> | 
 | 1498 |  | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1499 |   <dd>The identifier '<tt>null</tt>' is recognized as a null pointer constant | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1500 |   and must be of <a href="#t_pointer">pointer type</a>.</dd> | 
 | 1501 |  | 
 | 1502 | </dl> | 
 | 1503 |  | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1504 | <p>The one non-intuitive notation for constants is the optional hexadecimal form | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1505 | of floating point constants.  For example, the form '<tt>double | 
 | 1506 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double | 
 | 1507 | 4.5e+15</tt>'.  The only time hexadecimal floating point constants are required | 
| Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1508 | (and the only time that they are generated by the disassembler) is when a  | 
 | 1509 | floating point constant must be emitted but it cannot be represented as a  | 
 | 1510 | decimal floating point number.  For example, NaN's, infinities, and other  | 
 | 1511 | special values are represented in their IEEE hexadecimal format so that  | 
 | 1512 | assembly and disassembly do not cause any bits to change in the constants.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1513 |  | 
 | 1514 | </div> | 
 | 1515 |  | 
 | 1516 | <!-- ======================================================================= --> | 
 | 1517 | <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a> | 
 | 1518 | </div> | 
 | 1519 |  | 
 | 1520 | <div class="doc_text"> | 
| Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1521 | <p>Aggregate constants arise from aggregation of simple constants | 
 | 1522 | and smaller aggregate constants.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1523 |  | 
 | 1524 | <dl> | 
 | 1525 |   <dt><b>Structure constants</b></dt> | 
 | 1526 |  | 
 | 1527 |   <dd>Structure constants are represented with notation similar to structure | 
 | 1528 |   type definitions (a comma separated list of elements, surrounded by braces | 
| Chris Lattner | 64910ee | 2007-12-25 20:34:52 +0000 | [diff] [blame] | 1529 |   (<tt>{}</tt>)).  For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>", | 
 | 1530 |   where "<tt>@G</tt>" is declared as "<tt>@G = external global i32</tt>".  Structure constants | 
| Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1531 |   must have <a href="#t_struct">structure type</a>, and the number and | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1532 |   types of elements must match those specified by the type. | 
 | 1533 |   </dd> | 
 | 1534 |  | 
 | 1535 |   <dt><b>Array constants</b></dt> | 
 | 1536 |  | 
 | 1537 |   <dd>Array constants are represented with notation similar to array type | 
 | 1538 |   definitions (a comma separated list of elements, surrounded by square brackets | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1539 |   (<tt>[]</tt>)).  For example: "<tt>[ i32 42, i32 11, i32 74 ]</tt>".  Array | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1540 |   constants must have <a href="#t_array">array type</a>, and the number and | 
 | 1541 |   types of elements must match those specified by the type. | 
 | 1542 |   </dd> | 
 | 1543 |  | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1544 |   <dt><b>Vector constants</b></dt> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1545 |  | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1546 |   <dd>Vector constants are represented with notation similar to vector type | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1547 |   definitions (a comma separated list of elements, surrounded by | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1548 |   less-than/greater-than's (<tt><></tt>)).  For example: "<tt>< i32 42, | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1549 |   i32 11, i32 74, i32 100 ></tt>".  Vector constants must have <a | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1550 |   href="#t_vector">vector type</a>, and the number and types of elements must | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1551 |   match those specified by the type. | 
 | 1552 |   </dd> | 
 | 1553 |  | 
 | 1554 |   <dt><b>Zero initialization</b></dt> | 
 | 1555 |  | 
 | 1556 |   <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a | 
 | 1557 |   value to zero of <em>any</em> type, including scalar and aggregate types. | 
 | 1558 |   This is often used to avoid having to print large zero initializers (e.g. for | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1559 |   large arrays) and is always exactly equivalent to using explicit zero | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1560 |   initializers. | 
 | 1561 |   </dd> | 
 | 1562 | </dl> | 
 | 1563 |  | 
 | 1564 | </div> | 
 | 1565 |  | 
 | 1566 | <!-- ======================================================================= --> | 
 | 1567 | <div class="doc_subsection"> | 
 | 1568 |   <a name="globalconstants">Global Variable and Function Addresses</a> | 
 | 1569 | </div> | 
 | 1570 |  | 
 | 1571 | <div class="doc_text"> | 
 | 1572 |  | 
 | 1573 | <p>The addresses of <a href="#globalvars">global variables</a> and <a | 
 | 1574 | href="#functionstructure">functions</a> are always implicitly valid (link-time) | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1575 | constants.  These constants are explicitly referenced when the <a | 
 | 1576 | href="#identifiers">identifier for the global</a> is used and always have <a | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1577 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM | 
 | 1578 | file:</p> | 
 | 1579 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1580 | <div class="doc_code"> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1581 | <pre> | 
| Chris Lattner | a18a424 | 2007-06-06 18:28:13 +0000 | [diff] [blame] | 1582 | @X = global i32 17 | 
 | 1583 | @Y = global i32 42 | 
 | 1584 | @Z = global [2 x i32*] [ i32* @X, i32* @Y ] | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1585 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1586 | </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1587 |  | 
 | 1588 | </div> | 
 | 1589 |  | 
 | 1590 | <!-- ======================================================================= --> | 
| Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1591 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1592 | <div class="doc_text"> | 
| Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1593 |   <p>The string '<tt>undef</tt>' is recognized as a type-less constant that has  | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1594 |   no specific value.  Undefined values may be of any type and be used anywhere  | 
| Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1595 |   a constant is permitted.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1596 |  | 
| Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1597 |   <p>Undefined values indicate to the compiler that the program is well defined | 
 | 1598 |   no matter what value is used, giving the compiler more freedom to optimize. | 
 | 1599 |   </p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1600 | </div> | 
 | 1601 |  | 
 | 1602 | <!-- ======================================================================= --> | 
 | 1603 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> | 
 | 1604 | </div> | 
 | 1605 |  | 
 | 1606 | <div class="doc_text"> | 
 | 1607 |  | 
 | 1608 | <p>Constant expressions are used to allow expressions involving other constants | 
 | 1609 | to be used as constants.  Constant expressions may be of any <a | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1610 | href="#t_firstclass">first class</a> type and may involve any LLVM operation | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1611 | that does not have side effects (e.g. load and call are not supported).  The | 
 | 1612 | following is the syntax for constant expressions:</p> | 
 | 1613 |  | 
 | 1614 | <dl> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1615 |   <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt> | 
 | 1616 |   <dd>Truncate a constant to another type. The bit size of CST must be larger  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1617 |   than the bit size of TYPE. Both types must be integers.</dd> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1618 |  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1619 |   <dt><b><tt>zext ( CST to TYPE )</tt></b></dt> | 
 | 1620 |   <dd>Zero extend a constant to another type. The bit size of CST must be  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1621 |   smaller or equal to the bit size of TYPE.  Both types must be integers.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1622 |  | 
 | 1623 |   <dt><b><tt>sext ( CST to TYPE )</tt></b></dt> | 
 | 1624 |   <dd>Sign extend a constant to another type. The bit size of CST must be  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1625 |   smaller or equal to the bit size of TYPE.  Both types must be integers.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1626 |  | 
 | 1627 |   <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt> | 
 | 1628 |   <dd>Truncate a floating point constant to another floating point type. The  | 
 | 1629 |   size of CST must be larger than the size of TYPE. Both types must be  | 
 | 1630 |   floating point.</dd> | 
 | 1631 |  | 
 | 1632 |   <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt> | 
 | 1633 |   <dd>Floating point extend a constant to another type. The size of CST must be  | 
 | 1634 |   smaller or equal to the size of TYPE. Both types must be floating point.</dd> | 
 | 1635 |  | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 1636 |   <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1637 |   <dd>Convert a floating point constant to the corresponding unsigned integer | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1638 |   constant. TYPE must be a scalar or vector integer type. CST must be of scalar | 
 | 1639 |   or vector floating point type. Both CST and TYPE must be scalars, or vectors | 
 | 1640 |   of the same number of elements. If the  value won't fit in the integer type, | 
 | 1641 |   the results are undefined.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1642 |  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1643 |   <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1644 |   <dd>Convert a floating point constant to the corresponding signed integer | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1645 |   constant.  TYPE must be a scalar or vector integer type. CST must be of scalar | 
 | 1646 |   or vector floating point type. Both CST and TYPE must be scalars, or vectors | 
 | 1647 |   of the same number of elements. If the  value won't fit in the integer type, | 
 | 1648 |   the results are undefined.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1649 |  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1650 |   <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1651 |   <dd>Convert an unsigned integer constant to the corresponding floating point | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1652 |   constant. TYPE must be a scalar or vector floating point type. CST must be of | 
 | 1653 |   scalar or vector integer type. Both CST and TYPE must be scalars, or vectors | 
 | 1654 |   of the same number of elements. If the value won't fit in the floating point  | 
 | 1655 |   type, the results are undefined.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1656 |  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1657 |   <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1658 |   <dd>Convert a signed integer constant to the corresponding floating point | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1659 |   constant. TYPE must be a scalar or vector floating point type. CST must be of | 
 | 1660 |   scalar or vector integer type. Both CST and TYPE must be scalars, or vectors | 
 | 1661 |   of the same number of elements. If the value won't fit in the floating point  | 
 | 1662 |   type, the results are undefined.</dd> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1663 |  | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1664 |   <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt> | 
 | 1665 |   <dd>Convert a pointer typed constant to the corresponding integer constant | 
 | 1666 |   TYPE must be an integer type. CST must be of pointer type. The CST value is | 
 | 1667 |   zero extended, truncated, or unchanged to make it fit in TYPE.</dd> | 
 | 1668 |  | 
 | 1669 |   <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt> | 
 | 1670 |   <dd>Convert a integer constant to a pointer constant.  TYPE must be a | 
 | 1671 |   pointer type.  CST must be of integer type. The CST value is zero extended,  | 
 | 1672 |   truncated, or unchanged to make it fit in a pointer size. This one is  | 
 | 1673 |   <i>really</i> dangerous!</dd> | 
 | 1674 |  | 
 | 1675 |   <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1676 |   <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be | 
 | 1677 |   identical (same number of bits). The conversion is done as if the CST value | 
 | 1678 |   was stored to memory and read back as TYPE. In other words, no bits change  | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1679 |   with this operator, just the type.  This can be used for conversion of | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1680 |   vector types to any other type, as long as they have the same bit width. For | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1681 |   pointers it is only valid to cast to another pointer type. | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1682 |   </dd> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1683 |  | 
 | 1684 |   <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> | 
 | 1685 |  | 
 | 1686 |   <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on | 
 | 1687 |   constants.  As with the <a href="#i_getelementptr">getelementptr</a> | 
 | 1688 |   instruction, the index list may have zero or more indexes, which are required | 
 | 1689 |   to make sense for the type of "CSTPTR".</dd> | 
 | 1690 |  | 
| Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1691 |   <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt> | 
 | 1692 |  | 
 | 1693 |   <dd>Perform the <a href="#i_select">select operation</a> on | 
| Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1694 |   constants.</dd> | 
 | 1695 |  | 
 | 1696 |   <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt> | 
 | 1697 |   <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd> | 
 | 1698 |  | 
 | 1699 |   <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt> | 
 | 1700 |   <dd>Performs the <a href="#i_fcmp">fcmp operation</a> on constants.</dd> | 
| Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1701 |  | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 1702 |   <dt><b><tt>vicmp COND ( VAL1, VAL2 )</tt></b></dt> | 
 | 1703 |   <dd>Performs the <a href="#i_vicmp">vicmp operation</a> on constants.</dd> | 
 | 1704 |  | 
 | 1705 |   <dt><b><tt>vfcmp COND ( VAL1, VAL2 )</tt></b></dt> | 
 | 1706 |   <dd>Performs the <a href="#i_vfcmp">vfcmp operation</a> on constants.</dd> | 
 | 1707 |  | 
| Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1708 |   <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt> | 
 | 1709 |  | 
 | 1710 |   <dd>Perform the <a href="#i_extractelement">extractelement | 
 | 1711 |   operation</a> on constants. | 
 | 1712 |  | 
| Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 1713 |   <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt> | 
 | 1714 |  | 
 | 1715 |   <dd>Perform the <a href="#i_insertelement">insertelement | 
| Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1716 |     operation</a> on constants.</dd> | 
| Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 1717 |  | 
| Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 1718 |  | 
 | 1719 |   <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt> | 
 | 1720 |  | 
 | 1721 |   <dd>Perform the <a href="#i_shufflevector">shufflevector | 
| Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1722 |     operation</a> on constants.</dd> | 
| Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 1723 |  | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1724 |   <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> | 
 | 1725 |  | 
| Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1726 |   <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may  | 
 | 1727 |   be any of the <a href="#binaryops">binary</a> or <a href="#bitwiseops">bitwise | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1728 |   binary</a> operations.  The constraints on operands are the same as those for | 
 | 1729 |   the corresponding instruction (e.g. no bitwise operations on floating point | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1730 |   values are allowed).</dd> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1731 | </dl> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1732 | </div> | 
| Chris Lattner | 9ee5d22 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 1733 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1734 | <!-- *********************************************************************** --> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1735 | <div class="doc_section"> <a name="othervalues">Other Values</a> </div> | 
 | 1736 | <!-- *********************************************************************** --> | 
 | 1737 |  | 
 | 1738 | <!-- ======================================================================= --> | 
 | 1739 | <div class="doc_subsection"> | 
 | 1740 | <a name="inlineasm">Inline Assembler Expressions</a> | 
 | 1741 | </div> | 
 | 1742 |  | 
 | 1743 | <div class="doc_text"> | 
 | 1744 |  | 
 | 1745 | <p> | 
 | 1746 | LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm"> | 
 | 1747 | Module-Level Inline Assembly</a>) through the use of a special value.  This | 
 | 1748 | value represents the inline assembler as a string (containing the instructions | 
 | 1749 | to emit), a list of operand constraints (stored as a string), and a flag that  | 
 | 1750 | indicates whether or not the inline asm expression has side effects.  An example | 
 | 1751 | inline assembler expression is: | 
 | 1752 | </p> | 
 | 1753 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1754 | <div class="doc_code"> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1755 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1756 | i32 (i32) asm "bswap $0", "=r,r" | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1757 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1758 | </div> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1759 |  | 
 | 1760 | <p> | 
 | 1761 | Inline assembler expressions may <b>only</b> be used as the callee operand of | 
 | 1762 | a <a href="#i_call"><tt>call</tt> instruction</a>.  Thus, typically we have: | 
 | 1763 | </p> | 
 | 1764 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1765 | <div class="doc_code"> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1766 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1767 | %X = call i32 asm "<a href="#int_bswap">bswap</a> $0", "=r,r"(i32 %Y) | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1768 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1769 | </div> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1770 |  | 
 | 1771 | <p> | 
 | 1772 | Inline asms with side effects not visible in the constraint list must be marked | 
 | 1773 | as having side effects.  This is done through the use of the | 
 | 1774 | '<tt>sideeffect</tt>' keyword, like so: | 
 | 1775 | </p> | 
 | 1776 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1777 | <div class="doc_code"> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1778 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1779 | call void asm sideeffect "eieio", ""() | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1780 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1781 | </div> | 
| Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1782 |  | 
 | 1783 | <p>TODO: The format of the asm and constraints string still need to be | 
 | 1784 | documented here.  Constraints on what can be done (e.g. duplication, moving, etc | 
 | 1785 | need to be documented). | 
 | 1786 | </p> | 
 | 1787 |  | 
 | 1788 | </div> | 
 | 1789 |  | 
 | 1790 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1791 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> | 
 | 1792 | <!-- *********************************************************************** --> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1793 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1794 | <div class="doc_text"> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1795 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1796 | <p>The LLVM instruction set consists of several different | 
 | 1797 | classifications of instructions: <a href="#terminators">terminator | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1798 | instructions</a>, <a href="#binaryops">binary instructions</a>, | 
 | 1799 | <a href="#bitwiseops">bitwise binary instructions</a>, <a | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1800 |  href="#memoryops">memory instructions</a>, and <a href="#otherops">other | 
 | 1801 | instructions</a>.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1802 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1803 | </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1804 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1805 | <!-- ======================================================================= --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1806 | <div class="doc_subsection"> <a name="terminators">Terminator | 
 | 1807 | Instructions</a> </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1808 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1809 | <div class="doc_text"> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1810 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1811 | <p>As mentioned <a href="#functionstructure">previously</a>, every | 
 | 1812 | basic block in a program ends with a "Terminator" instruction, which | 
 | 1813 | indicates which block should be executed after the current block is | 
 | 1814 | finished. These terminator instructions typically yield a '<tt>void</tt>' | 
 | 1815 | value: they produce control flow, not values (the one exception being | 
 | 1816 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1817 | <p>There are six different terminator instructions: the '<a | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1818 |  href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' | 
 | 1819 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1820 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a | 
 | 1821 |  href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a | 
 | 1822 |  href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1823 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1824 | </div> | 
| Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1825 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1826 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1827 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' | 
 | 1828 | Instruction</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1829 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1830 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1831 | <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] | 1832 |   ret void                 <i>; Return from void function</i> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1833 |   ret <type> <value>, <type> <value>  <i>; Return two values from a non-void function </i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1834 | </pre> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1835 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1836 | <h5>Overview:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1837 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1838 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and a | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1839 | value) from a function back to the caller.</p> | 
| John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 1840 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1841 | returns value(s) and then causes control flow, and one that just causes | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1842 | control flow to occur.</p> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1843 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1844 | <h5>Arguments:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1845 |  | 
 | 1846 | <p>The '<tt>ret</tt>' instruction may return zero, one or multiple values.  | 
 | 1847 | The type of each return value must be a '<a href="#t_firstclass">first  | 
 | 1848 | class</a>' type.  Note that a function is not <a href="#wellformed">well  | 
 | 1849 | formed</a> if there exists a '<tt>ret</tt>' instruction inside of the  | 
 | 1850 | function that returns values that do not match the return type of the  | 
 | 1851 | function.</p> | 
 | 1852 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1853 | <h5>Semantics:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1854 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1855 | <p>When the '<tt>ret</tt>' instruction is executed, control flow | 
 | 1856 | returns back to the calling function's context.  If the caller is a "<a | 
| John Criswell | fa08187 | 2004-06-25 15:16:57 +0000 | [diff] [blame] | 1857 |  href="#i_call"><tt>call</tt></a>" instruction, execution continues at | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1858 | the instruction after the call.  If the caller was an "<a | 
 | 1859 |  href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1860 | at the beginning of the "normal" destination block.  If the instruction | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1861 | returns a value, that value shall set the call or invoke instruction's | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1862 | return value. If the instruction returns multiple values then these  | 
| Devang Patel | 0dbb4a1 | 2008-03-11 05:51:59 +0000 | [diff] [blame] | 1863 | values can only be accessed through a '<a href="#i_getresult"><tt>getresult</tt> | 
 | 1864 | </a>' instruction.</p> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1865 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1866 | <h5>Example:</h5> | 
| Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1867 |  | 
 | 1868 | <pre> | 
 | 1869 |   ret i32 5                       <i>; Return an integer value of 5</i> | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1870 |   ret void                        <i>; Return from a void function</i> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1871 |   ret i32 4, i8 2                 <i>; Return two values 4 and 2 </i>  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1872 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1873 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1874 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1875 | <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] | 1876 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1877 | <h5>Syntax:</h5> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1878 | <pre>  br i1 <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] | 1879 | </pre> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1880 | <h5>Overview:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1881 | <p>The '<tt>br</tt>' instruction is used to cause control flow to | 
 | 1882 | transfer to a different basic block in the current function.  There are | 
 | 1883 | two forms of this instruction, corresponding to a conditional branch | 
 | 1884 | and an unconditional branch.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1885 | <h5>Arguments:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1886 | <p>The conditional branch form of the '<tt>br</tt>' instruction takes a | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1887 | single '<tt>i1</tt>' value and two '<tt>label</tt>' values.  The | 
| Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1888 | unconditional form of the '<tt>br</tt>' instruction takes a single  | 
 | 1889 | '<tt>label</tt>' value as a target.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1890 | <h5>Semantics:</h5> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1891 | <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>i1</tt>' | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1892 | argument is evaluated.  If the value is <tt>true</tt>, control flows | 
 | 1893 | to the '<tt>iftrue</tt>' <tt>label</tt> argument.  If "cond" is <tt>false</tt>, | 
 | 1894 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1895 | <h5>Example:</h5> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1896 | <pre>Test:<br>  %cond = <a href="#i_icmp">icmp</a> eq, i32 %a, %b<br>  br i1 %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br>  <a | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1897 |  href="#i_ret">ret</a> i32 1<br>IfUnequal:<br>  <a href="#i_ret">ret</a> i32 0<br></pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1898 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1899 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1900 | <div class="doc_subsubsection"> | 
 | 1901 |    <a name="i_switch">'<tt>switch</tt>' Instruction</a> | 
 | 1902 | </div> | 
 | 1903 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1904 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1905 | <h5>Syntax:</h5> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1906 |  | 
 | 1907 | <pre> | 
 | 1908 |   switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] | 
 | 1909 | </pre> | 
 | 1910 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1911 | <h5>Overview:</h5> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1912 |  | 
 | 1913 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of | 
 | 1914 | several different places.  It is a generalization of the '<tt>br</tt>' | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1915 | instruction, allowing a branch to occur to one of many possible | 
 | 1916 | destinations.</p> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1917 |  | 
 | 1918 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1919 | <h5>Arguments:</h5> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1920 |  | 
 | 1921 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer | 
 | 1922 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and | 
 | 1923 | an array of pairs of comparison value constants and '<tt>label</tt>'s.  The | 
 | 1924 | table is not allowed to contain duplicate constant entries.</p> | 
 | 1925 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1926 | <h5>Semantics:</h5> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1927 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1928 | <p>The <tt>switch</tt> instruction specifies a table of values and | 
 | 1929 | destinations. When the '<tt>switch</tt>' instruction is executed, this | 
| John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1930 | table is searched for the given value.  If the value is found, control flow is | 
 | 1931 | transfered to the corresponding destination; otherwise, control flow is | 
 | 1932 | transfered to the default destination.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1933 |  | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1934 | <h5>Implementation:</h5> | 
 | 1935 |  | 
 | 1936 | <p>Depending on properties of the target machine and the particular | 
 | 1937 | <tt>switch</tt> instruction, this instruction may be code generated in different | 
| John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1938 | ways.  For example, it could be generated as a series of chained conditional | 
 | 1939 | branches or with a lookup table.</p> | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1940 |  | 
 | 1941 | <h5>Example:</h5> | 
 | 1942 |  | 
 | 1943 | <pre> | 
 | 1944 |  <i>; Emulate a conditional br instruction</i> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1945 |  %Val = <a href="#i_zext">zext</a> i1 %value to i32 | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1946 |  switch i32 %Val, label %truedest [i32 0, label %falsedest ] | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1947 |  | 
 | 1948 |  <i>; Emulate an unconditional br instruction</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1949 |  switch i32 0, label %dest [ ] | 
| Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1950 |  | 
 | 1951 |  <i>; Implement a jump table:</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1952 |  switch i32 %val, label %otherwise [ i32 0, label %onzero  | 
 | 1953 |                                       i32 1, label %onone  | 
 | 1954 |                                       i32 2, label %ontwo ] | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1955 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1956 | </div> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1957 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1958 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1959 | <div class="doc_subsubsection"> | 
 | 1960 |   <a name="i_invoke">'<tt>invoke</tt>' Instruction</a> | 
 | 1961 | </div> | 
 | 1962 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1963 | <div class="doc_text"> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1964 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1965 | <h5>Syntax:</h5> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1966 |  | 
 | 1967 | <pre> | 
| Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 1968 |   <result> = invoke [<a href="#callingconv">cconv</a>] <ptr to function ty> <function ptr val>(<function args>)  | 
| Chris Lattner | 76b8a33 | 2006-05-14 18:23:06 +0000 | [diff] [blame] | 1969 |                 to label <normal label> unwind label <exception label> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1970 | </pre> | 
 | 1971 |  | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1972 | <h5>Overview:</h5> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1973 |  | 
 | 1974 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified | 
 | 1975 | function, with the possibility of control flow transfer to either the | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1976 | '<tt>normal</tt>' label or the | 
 | 1977 | '<tt>exception</tt>' label.  If the callee function returns with the | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1978 | "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the | 
 | 1979 | "normal" label.  If the callee (or any indirect callees) returns with the "<a | 
| John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1980 | href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1981 | continued at the dynamically nearest "exception" label. If the callee function  | 
| Devang Patel | 0dbb4a1 | 2008-03-11 05:51:59 +0000 | [diff] [blame] | 1982 | returns multiple values then individual return values are only accessible through  | 
 | 1983 | a '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1984 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1985 | <h5>Arguments:</h5> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1986 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1987 | <p>This instruction requires several arguments:</p> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1988 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1989 | <ol> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1990 |   <li> | 
| Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 1991 |     The optional "cconv" marker indicates which <a href="#callingconv">calling | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1992 |     convention</a> the call should use.  If none is specified, the call defaults | 
 | 1993 |     to using C calling conventions. | 
 | 1994 |   </li> | 
 | 1995 |   <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to | 
 | 1996 |   function value being invoked.  In most cases, this is a direct function | 
 | 1997 |   invocation, but indirect <tt>invoke</tt>s are just as possible, branching off | 
 | 1998 |   an arbitrary pointer to function value. | 
 | 1999 |   </li> | 
 | 2000 |  | 
 | 2001 |   <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a | 
 | 2002 |   function to be invoked. </li> | 
 | 2003 |  | 
 | 2004 |   <li>'<tt>function args</tt>': argument list whose types match the function | 
 | 2005 |   signature argument types.  If the function signature indicates the function | 
 | 2006 |   accepts a variable number of arguments, the extra arguments can be | 
 | 2007 |   specified. </li> | 
 | 2008 |  | 
 | 2009 |   <li>'<tt>normal label</tt>': the label reached when the called function | 
 | 2010 |   executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> | 
 | 2011 |  | 
 | 2012 |   <li>'<tt>exception label</tt>': the label reached when a callee returns with | 
 | 2013 |   the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> | 
 | 2014 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2015 | </ol> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2016 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2017 | <h5>Semantics:</h5> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2018 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2019 | <p>This instruction is designed to operate as a standard '<tt><a | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2020 | href="#i_call">call</a></tt>' instruction in most regards.  The primary | 
 | 2021 | difference is that it establishes an association with a label, which is used by | 
 | 2022 | the runtime library to unwind the stack.</p> | 
 | 2023 |  | 
 | 2024 | <p>This instruction is used in languages with destructors to ensure that proper | 
 | 2025 | cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown | 
 | 2026 | exception.  Additionally, this is important for implementation of | 
 | 2027 | '<tt>catch</tt>' clauses in high-level languages that support them.</p> | 
 | 2028 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2029 | <h5>Example:</h5> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2030 | <pre> | 
| Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2031 |   %retval = invoke i32 @Test(i32 15) to label %Continue | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2032 |               unwind label %TestCleanup              <i>; {i32}:retval set</i> | 
| Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2033 |   %retval = invoke <a href="#callingconv">coldcc</a> i32 %Testfnptr(i32 15) to label %Continue | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2034 |               unwind label %TestCleanup              <i>; {i32}:retval set</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2035 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2036 | </div> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2037 |  | 
 | 2038 |  | 
| Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2039 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2040 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2041 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' | 
 | 2042 | Instruction</a> </div> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2043 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2044 | <div class="doc_text"> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2045 |  | 
| Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2046 | <h5>Syntax:</h5> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2047 | <pre> | 
 | 2048 |   unwind | 
 | 2049 | </pre> | 
 | 2050 |  | 
| Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2051 | <h5>Overview:</h5> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2052 |  | 
 | 2053 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow | 
 | 2054 | at the first callee in the dynamic call stack which used an <a | 
 | 2055 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call.  This is | 
 | 2056 | primarily used to implement exception handling.</p> | 
 | 2057 |  | 
| Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2058 | <h5>Semantics:</h5> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2059 |  | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2060 | <p>The '<tt>unwind</tt>' instruction causes execution of the current function to | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2061 | immediately halt.  The dynamic call stack is then searched for the first <a | 
 | 2062 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack.  Once found, | 
 | 2063 | execution continues at the "exceptional" destination block specified by the | 
 | 2064 | <tt>invoke</tt> instruction.  If there is no <tt>invoke</tt> instruction in the | 
 | 2065 | dynamic call chain, undefined behavior results.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2066 | </div> | 
| Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2067 |  | 
 | 2068 | <!-- _______________________________________________________________________ --> | 
 | 2069 |  | 
 | 2070 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' | 
 | 2071 | Instruction</a> </div> | 
 | 2072 |  | 
 | 2073 | <div class="doc_text"> | 
 | 2074 |  | 
 | 2075 | <h5>Syntax:</h5> | 
 | 2076 | <pre> | 
 | 2077 |   unreachable | 
 | 2078 | </pre> | 
 | 2079 |  | 
 | 2080 | <h5>Overview:</h5> | 
 | 2081 |  | 
 | 2082 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.  This | 
 | 2083 | instruction is used to inform the optimizer that a particular portion of the | 
 | 2084 | code is not reachable.  This can be used to indicate that the code after a | 
 | 2085 | no-return function cannot be reached, and other facts.</p> | 
 | 2086 |  | 
 | 2087 | <h5>Semantics:</h5> | 
 | 2088 |  | 
 | 2089 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> | 
 | 2090 | </div> | 
 | 2091 |  | 
 | 2092 |  | 
 | 2093 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2094 | <!-- ======================================================================= --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2095 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2096 | <div class="doc_text"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2097 | <p>Binary operators are used to do most of the computation in a | 
| Chris Lattner | 5a15814 | 2008-04-01 18:47:32 +0000 | [diff] [blame] | 2098 | program.  They require two operands of the same type, execute an operation on them, and | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2099 | produce a single value.  The operands might represent  | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2100 | multiple data, as is the case with the <a href="#t_vector">vector</a> data type.  | 
| Chris Lattner | 5a15814 | 2008-04-01 18:47:32 +0000 | [diff] [blame] | 2101 | The result value has the same type as its operands.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2102 | <p>There are several different binary operators:</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2103 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2104 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2105 | <div class="doc_subsubsection"> | 
 | 2106 |   <a name="i_add">'<tt>add</tt>' Instruction</a> | 
 | 2107 | </div> | 
 | 2108 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2109 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2110 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2111 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2112 |  | 
 | 2113 | <pre> | 
 | 2114 |   <result> = add <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2115 | </pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2116 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2117 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2118 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2119 | <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2120 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2121 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2122 |  | 
 | 2123 | <p>The two arguments to the '<tt>add</tt>' instruction must be <a | 
 | 2124 |  href="#t_integer">integer</a>, <a href="#t_floating">floating point</a>, or | 
 | 2125 |  <a href="#t_vector">vector</a> values. Both arguments must have identical | 
 | 2126 |  types.</p> | 
 | 2127 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2128 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2129 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2130 | <p>The value produced is the integer or floating point sum of the two | 
 | 2131 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2132 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2133 | <p>If an integer sum has unsigned overflow, the result returned is the | 
 | 2134 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of | 
 | 2135 | the result.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2136 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2137 | <p>Because LLVM integers use a two's complement representation, this | 
 | 2138 | instruction is appropriate for both signed and unsigned integers.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2139 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2140 | <h5>Example:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2141 |  | 
 | 2142 | <pre> | 
 | 2143 |   <result> = add i32 4, %var          <i>; yields {i32}:result = 4 + %var</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2144 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2145 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2146 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2147 | <div class="doc_subsubsection"> | 
 | 2148 |    <a name="i_sub">'<tt>sub</tt>' Instruction</a> | 
 | 2149 | </div> | 
 | 2150 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2151 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2152 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2153 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2154 |  | 
 | 2155 | <pre> | 
 | 2156 |   <result> = sub <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2157 | </pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2158 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2159 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2160 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2161 | <p>The '<tt>sub</tt>' instruction returns the difference of its two | 
 | 2162 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2163 |  | 
 | 2164 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the | 
 | 2165 | '<tt>neg</tt>' instruction present in most other intermediate  | 
 | 2166 | representations.</p> | 
 | 2167 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2168 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2169 |  | 
 | 2170 | <p>The two arguments to the '<tt>sub</tt>' instruction must be <a | 
 | 2171 |  href="#t_integer">integer</a>, <a href="#t_floating">floating point</a>, | 
 | 2172 |  or <a href="#t_vector">vector</a> values.  Both arguments must have identical | 
 | 2173 |  types.</p> | 
 | 2174 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2175 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2176 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2177 | <p>The value produced is the integer or floating point difference of | 
 | 2178 | the two operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2179 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2180 | <p>If an integer difference has unsigned overflow, the result returned is the | 
 | 2181 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of | 
 | 2182 | the result.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2183 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2184 | <p>Because LLVM integers use a two's complement representation, this | 
 | 2185 | instruction is appropriate for both signed and unsigned integers.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2186 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2187 | <h5>Example:</h5> | 
| Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 2188 | <pre> | 
 | 2189 |   <result> = sub i32 4, %var          <i>; yields {i32}:result = 4 - %var</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2190 |   <result> = sub i32 0, %val          <i>; yields {i32}:result = -%var</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2191 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2192 | </div> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2193 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2194 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2195 | <div class="doc_subsubsection"> | 
 | 2196 |   <a name="i_mul">'<tt>mul</tt>' Instruction</a> | 
 | 2197 | </div> | 
 | 2198 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2199 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2200 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2201 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2202 | <pre>  <result> = mul <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2203 | </pre> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2204 | <h5>Overview:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2205 | <p>The  '<tt>mul</tt>' instruction returns the product of its two | 
 | 2206 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2207 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2208 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2209 |  | 
 | 2210 | <p>The two arguments to the '<tt>mul</tt>' instruction must be <a | 
 | 2211 | href="#t_integer">integer</a>, <a href="#t_floating">floating point</a>, | 
 | 2212 | or <a href="#t_vector">vector</a> values.  Both arguments must have identical | 
 | 2213 | types.</p> | 
 | 2214 |   | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2215 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2216 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2217 | <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] | 2218 | two operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2219 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2220 | <p>If the result of an integer multiplication has unsigned overflow, | 
 | 2221 | the result returned is the mathematical result modulo  | 
 | 2222 | 2<sup>n</sup>, where n is the bit width of the result.</p> | 
 | 2223 | <p>Because LLVM integers use a two's complement representation, and the | 
 | 2224 | result is the same width as the operands, this instruction returns the | 
 | 2225 | correct result for both signed and unsigned integers.  If a full product | 
 | 2226 | (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands | 
 | 2227 | should be sign-extended or zero-extended as appropriate to the | 
 | 2228 | width of the full product.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2229 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2230 | <pre>  <result> = mul i32 4, %var          <i>; yields {i32}:result = 4 * %var</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2231 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2232 | </div> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2233 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2234 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2235 | <div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction | 
 | 2236 | </a></div> | 
 | 2237 | <div class="doc_text"> | 
 | 2238 | <h5>Syntax:</h5> | 
 | 2239 | <pre>  <result> = udiv <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2240 | </pre> | 
 | 2241 | <h5>Overview:</h5> | 
 | 2242 | <p>The '<tt>udiv</tt>' instruction returns the quotient of its two | 
 | 2243 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2244 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2245 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2246 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2247 | <p>The two arguments to the '<tt>udiv</tt>' instruction must be  | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2248 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2249 | values.  Both arguments must have identical types.</p> | 
 | 2250 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2251 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2252 |  | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2253 | <p>The value produced is the unsigned integer quotient of the two operands.</p> | 
 | 2254 | <p>Note that unsigned integer division and signed integer division are distinct | 
 | 2255 | operations; for signed integer division, use '<tt>sdiv</tt>'.</p> | 
 | 2256 | <p>Division by zero leads to undefined behavior.</p> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2257 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2258 | <pre>  <result> = udiv i32 4, %var          <i>; yields {i32}:result = 4 / %var</i> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2259 | </pre> | 
 | 2260 | </div> | 
 | 2261 | <!-- _______________________________________________________________________ --> | 
 | 2262 | <div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction | 
 | 2263 | </a> </div> | 
 | 2264 | <div class="doc_text"> | 
 | 2265 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2266 | <pre> | 
 | 2267 |   <result> = sdiv <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2268 | </pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2269 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2270 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2271 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2272 | <p>The '<tt>sdiv</tt>' instruction returns the quotient of its two | 
 | 2273 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2274 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2275 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2276 |  | 
 | 2277 | <p>The two arguments to the '<tt>sdiv</tt>' instruction must be  | 
 | 2278 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2279 | values.  Both arguments must have identical types.</p> | 
 | 2280 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2281 | <h5>Semantics:</h5> | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2282 | <p>The value produced is the signed integer quotient of the two operands rounded towards zero.</p> | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2283 | <p>Note that signed integer division and unsigned integer division are distinct | 
 | 2284 | operations; for unsigned integer division, use '<tt>udiv</tt>'.</p> | 
 | 2285 | <p>Division by zero leads to undefined behavior. Overflow also leads to | 
 | 2286 | undefined behavior; this is a rare case, but can occur, for example, | 
 | 2287 | by doing a 32-bit division of -2147483648 by -1.</p> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2288 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2289 | <pre>  <result> = sdiv i32 4, %var          <i>; yields {i32}:result = 4 / %var</i> | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2290 | </pre> | 
 | 2291 | </div> | 
 | 2292 | <!-- _______________________________________________________________________ --> | 
 | 2293 | <div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>' | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2294 | Instruction</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2295 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2296 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2297 | <pre> | 
 | 2298 |   <result> = fdiv <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2299 | </pre> | 
 | 2300 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2301 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2302 | <p>The '<tt>fdiv</tt>' instruction returns the quotient of its two | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2303 | operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2304 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2305 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2306 |  | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2307 | <p>The two arguments to the '<tt>fdiv</tt>' instruction must be | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2308 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> | 
 | 2309 | of floating point values.  Both arguments must have identical types.</p> | 
 | 2310 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2311 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2312 |  | 
| Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2313 | <p>The value produced is the floating point quotient of the two operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2314 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2315 | <h5>Example:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2316 |  | 
 | 2317 | <pre> | 
 | 2318 |   <result> = fdiv float 4.0, %var          <i>; yields {float}:result = 4.0 / %var</i> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2319 | </pre> | 
 | 2320 | </div> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2321 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2322 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2323 | <div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a> | 
 | 2324 | </div> | 
 | 2325 | <div class="doc_text"> | 
 | 2326 | <h5>Syntax:</h5> | 
 | 2327 | <pre>  <result> = urem <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2328 | </pre> | 
 | 2329 | <h5>Overview:</h5> | 
 | 2330 | <p>The '<tt>urem</tt>' instruction returns the remainder from the | 
 | 2331 | unsigned division of its two arguments.</p> | 
 | 2332 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2333 | <p>The two arguments to the '<tt>urem</tt>' instruction must be  | 
 | 2334 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2335 | values.  Both arguments must have identical types.</p> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2336 | <h5>Semantics:</h5> | 
 | 2337 | <p>This instruction returns the unsigned integer <i>remainder</i> of a division. | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2338 | This instruction always performs an unsigned division to get the remainder.</p> | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2339 | <p>Note that unsigned integer remainder and signed integer remainder are | 
 | 2340 | distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p> | 
 | 2341 | <p>Taking the remainder of a division by zero leads to undefined behavior.</p> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2342 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2343 | <pre>  <result> = urem i32 4, %var          <i>; yields {i32}:result = 4 % %var</i> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2344 | </pre> | 
 | 2345 |  | 
 | 2346 | </div> | 
 | 2347 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2348 | <div class="doc_subsubsection"> | 
 | 2349 |   <a name="i_srem">'<tt>srem</tt>' Instruction</a> | 
 | 2350 | </div> | 
 | 2351 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2352 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2353 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2354 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2355 |  | 
 | 2356 | <pre> | 
 | 2357 |   <result> = srem <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2358 | </pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2359 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2360 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2361 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2362 | <p>The '<tt>srem</tt>' instruction returns the remainder from the | 
| Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 2363 | signed division of its two operands. This instruction can also take | 
 | 2364 | <a href="#t_vector">vector</a> versions of the values in which case | 
 | 2365 | the elements must be integers.</p> | 
| Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 2366 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2367 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2368 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2369 | <p>The two arguments to the '<tt>srem</tt>' instruction must be  | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2370 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2371 | values.  Both arguments must have identical types.</p> | 
 | 2372 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2373 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2374 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2375 | <p>This instruction returns the <i>remainder</i> of a division (where the result | 
| Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2376 | has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i>  | 
 | 2377 | operator (where the result has the same sign as the divisor, <tt>var2</tt>) of  | 
 | 2378 | a value.  For more information about the difference, see <a | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2379 |  href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The | 
| Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2380 | Math Forum</a>. For a table of how this is implemented in various languages, | 
| Reid Spencer | 64f5c6c | 2007-03-24 22:40:44 +0000 | [diff] [blame] | 2381 | please see <a href="http://en.wikipedia.org/wiki/Modulo_operation"> | 
| Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2382 | Wikipedia: modulo operation</a>.</p> | 
| Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2383 | <p>Note that signed integer remainder and unsigned integer remainder are | 
 | 2384 | distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p> | 
 | 2385 | <p>Taking the remainder of a division by zero leads to undefined behavior. | 
 | 2386 | Overflow also leads to undefined behavior; this is a rare case, but can occur, | 
 | 2387 | for example, by taking the remainder of a 32-bit division of -2147483648 by -1. | 
 | 2388 | (The remainder doesn't actually overflow, but this rule lets srem be  | 
 | 2389 | implemented using instructions that return both the result of the division | 
 | 2390 | and the remainder.)</p> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2391 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2392 | <pre>  <result> = srem i32 4, %var          <i>; yields {i32}:result = 4 % %var</i> | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2393 | </pre> | 
 | 2394 |  | 
 | 2395 | </div> | 
 | 2396 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2397 | <div class="doc_subsubsection"> | 
 | 2398 |   <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div> | 
 | 2399 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2400 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2401 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2402 | <h5>Syntax:</h5> | 
 | 2403 | <pre>  <result> = frem <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2404 | </pre> | 
 | 2405 | <h5>Overview:</h5> | 
 | 2406 | <p>The '<tt>frem</tt>' instruction returns the remainder from the | 
 | 2407 | division of its two operands.</p> | 
 | 2408 | <h5>Arguments:</h5> | 
 | 2409 | <p>The two arguments to the '<tt>frem</tt>' instruction must be | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2410 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> | 
 | 2411 | of floating point values.  Both arguments must have identical types.</p> | 
 | 2412 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2413 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2414 |  | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2415 | <p>This instruction returns the <i>remainder</i> of a division. | 
 | 2416 | The remainder has the same sign as the dividend.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2417 |  | 
| Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2418 | <h5>Example:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2419 |  | 
 | 2420 | <pre> | 
 | 2421 |   <result> = frem float 4.0, %var          <i>; yields {float}:result = 4.0 % %var</i> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2422 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2423 | </div> | 
| Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 2424 |  | 
| Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2425 | <!-- ======================================================================= --> | 
 | 2426 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary | 
 | 2427 | Operations</a> </div> | 
 | 2428 | <div class="doc_text"> | 
 | 2429 | <p>Bitwise binary operators are used to do various forms of | 
 | 2430 | bit-twiddling in a program.  They are generally very efficient | 
 | 2431 | instructions and can commonly be strength reduced from other | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2432 | instructions.  They require two operands of the same type, execute an operation on them, | 
 | 2433 | and produce a single value.  The resulting value is the same type as its operands.</p> | 
| Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2434 | </div> | 
 | 2435 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2436 | <!-- _______________________________________________________________________ --> | 
 | 2437 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' | 
 | 2438 | Instruction</a> </div> | 
 | 2439 | <div class="doc_text"> | 
 | 2440 | <h5>Syntax:</h5> | 
 | 2441 | <pre>  <result> = shl <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2442 | </pre> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2443 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2444 | <h5>Overview:</h5> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2445 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2446 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to | 
 | 2447 | the left a specified number of bits.</p> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2448 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2449 | <h5>Arguments:</h5> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2450 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2451 | <p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2452 |  href="#t_integer">integer</a> type.  '<tt>var2</tt>' is treated as an | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2453 | unsigned value.  This instruction does not support | 
 | 2454 | <a href="#t_vector">vector</a> operands.</p> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2455 |   | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2456 | <h5>Semantics:</h5> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2457 |  | 
| Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2458 | <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup> mod 2<sup>n</sup>, | 
 | 2459 | where n is the width of the result.  If <tt>var2</tt> is (statically or dynamically) negative or | 
 | 2460 | equal to or larger than the number of bits in <tt>var1</tt>, the result is undefined.</p> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2461 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2462 | <h5>Example:</h5><pre> | 
 | 2463 |   <result> = shl i32 4, %var   <i>; yields {i32}: 4 << %var</i> | 
 | 2464 |   <result> = shl i32 4, 2      <i>; yields {i32}: 16</i> | 
 | 2465 |   <result> = shl i32 1, 10     <i>; yields {i32}: 1024</i> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2466 |   <result> = shl i32 1, 32     <i>; undefined</i> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2467 | </pre> | 
 | 2468 | </div> | 
 | 2469 | <!-- _______________________________________________________________________ --> | 
 | 2470 | <div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>' | 
 | 2471 | Instruction</a> </div> | 
 | 2472 | <div class="doc_text"> | 
 | 2473 | <h5>Syntax:</h5> | 
 | 2474 | <pre>  <result> = lshr <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2475 | </pre> | 
 | 2476 |  | 
 | 2477 | <h5>Overview:</h5> | 
 | 2478 | <p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first  | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2479 | operand shifted to the right a specified number of bits with zero fill.</p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2480 |  | 
 | 2481 | <h5>Arguments:</h5> | 
 | 2482 | <p>Both arguments to the '<tt>lshr</tt>' instruction must be the same  | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2483 | <a href="#t_integer">integer</a> type.  '<tt>var2</tt>' is treated as an | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2484 | unsigned value.  This instruction does not support | 
 | 2485 | <a href="#t_vector">vector</a> operands.</p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2486 |  | 
 | 2487 | <h5>Semantics:</h5> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2488 |  | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2489 | <p>This instruction always performs a logical shift right operation. The most | 
 | 2490 | significant bits of the result will be filled with zero bits after the  | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2491 | shift.  If <tt>var2</tt> is (statically or dynamically) equal to or larger than | 
 | 2492 | the number of bits in <tt>var1</tt>, the result is undefined.</p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2493 |  | 
 | 2494 | <h5>Example:</h5> | 
 | 2495 | <pre> | 
 | 2496 |   <result> = lshr i32 4, 1   <i>; yields {i32}:result = 2</i> | 
 | 2497 |   <result> = lshr i32 4, 2   <i>; yields {i32}:result = 1</i> | 
 | 2498 |   <result> = lshr i8  4, 3   <i>; yields {i8}:result = 0</i> | 
 | 2499 |   <result> = lshr i8 -2, 1   <i>; yields {i8}:result = 0x7FFFFFFF </i> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2500 |   <result> = lshr i32 1, 32  <i>; undefined</i> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2501 | </pre> | 
 | 2502 | </div> | 
 | 2503 |  | 
| Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2504 | <!-- _______________________________________________________________________ --> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2505 | <div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>' | 
 | 2506 | Instruction</a> </div> | 
 | 2507 | <div class="doc_text"> | 
 | 2508 |  | 
 | 2509 | <h5>Syntax:</h5> | 
 | 2510 | <pre>  <result> = ashr <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 2511 | </pre> | 
 | 2512 |  | 
 | 2513 | <h5>Overview:</h5> | 
 | 2514 | <p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first  | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2515 | operand shifted to the right a specified number of bits with sign extension.</p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2516 |  | 
 | 2517 | <h5>Arguments:</h5> | 
 | 2518 | <p>Both arguments to the '<tt>ashr</tt>' instruction must be the same  | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2519 | <a href="#t_integer">integer</a> type.  '<tt>var2</tt>' is treated as an | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2520 | unsigned value.  This instruction does not support | 
 | 2521 | <a href="#t_vector">vector</a> operands.</p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2522 |  | 
 | 2523 | <h5>Semantics:</h5> | 
 | 2524 | <p>This instruction always performs an arithmetic shift right operation,  | 
 | 2525 | The most significant bits of the result will be filled with the sign bit  | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2526 | of <tt>var1</tt>.  If <tt>var2</tt> is (statically or dynamically) equal to or | 
 | 2527 | larger than the number of bits in <tt>var1</tt>, the result is undefined. | 
 | 2528 | </p> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2529 |  | 
 | 2530 | <h5>Example:</h5> | 
 | 2531 | <pre> | 
 | 2532 |   <result> = ashr i32 4, 1   <i>; yields {i32}:result = 2</i> | 
 | 2533 |   <result> = ashr i32 4, 2   <i>; yields {i32}:result = 1</i> | 
 | 2534 |   <result> = ashr i8  4, 3   <i>; yields {i8}:result = 0</i> | 
 | 2535 |   <result> = ashr i8 -2, 1   <i>; yields {i8}:result = -1</i> | 
| Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2536 |   <result> = ashr i32 1, 32  <i>; undefined</i> | 
| Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2537 | </pre> | 
 | 2538 | </div> | 
 | 2539 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2540 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2541 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' | 
 | 2542 | Instruction</a> </div> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2543 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2544 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2545 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2546 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2547 |  | 
 | 2548 | <pre> | 
 | 2549 |   <result> = and <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2550 | </pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2551 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2552 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2553 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2554 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of | 
 | 2555 | its two operands.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2556 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2557 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2558 |  | 
 | 2559 | <p>The two arguments to the '<tt>and</tt>' instruction must be  | 
 | 2560 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2561 | values.  Both arguments must have identical types.</p> | 
 | 2562 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2563 | <h5>Semantics:</h5> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2564 | <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] | 2565 | <p> </p> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2566 | <div style="align: center"> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2567 | <table border="1" cellspacing="0" cellpadding="4"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2568 |   <tbody> | 
 | 2569 |     <tr> | 
 | 2570 |       <td>In0</td> | 
 | 2571 |       <td>In1</td> | 
 | 2572 |       <td>Out</td> | 
 | 2573 |     </tr> | 
 | 2574 |     <tr> | 
 | 2575 |       <td>0</td> | 
 | 2576 |       <td>0</td> | 
 | 2577 |       <td>0</td> | 
 | 2578 |     </tr> | 
 | 2579 |     <tr> | 
 | 2580 |       <td>0</td> | 
 | 2581 |       <td>1</td> | 
 | 2582 |       <td>0</td> | 
 | 2583 |     </tr> | 
 | 2584 |     <tr> | 
 | 2585 |       <td>1</td> | 
 | 2586 |       <td>0</td> | 
 | 2587 |       <td>0</td> | 
 | 2588 |     </tr> | 
 | 2589 |     <tr> | 
 | 2590 |       <td>1</td> | 
 | 2591 |       <td>1</td> | 
 | 2592 |       <td>1</td> | 
 | 2593 |     </tr> | 
 | 2594 |   </tbody> | 
 | 2595 | </table> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2596 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2597 | <h5>Example:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2598 | <pre> | 
 | 2599 |   <result> = and i32 4, %var         <i>; yields {i32}:result = 4 & %var</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2600 |   <result> = and i32 15, 40          <i>; yields {i32}:result = 8</i> | 
 | 2601 |   <result> = and i32 4, 8            <i>; yields {i32}:result = 0</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2602 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2603 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2604 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2605 | <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] | 2606 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2607 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2608 | <pre>  <result> = or <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2609 | </pre> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2610 | <h5>Overview:</h5> | 
 | 2611 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive | 
 | 2612 | or of its two operands.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2613 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2614 |  | 
 | 2615 | <p>The two arguments to the '<tt>or</tt>' instruction must be  | 
 | 2616 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2617 | values.  Both arguments must have identical types.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2618 | <h5>Semantics:</h5> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2619 | <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] | 2620 | <p> </p> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2621 | <div style="align: center"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2622 | <table border="1" cellspacing="0" cellpadding="4"> | 
 | 2623 |   <tbody> | 
 | 2624 |     <tr> | 
 | 2625 |       <td>In0</td> | 
 | 2626 |       <td>In1</td> | 
 | 2627 |       <td>Out</td> | 
 | 2628 |     </tr> | 
 | 2629 |     <tr> | 
 | 2630 |       <td>0</td> | 
 | 2631 |       <td>0</td> | 
 | 2632 |       <td>0</td> | 
 | 2633 |     </tr> | 
 | 2634 |     <tr> | 
 | 2635 |       <td>0</td> | 
 | 2636 |       <td>1</td> | 
 | 2637 |       <td>1</td> | 
 | 2638 |     </tr> | 
 | 2639 |     <tr> | 
 | 2640 |       <td>1</td> | 
 | 2641 |       <td>0</td> | 
 | 2642 |       <td>1</td> | 
 | 2643 |     </tr> | 
 | 2644 |     <tr> | 
 | 2645 |       <td>1</td> | 
 | 2646 |       <td>1</td> | 
 | 2647 |       <td>1</td> | 
 | 2648 |     </tr> | 
 | 2649 |   </tbody> | 
 | 2650 | </table> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2651 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2652 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2653 | <pre>  <result> = or i32 4, %var         <i>; yields {i32}:result = 4 | %var</i> | 
 | 2654 |   <result> = or i32 15, 40          <i>; yields {i32}:result = 47</i> | 
 | 2655 |   <result> = or i32 4, 8            <i>; yields {i32}:result = 12</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2656 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2657 | </div> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2658 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2659 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' | 
 | 2660 | Instruction</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2661 | <div class="doc_text"> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2662 | <h5>Syntax:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2663 | <pre>  <result> = xor <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2664 | </pre> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2665 | <h5>Overview:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2666 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive | 
 | 2667 | or of its two operands.  The <tt>xor</tt> is used to implement the | 
 | 2668 | "one's complement" operation, which is the "~" operator in C.</p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2669 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2670 | <p>The two arguments to the '<tt>xor</tt>' instruction must be  | 
 | 2671 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer | 
 | 2672 | values.  Both arguments must have identical types.</p> | 
 | 2673 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2674 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2675 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2676 | <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] | 2677 | <p> </p> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2678 | <div style="align: center"> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2679 | <table border="1" cellspacing="0" cellpadding="4"> | 
 | 2680 |   <tbody> | 
 | 2681 |     <tr> | 
 | 2682 |       <td>In0</td> | 
 | 2683 |       <td>In1</td> | 
 | 2684 |       <td>Out</td> | 
 | 2685 |     </tr> | 
 | 2686 |     <tr> | 
 | 2687 |       <td>0</td> | 
 | 2688 |       <td>0</td> | 
 | 2689 |       <td>0</td> | 
 | 2690 |     </tr> | 
 | 2691 |     <tr> | 
 | 2692 |       <td>0</td> | 
 | 2693 |       <td>1</td> | 
 | 2694 |       <td>1</td> | 
 | 2695 |     </tr> | 
 | 2696 |     <tr> | 
 | 2697 |       <td>1</td> | 
 | 2698 |       <td>0</td> | 
 | 2699 |       <td>1</td> | 
 | 2700 |     </tr> | 
 | 2701 |     <tr> | 
 | 2702 |       <td>1</td> | 
 | 2703 |       <td>1</td> | 
 | 2704 |       <td>0</td> | 
 | 2705 |     </tr> | 
 | 2706 |   </tbody> | 
 | 2707 | </table> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2708 | </div> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2709 | <p> </p> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2710 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2711 | <pre>  <result> = xor i32 4, %var         <i>; yields {i32}:result = 4 ^ %var</i> | 
 | 2712 |   <result> = xor i32 15, 40          <i>; yields {i32}:result = 39</i> | 
 | 2713 |   <result> = xor i32 4, 8            <i>; yields {i32}:result = 12</i> | 
 | 2714 |   <result> = xor i32 %V, -1          <i>; yields {i32}:result = ~%V</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2715 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2716 | </div> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2717 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2718 | <!-- ======================================================================= --> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2719 | <div class="doc_subsection">  | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2720 |   <a name="vectorops">Vector Operations</a> | 
 | 2721 | </div> | 
 | 2722 |  | 
 | 2723 | <div class="doc_text"> | 
 | 2724 |  | 
 | 2725 | <p>LLVM supports several instructions to represent vector operations in a | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2726 | target-independent manner.  These instructions cover the element-access and | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2727 | vector-specific operations needed to process vectors effectively.  While LLVM | 
 | 2728 | does directly support these vector operations, many sophisticated algorithms | 
 | 2729 | will want to use target-specific intrinsics to take full advantage of a specific | 
 | 2730 | target.</p> | 
 | 2731 |  | 
 | 2732 | </div> | 
 | 2733 |  | 
 | 2734 | <!-- _______________________________________________________________________ --> | 
 | 2735 | <div class="doc_subsubsection"> | 
 | 2736 |    <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a> | 
 | 2737 | </div> | 
 | 2738 |  | 
 | 2739 | <div class="doc_text"> | 
 | 2740 |  | 
 | 2741 | <h5>Syntax:</h5> | 
 | 2742 |  | 
 | 2743 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2744 |   <result> = extractelement <n x <ty>> <val>, i32 <idx>    <i>; yields <ty></i> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2745 | </pre> | 
 | 2746 |  | 
 | 2747 | <h5>Overview:</h5> | 
 | 2748 |  | 
 | 2749 | <p> | 
 | 2750 | The '<tt>extractelement</tt>' instruction extracts a single scalar | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2751 | element from a vector at a specified index. | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2752 | </p> | 
 | 2753 |  | 
 | 2754 |  | 
 | 2755 | <h5>Arguments:</h5> | 
 | 2756 |  | 
 | 2757 | <p> | 
 | 2758 | The first operand of an '<tt>extractelement</tt>' instruction is a | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2759 | value of <a href="#t_vector">vector</a> type.  The second operand is | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2760 | an index indicating the position from which to extract the element. | 
 | 2761 | The index may be a variable.</p> | 
 | 2762 |  | 
 | 2763 | <h5>Semantics:</h5> | 
 | 2764 |  | 
 | 2765 | <p> | 
 | 2766 | The result is a scalar of the same type as the element type of | 
 | 2767 | <tt>val</tt>.  Its value is the value at position <tt>idx</tt> of | 
 | 2768 | <tt>val</tt>.  If <tt>idx</tt> exceeds the length of <tt>val</tt>, the | 
 | 2769 | results are undefined. | 
 | 2770 | </p> | 
 | 2771 |  | 
 | 2772 | <h5>Example:</h5> | 
 | 2773 |  | 
 | 2774 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2775 |   %result = extractelement <4 x i32> %vec, i32 0    <i>; yields i32</i> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2776 | </pre> | 
 | 2777 | </div> | 
 | 2778 |  | 
 | 2779 |  | 
 | 2780 | <!-- _______________________________________________________________________ --> | 
 | 2781 | <div class="doc_subsubsection"> | 
 | 2782 |    <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a> | 
 | 2783 | </div> | 
 | 2784 |  | 
 | 2785 | <div class="doc_text"> | 
 | 2786 |  | 
 | 2787 | <h5>Syntax:</h5> | 
 | 2788 |  | 
 | 2789 | <pre> | 
| Dan Gohman | f3480b9 | 2008-05-12 23:38:42 +0000 | [diff] [blame] | 2790 |   <result> = insertelement <n x <ty>> <val>, <ty> <elt>, i32 <idx>    <i>; yields <n x <ty>></i> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2791 | </pre> | 
 | 2792 |  | 
 | 2793 | <h5>Overview:</h5> | 
 | 2794 |  | 
 | 2795 | <p> | 
 | 2796 | The '<tt>insertelement</tt>' instruction inserts a scalar | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2797 | element into a vector at a specified index. | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2798 | </p> | 
 | 2799 |  | 
 | 2800 |  | 
 | 2801 | <h5>Arguments:</h5> | 
 | 2802 |  | 
 | 2803 | <p> | 
 | 2804 | The first operand of an '<tt>insertelement</tt>' instruction is a | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2805 | value of <a href="#t_vector">vector</a> type.  The second operand is a | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2806 | scalar value whose type must equal the element type of the first | 
 | 2807 | operand.  The third operand is an index indicating the position at | 
 | 2808 | which to insert the value.  The index may be a variable.</p> | 
 | 2809 |  | 
 | 2810 | <h5>Semantics:</h5> | 
 | 2811 |  | 
 | 2812 | <p> | 
| Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2813 | The result is a vector of the same type as <tt>val</tt>.  Its | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2814 | element values are those of <tt>val</tt> except at position | 
 | 2815 | <tt>idx</tt>, where it gets the value <tt>elt</tt>.  If <tt>idx</tt> | 
 | 2816 | exceeds the length of <tt>val</tt>, the results are undefined. | 
 | 2817 | </p> | 
 | 2818 |  | 
 | 2819 | <h5>Example:</h5> | 
 | 2820 |  | 
 | 2821 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2822 |   %result = insertelement <4 x i32> %vec, i32 1, i32 0    <i>; yields <4 x i32></i> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2823 | </pre> | 
 | 2824 | </div> | 
 | 2825 |  | 
 | 2826 | <!-- _______________________________________________________________________ --> | 
 | 2827 | <div class="doc_subsubsection"> | 
 | 2828 |    <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a> | 
 | 2829 | </div> | 
 | 2830 |  | 
 | 2831 | <div class="doc_text"> | 
 | 2832 |  | 
 | 2833 | <h5>Syntax:</h5> | 
 | 2834 |  | 
 | 2835 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2836 |   <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x i32> <mask>    <i>; yields <n x <ty>></i> | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2837 | </pre> | 
 | 2838 |  | 
 | 2839 | <h5>Overview:</h5> | 
 | 2840 |  | 
 | 2841 | <p> | 
 | 2842 | The '<tt>shufflevector</tt>' instruction constructs a permutation of elements | 
 | 2843 | from two input vectors, returning a vector of the same type. | 
 | 2844 | </p> | 
 | 2845 |  | 
 | 2846 | <h5>Arguments:</h5> | 
 | 2847 |  | 
 | 2848 | <p> | 
 | 2849 | The first two operands of a '<tt>shufflevector</tt>' instruction are vectors | 
 | 2850 | with types that match each other and types that match the result of the | 
 | 2851 | instruction.  The third argument is a shuffle mask, which has the same number | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2852 | of elements as the other vector type, but whose element type is always 'i32'. | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2853 | </p> | 
 | 2854 |  | 
 | 2855 | <p> | 
 | 2856 | The shuffle mask operand is required to be a constant vector with either | 
 | 2857 | constant integer or undef values. | 
 | 2858 | </p> | 
 | 2859 |  | 
 | 2860 | <h5>Semantics:</h5> | 
 | 2861 |  | 
 | 2862 | <p> | 
 | 2863 | The elements of the two input vectors are numbered from left to right across | 
 | 2864 | both of the vectors.  The shuffle mask operand specifies, for each element of | 
 | 2865 | the result vector, which element of the two input registers the result element | 
 | 2866 | gets.  The element selector may be undef (meaning "don't care") and the second | 
 | 2867 | operand may be undef if performing a shuffle from only one vector. | 
 | 2868 | </p> | 
 | 2869 |  | 
 | 2870 | <h5>Example:</h5> | 
 | 2871 |  | 
 | 2872 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2873 |   %result = shufflevector <4 x i32> %v1, <4 x i32> %v2,  | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2874 |                           <4 x i32> <i32 0, i32 4, i32 1, i32 5>  <i>; yields <4 x i32></i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2875 |   %result = shufflevector <4 x i32> %v1, <4 x i32> undef,  | 
 | 2876 |                           <4 x i32> <i32 0, i32 1, i32 2, i32 3>  <i>; yields <4 x i32></i> - Identity shuffle. | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2877 | </pre> | 
 | 2878 | </div> | 
 | 2879 |  | 
| Tanya Lattner | 0947429 | 2006-04-14 19:24:33 +0000 | [diff] [blame] | 2880 |  | 
| Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2881 | <!-- ======================================================================= --> | 
 | 2882 | <div class="doc_subsection">  | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2883 |   <a name="aggregateops">Aggregate Operations</a> | 
 | 2884 | </div> | 
 | 2885 |  | 
 | 2886 | <div class="doc_text"> | 
 | 2887 |  | 
 | 2888 | <p>LLVM supports several instructions for working with aggregate values. | 
 | 2889 | </p> | 
 | 2890 |  | 
 | 2891 | </div> | 
 | 2892 |  | 
 | 2893 | <!-- _______________________________________________________________________ --> | 
 | 2894 | <div class="doc_subsubsection"> | 
 | 2895 |    <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a> | 
 | 2896 | </div> | 
 | 2897 |  | 
 | 2898 | <div class="doc_text"> | 
 | 2899 |  | 
 | 2900 | <h5>Syntax:</h5> | 
 | 2901 |  | 
 | 2902 | <pre> | 
 | 2903 |   <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* | 
 | 2904 | </pre> | 
 | 2905 |  | 
 | 2906 | <h5>Overview:</h5> | 
 | 2907 |  | 
 | 2908 | <p> | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2909 | The '<tt>extractvalue</tt>' instruction extracts the value of a struct field | 
 | 2910 | or array element from an aggregate value. | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2911 | </p> | 
 | 2912 |  | 
 | 2913 |  | 
 | 2914 | <h5>Arguments:</h5> | 
 | 2915 |  | 
 | 2916 | <p> | 
 | 2917 | The first operand of an '<tt>extractvalue</tt>' instruction is a | 
 | 2918 | value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2919 | type.  The operands are constant indices to specify which value to extract | 
| Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 2920 | in a similar manner as indices in a | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2921 | '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. | 
 | 2922 | </p> | 
 | 2923 |  | 
 | 2924 | <h5>Semantics:</h5> | 
 | 2925 |  | 
 | 2926 | <p> | 
 | 2927 | The result is the value at the position in the aggregate specified by | 
 | 2928 | the index operands. | 
 | 2929 | </p> | 
 | 2930 |  | 
 | 2931 | <h5>Example:</h5> | 
 | 2932 |  | 
 | 2933 | <pre> | 
| Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 2934 |   %result = extractvalue {i32, float} %agg, 0    <i>; yields i32</i> | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2935 | </pre> | 
 | 2936 | </div> | 
 | 2937 |  | 
 | 2938 |  | 
 | 2939 | <!-- _______________________________________________________________________ --> | 
 | 2940 | <div class="doc_subsubsection"> | 
 | 2941 |    <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a> | 
 | 2942 | </div> | 
 | 2943 |  | 
 | 2944 | <div class="doc_text"> | 
 | 2945 |  | 
 | 2946 | <h5>Syntax:</h5> | 
 | 2947 |  | 
 | 2948 | <pre> | 
| Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 2949 |   <result> = insertvalue <aggregate type> <val>, <ty> <val>, <idx>    <i>; yields <n x <ty>></i> | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2950 | </pre> | 
 | 2951 |  | 
 | 2952 | <h5>Overview:</h5> | 
 | 2953 |  | 
 | 2954 | <p> | 
 | 2955 | The '<tt>insertvalue</tt>' instruction inserts a value | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2956 | into a struct field or array element in an aggregate. | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2957 | </p> | 
 | 2958 |  | 
 | 2959 |  | 
 | 2960 | <h5>Arguments:</h5> | 
 | 2961 |  | 
 | 2962 | <p> | 
 | 2963 | The first operand of an '<tt>insertvalue</tt>' instruction is a | 
 | 2964 | value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. | 
 | 2965 | The second operand is a first-class value to insert. | 
| Dan Gohman | c4b49eb | 2008-05-23 21:53:15 +0000 | [diff] [blame] | 2966 | The following operands are constant indices | 
| Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 2967 | indicating the position at which to insert the value in a similar manner as | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2968 | indices in a | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2969 | '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. | 
 | 2970 | The value to insert must have the same type as the value identified | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2971 | by the indices. | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2972 |  | 
 | 2973 | <h5>Semantics:</h5> | 
 | 2974 |  | 
 | 2975 | <p> | 
 | 2976 | The result is an aggregate of the same type as <tt>val</tt>.  Its | 
 | 2977 | value is that of <tt>val</tt> except that the value at the position | 
| Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 2978 | specified by the indices is that of <tt>elt</tt>. | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2979 | </p> | 
 | 2980 |  | 
 | 2981 | <h5>Example:</h5> | 
 | 2982 |  | 
 | 2983 | <pre> | 
| Dan Gohman | 52bb2db | 2008-06-23 15:26:37 +0000 | [diff] [blame^] | 2984 |   %result = insertvalue {i32, float} %agg, i32 1, 0    <i>; yields {i32, float}</i> | 
| Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 2985 | </pre> | 
 | 2986 | </div> | 
 | 2987 |  | 
 | 2988 |  | 
 | 2989 | <!-- ======================================================================= --> | 
 | 2990 | <div class="doc_subsection">  | 
| Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 2991 |   <a name="memoryops">Memory Access and Addressing Operations</a> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2992 | </div> | 
 | 2993 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2994 | <div class="doc_text"> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2995 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2996 | <p>A key design point of an SSA-based representation is how it | 
 | 2997 | represents memory.  In LLVM, no memory locations are in SSA form, which | 
 | 2998 | makes things very simple.  This section describes how to read, write, | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2999 | allocate, and free memory in LLVM.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3000 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3001 | </div> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3002 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3003 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3004 | <div class="doc_subsubsection"> | 
 | 3005 |   <a name="i_malloc">'<tt>malloc</tt>' Instruction</a> | 
 | 3006 | </div> | 
 | 3007 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3008 | <div class="doc_text"> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3009 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3010 | <h5>Syntax:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3011 |  | 
 | 3012 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3013 |   <result> = malloc <type>[, i32 <NumElements>][, align <alignment>]     <i>; yields {type*}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3014 | </pre> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3015 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3016 | <h5>Overview:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3017 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3018 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system | 
| Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 3019 | heap and returns a pointer to it. The object is always allocated in the generic  | 
 | 3020 | address space (address space zero).</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3021 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3022 | <h5>Arguments:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3023 |  | 
 | 3024 | <p>The '<tt>malloc</tt>' instruction allocates | 
 | 3025 | <tt>sizeof(<type>)*NumElements</tt> | 
| John Criswell | 6e4ca61 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 3026 | bytes of memory from the operating system and returns a pointer of the | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3027 | appropriate type to the program.  If "NumElements" is specified, it is the | 
| Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3028 | number of elements allocated, otherwise "NumElements" is defaulted to be one. | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3029 | If a constant alignment is specified, the value result of the allocation is guaranteed to | 
| Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3030 | be aligned to at least that boundary.  If not specified, or if zero, the target can | 
 | 3031 | choose to align the allocation on any convenient boundary.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3032 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3033 | <p>'<tt>type</tt>' must be a sized type.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3034 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3035 | <h5>Semantics:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3036 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3037 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 3038 | a pointer is returned.  The result of a zero byte allocattion is undefined.  The | 
 | 3039 | result is null if there is insufficient memory available.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3040 |  | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3041 | <h5>Example:</h5> | 
 | 3042 |  | 
 | 3043 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3044 |   %array  = malloc [4 x i8 ]                    <i>; yields {[%4 x i8]*}:array</i> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3045 |  | 
| Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 3046 |   %size   = <a href="#i_add">add</a> i32 2, 2                        <i>; yields {i32}:size = i32 4</i> | 
 | 3047 |   %array1 = malloc i8, i32 4                    <i>; yields {i8*}:array1</i> | 
 | 3048 |   %array2 = malloc [12 x i8], i32 %size         <i>; yields {[12 x i8]*}:array2</i> | 
 | 3049 |   %array3 = malloc i32, i32 4, align 1024       <i>; yields {i32*}:array3</i> | 
 | 3050 |   %array4 = malloc i32, align 1024              <i>; yields {i32*}:array4</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3051 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3052 | </div> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3053 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3054 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3055 | <div class="doc_subsubsection"> | 
 | 3056 |   <a name="i_free">'<tt>free</tt>' Instruction</a> | 
 | 3057 | </div> | 
 | 3058 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3059 | <div class="doc_text"> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3060 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3061 | <h5>Syntax:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3062 |  | 
 | 3063 | <pre> | 
 | 3064 |   free <type> <value>                              <i>; yields {void}</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3065 | </pre> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3066 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3067 | <h5>Overview:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3068 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3069 | <p>The '<tt>free</tt>' instruction returns memory back to the unused | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3070 | memory heap to be reallocated in the future.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3071 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3072 | <h5>Arguments:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3073 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3074 | <p>'<tt>value</tt>' shall be a pointer value that points to a value | 
 | 3075 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' | 
 | 3076 | instruction.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3077 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3078 | <h5>Semantics:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3079 |  | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3080 | <p>Access to the memory pointed to by the pointer is no longer defined | 
| Chris Lattner | e0db56d | 2008-04-19 22:41:32 +0000 | [diff] [blame] | 3081 | after this instruction executes.  If the pointer is null, the operation | 
 | 3082 | is a noop.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3083 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3084 | <h5>Example:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3085 |  | 
 | 3086 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3087 |   %array  = <a href="#i_malloc">malloc</a> [4 x i8]                    <i>; yields {[4 x i8]*}:array</i> | 
 | 3088 |             free   [4 x i8]* %array | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3089 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3090 | </div> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3091 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3092 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3093 | <div class="doc_subsubsection"> | 
 | 3094 |   <a name="i_alloca">'<tt>alloca</tt>' Instruction</a> | 
 | 3095 | </div> | 
 | 3096 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3097 | <div class="doc_text"> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3098 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3099 | <h5>Syntax:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3100 |  | 
 | 3101 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3102 |   <result> = alloca <type>[, i32 <NumElements>][, align <alignment>]     <i>; yields {type*}:result</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3103 | </pre> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3104 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3105 | <h5>Overview:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3106 |  | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3107 | <p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the | 
 | 3108 | currently executing function, to be automatically released when this function | 
| Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 3109 | returns to its caller. The object is always allocated in the generic address  | 
 | 3110 | space (address space zero).</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3111 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3112 | <h5>Arguments:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3113 |  | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3114 | <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3115 | bytes of memory on the runtime stack, returning a pointer of the | 
| Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3116 | appropriate type to the program.  If "NumElements" is specified, it is the | 
 | 3117 | number of elements allocated, otherwise "NumElements" is defaulted to be one. | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3118 | If a constant alignment is specified, the value result of the allocation is guaranteed | 
| Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3119 | to be aligned to at least that boundary.  If not specified, or if zero, the target | 
 | 3120 | can choose to align the allocation on any convenient boundary.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3121 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3122 | <p>'<tt>type</tt>' may be any sized type.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3123 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3124 | <h5>Semantics:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3125 |  | 
| Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 3126 | <p>Memory is allocated; a pointer is returned.  The operation is undefiend if | 
 | 3127 | there is insufficient stack space for the allocation.  '<tt>alloca</tt>'d | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3128 | memory is automatically released when the function returns.  The '<tt>alloca</tt>' | 
 | 3129 | instruction is commonly used to represent automatic variables that must | 
 | 3130 | have an address available.  When the function returns (either with the <tt><a | 
| John Criswell | dae2e93 | 2005-05-12 16:55:34 +0000 | [diff] [blame] | 3131 |  href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt> | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3132 | instructions), the memory is reclaimed.  Allocating zero bytes | 
 | 3133 | is legal, but the result is undefined.</p> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3134 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3135 | <h5>Example:</h5> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3136 |  | 
 | 3137 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3138 |   %ptr = alloca i32                              <i>; yields {i32*}:ptr</i> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3139 |   %ptr = alloca i32, i32 4                       <i>; yields {i32*}:ptr</i> | 
 | 3140 |   %ptr = alloca i32, i32 4, align 1024           <i>; yields {i32*}:ptr</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3141 |   %ptr = alloca i32, align 1024                  <i>; yields {i32*}:ptr</i> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3142 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3143 | </div> | 
| Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3144 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3145 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3146 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' | 
 | 3147 | Instruction</a> </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3148 | <div class="doc_text"> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3149 | <h5>Syntax:</h5> | 
| Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 3150 | <pre>  <result> = load <ty>* <pointer>[, align <alignment>]<br>  <result> = volatile load <ty>* <pointer>[, align <alignment>]<br></pre> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3151 | <h5>Overview:</h5> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3152 | <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] | 3153 | <h5>Arguments:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3154 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 3155 | address from which to load.  The pointer must point to a <a | 
| Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 3156 |  href="#t_firstclass">first class</a> type.  If the <tt>load</tt> is | 
| John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 3157 | marked as <tt>volatile</tt>, then the optimizer is not allowed to modify | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3158 | the number or order of execution of this <tt>load</tt> with other | 
 | 3159 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> | 
 | 3160 | instructions. </p> | 
| Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3161 | <p> | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3162 | The optional constant "align" argument specifies the alignment of the operation | 
| Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3163 | (that is, the alignment of the memory address). A value of 0 or an | 
 | 3164 | omitted "align" argument means that the operation has the preferential | 
 | 3165 | alignment for the target. It is the responsibility of the code emitter | 
 | 3166 | to ensure that the alignment information is correct. Overestimating | 
 | 3167 | the alignment results in an undefined behavior. Underestimating the | 
 | 3168 | alignment may produce less efficient code. An alignment of 1 is always | 
 | 3169 | safe. | 
 | 3170 | </p> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3171 | <h5>Semantics:</h5> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3172 | <p>The location of memory pointed to is loaded.</p> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3173 | <h5>Examples:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3174 | <pre>  %ptr = <a href="#i_alloca">alloca</a> i32                               <i>; yields {i32*}:ptr</i> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3175 |   <a | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3176 |  href="#i_store">store</a> i32 3, i32* %ptr                          <i>; yields {void}</i> | 
 | 3177 |   %val = load i32* %ptr                           <i>; yields {i32}:val = i32 3</i> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3178 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3179 | </div> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3180 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3181 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' | 
 | 3182 | Instruction</a> </div> | 
| Reid Spencer | 035ab57 | 2006-11-09 21:18:01 +0000 | [diff] [blame] | 3183 | <div class="doc_text"> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3184 | <h5>Syntax:</h5> | 
| Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 3185 | <pre>  store <ty> <value>, <ty>* <pointer>[, align <alignment>]                   <i>; yields {void}</i> | 
 | 3186 |   volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>]          <i>; yields {void}</i> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3187 | </pre> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3188 | <h5>Overview:</h5> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3189 | <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] | 3190 | <h5>Arguments:</h5> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3191 | <p>There are two arguments to the '<tt>store</tt>' instruction: a value | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3192 | to store and an address at which to store it.  The type of the '<tt><pointer></tt>' | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3193 | operand must be a pointer to the <a href="#t_firstclass">first class</a> type | 
 | 3194 | of the '<tt><value></tt>' | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3195 | operand. If the <tt>store</tt> is marked as <tt>volatile</tt>, then the | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3196 | optimizer is not allowed to modify the number or order of execution of | 
 | 3197 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a | 
 | 3198 |  href="#i_store">store</a></tt> instructions.</p> | 
| Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3199 | <p> | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3200 | The optional constant "align" argument specifies the alignment of the operation | 
| Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3201 | (that is, the alignment of the memory address). A value of 0 or an | 
 | 3202 | omitted "align" argument means that the operation has the preferential | 
 | 3203 | alignment for the target. It is the responsibility of the code emitter | 
 | 3204 | to ensure that the alignment information is correct. Overestimating | 
 | 3205 | the alignment results in an undefined behavior. Underestimating the | 
 | 3206 | alignment may produce less efficient code. An alignment of 1 is always | 
 | 3207 | safe. | 
 | 3208 | </p> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3209 | <h5>Semantics:</h5> | 
 | 3210 | <p>The contents of memory are updated to contain '<tt><value></tt>' | 
 | 3211 | at the location specified by the '<tt><pointer></tt>' operand.</p> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3212 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3213 | <pre>  %ptr = <a href="#i_alloca">alloca</a> i32                               <i>; yields {i32*}:ptr</i> | 
| Bill Wendling | 8c6c72d | 2007-10-22 05:10:05 +0000 | [diff] [blame] | 3214 |   store i32 3, i32* %ptr                          <i>; yields {void}</i> | 
 | 3215 |   %val = <a href="#i_load">load</a> i32* %ptr                           <i>; yields {i32}:val = i32 3</i> | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3216 | </pre> | 
| Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3217 | </div> | 
 | 3218 |  | 
| Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3219 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3220 | <div class="doc_subsubsection"> | 
 | 3221 |    <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> | 
 | 3222 | </div> | 
 | 3223 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3224 | <div class="doc_text"> | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3225 | <h5>Syntax:</h5> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3226 | <pre> | 
 | 3227 |   <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}* | 
 | 3228 | </pre> | 
 | 3229 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3230 | <h5>Overview:</h5> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3231 |  | 
 | 3232 | <p> | 
 | 3233 | The '<tt>getelementptr</tt>' instruction is used to get the address of a | 
 | 3234 | subelement of an aggregate data structure.</p> | 
 | 3235 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3236 | <h5>Arguments:</h5> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3237 |  | 
| Reid Spencer | 85f5b5b | 2006-12-04 21:29:24 +0000 | [diff] [blame] | 3238 | <p>This instruction takes a list of integer operands that indicate what | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3239 | elements of the aggregate object to index to.  The actual types of the arguments | 
 | 3240 | provided depend on the type of the first pointer argument.  The | 
 | 3241 | '<tt>getelementptr</tt>' instruction is used to index down through the type | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3242 | levels of a structure or to a specific index in an array.  When indexing into a | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3243 | structure, only <tt>i32</tt> integer constants are allowed.  When indexing  | 
| Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 3244 | into an array or pointer, only integers of 32 or 64 bits are allowed; 32-bit  | 
 | 3245 | values will be sign extended to 64-bits if required.</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3246 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3247 | <p>For example, let's consider a C code fragment and how it gets | 
 | 3248 | compiled to LLVM:</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3249 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3250 | <div class="doc_code"> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3251 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3252 | struct RT { | 
 | 3253 |   char A; | 
| Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3254 |   int B[10][20]; | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3255 |   char C; | 
 | 3256 | }; | 
 | 3257 | struct ST { | 
| Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3258 |   int X; | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3259 |   double Y; | 
 | 3260 |   struct RT Z; | 
 | 3261 | }; | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3262 |  | 
| Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3263 | int *foo(struct ST *s) { | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3264 |   return &s[1].Z.B[5][13]; | 
 | 3265 | } | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3266 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3267 | </div> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3268 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3269 | <p>The LLVM code generated by the GCC frontend is:</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3270 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3271 | <div class="doc_code"> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3272 | <pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3273 | %RT = type { i8 , [10 x [20 x i32]], i8  } | 
 | 3274 | %ST = type { i32, double, %RT } | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3275 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3276 | define i32* %foo(%ST* %s) { | 
 | 3277 | entry: | 
 | 3278 |   %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 | 
 | 3279 |   ret i32* %reg | 
 | 3280 | } | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3281 | </pre> | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3282 | </div> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3283 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3284 | <h5>Semantics:</h5> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3285 |  | 
 | 3286 | <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend | 
| John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3287 | on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a> | 
| Reid Spencer | 85f5b5b | 2006-12-04 21:29:24 +0000 | [diff] [blame] | 3288 | and <a href="#t_array">array</a> types can use a 32-bit or 64-bit | 
| Reid Spencer | 42ddd84 | 2006-12-03 16:53:48 +0000 | [diff] [blame] | 3289 | <a href="#t_integer">integer</a> type but the value will always be sign extended | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3290 | to 64-bits.  <a href="#t_struct">Structure</a> and <a href="#t_pstruct">packed | 
 | 3291 | structure</a> types require <tt>i32</tt> <b>constants</b>.</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3292 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3293 | <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>' | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3294 | type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ i32, double, %RT | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3295 | }</tt>' type, a structure.  The second index indexes into the third element of | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3296 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]], | 
 | 3297 | i8  }</tt>' type, another structure.  The third index indexes into the second | 
 | 3298 | element of the structure, yielding a '<tt>[10 x [20 x i32]]</tt>' type, an | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3299 | array.  The two dimensions of the array are subscripted into, yielding an | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3300 | '<tt>i32</tt>' type.  The '<tt>getelementptr</tt>' instruction returns a pointer | 
 | 3301 | to this element, thus computing a value of '<tt>i32*</tt>' type.</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3302 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3303 | <p>Note that it is perfectly legal to index partially through a | 
 | 3304 | structure, returning a pointer to an inner element.  Because of this, | 
 | 3305 | the LLVM code for the given testcase is equivalent to:</p> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3306 |  | 
 | 3307 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3308 |   define i32* %foo(%ST* %s) { | 
 | 3309 |     %t1 = getelementptr %ST* %s, i32 1                        <i>; yields %ST*:%t1</i> | 
| Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3310 |     %t2 = getelementptr %ST* %t1, i32 0, i32 2                <i>; yields %RT*:%t2</i> | 
 | 3311 |     %t3 = getelementptr %RT* %t2, i32 0, i32 1                <i>; yields [10 x [20 x i32]]*:%t3</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3312 |     %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5  <i>; yields [20 x i32]*:%t4</i> | 
 | 3313 |     %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13        <i>; yields i32*:%t5</i> | 
 | 3314 |     ret i32* %t5 | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3315 |   } | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3316 | </pre> | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3317 |  | 
 | 3318 | <p>Note that it is undefined to access an array out of bounds: array and  | 
 | 3319 | pointer indexes must always be within the defined bounds of the array type. | 
| Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 3320 | The one exception for this rule is zero length arrays.  These arrays are | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3321 | defined to be accessible as variable length arrays, which requires access | 
 | 3322 | beyond the zero'th element.</p> | 
 | 3323 |  | 
| Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 3324 | <p>The getelementptr instruction is often confusing.  For some more insight | 
 | 3325 | into how it works, see <a href="GetElementPtr.html">the getelementptr  | 
 | 3326 | FAQ</a>.</p> | 
 | 3327 |  | 
| Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3328 | <h5>Example:</h5> | 
| Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3329 |  | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3330 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3331 |     <i>; yields [12 x i8]*:aptr</i> | 
 | 3332 |     %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1 | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3333 | </pre> | 
| Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3334 | </div> | 
| Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3335 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3336 | <!-- ======================================================================= --> | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3337 | <div class="doc_subsection"> <a name="convertops">Conversion Operations</a> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3338 | </div> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3339 | <div class="doc_text"> | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3340 | <p>The instructions in this category are the conversion instructions (casting) | 
 | 3341 | which all take a single operand and a type. They perform various bit conversions | 
 | 3342 | on the operand.</p> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3343 | </div> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3344 |  | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3345 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3346 | <div class="doc_subsubsection"> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3347 |    <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a> | 
 | 3348 | </div> | 
 | 3349 | <div class="doc_text"> | 
 | 3350 |  | 
 | 3351 | <h5>Syntax:</h5> | 
 | 3352 | <pre> | 
 | 3353 |   <result> = trunc <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3354 | </pre> | 
 | 3355 |  | 
 | 3356 | <h5>Overview:</h5> | 
 | 3357 | <p> | 
 | 3358 | The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>. | 
 | 3359 | </p> | 
 | 3360 |  | 
 | 3361 | <h5>Arguments:</h5> | 
 | 3362 | <p> | 
 | 3363 | The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must  | 
 | 3364 | be an <a href="#t_integer">integer</a> type, and a type that specifies the size  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 3365 | and type of the result, which must be an <a href="#t_integer">integer</a>  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3366 | type. The bit size of <tt>value</tt> must be larger than the bit size of  | 
 | 3367 | <tt>ty2</tt>. Equal sized types are not allowed.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3368 |  | 
 | 3369 | <h5>Semantics:</h5> | 
 | 3370 | <p> | 
 | 3371 | The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3372 | and converts the remaining bits to <tt>ty2</tt>. Since the source size must be | 
 | 3373 | larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>. | 
 | 3374 | It will always truncate bits.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3375 |  | 
 | 3376 | <h5>Example:</h5> | 
 | 3377 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3378 |   %X = trunc i32 257 to i8              <i>; yields i8:1</i> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3379 |   %Y = trunc i32 123 to i1              <i>; yields i1:true</i> | 
 | 3380 |   %Y = trunc i32 122 to i1              <i>; yields i1:false</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3381 | </pre> | 
 | 3382 | </div> | 
 | 3383 |  | 
 | 3384 | <!-- _______________________________________________________________________ --> | 
 | 3385 | <div class="doc_subsubsection"> | 
 | 3386 |    <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a> | 
 | 3387 | </div> | 
 | 3388 | <div class="doc_text"> | 
 | 3389 |  | 
 | 3390 | <h5>Syntax:</h5> | 
 | 3391 | <pre> | 
 | 3392 |   <result> = zext <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3393 | </pre> | 
 | 3394 |  | 
 | 3395 | <h5>Overview:</h5> | 
 | 3396 | <p>The '<tt>zext</tt>' instruction zero extends its operand to type  | 
 | 3397 | <tt>ty2</tt>.</p> | 
 | 3398 |  | 
 | 3399 |  | 
 | 3400 | <h5>Arguments:</h5> | 
 | 3401 | <p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 3402 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must | 
 | 3403 | also be of <a href="#t_integer">integer</a> type. The bit size of the | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3404 | <tt>value</tt> must be smaller than the bit size of the destination type,  | 
 | 3405 | <tt>ty2</tt>.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3406 |  | 
 | 3407 | <h5>Semantics:</h5> | 
 | 3408 | <p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero | 
| Chris Lattner | d1d2517 | 2007-05-24 19:13:27 +0000 | [diff] [blame] | 3409 | bits until it reaches the size of the destination type, <tt>ty2</tt>.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3410 |  | 
| Reid Spencer | b592952 | 2007-01-12 15:46:11 +0000 | [diff] [blame] | 3411 | <p>When zero extending from i1, the result will always be either 0 or 1.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3412 |  | 
 | 3413 | <h5>Example:</h5> | 
 | 3414 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3415 |   %X = zext i32 257 to i64              <i>; yields i64:257</i> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3416 |   %Y = zext i1 true to i32              <i>; yields i32:1</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3417 | </pre> | 
 | 3418 | </div> | 
 | 3419 |  | 
 | 3420 | <!-- _______________________________________________________________________ --> | 
 | 3421 | <div class="doc_subsubsection"> | 
 | 3422 |    <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a> | 
 | 3423 | </div> | 
 | 3424 | <div class="doc_text"> | 
 | 3425 |  | 
 | 3426 | <h5>Syntax:</h5> | 
 | 3427 | <pre> | 
 | 3428 |   <result> = sext <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3429 | </pre> | 
 | 3430 |  | 
 | 3431 | <h5>Overview:</h5> | 
 | 3432 | <p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p> | 
 | 3433 |  | 
 | 3434 | <h5>Arguments:</h5> | 
 | 3435 | <p> | 
 | 3436 | The '<tt>sext</tt>' instruction takes a value to cast, which must be of  | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 3437 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must | 
 | 3438 | also be of <a href="#t_integer">integer</a> type.  The bit size of the | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3439 | <tt>value</tt> must be smaller than the bit size of the destination type,  | 
 | 3440 | <tt>ty2</tt>.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3441 |  | 
 | 3442 | <h5>Semantics:</h5> | 
 | 3443 | <p> | 
 | 3444 | The '<tt>sext</tt>' instruction performs a sign extension by copying the sign | 
 | 3445 | bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of | 
| Chris Lattner | d1d2517 | 2007-05-24 19:13:27 +0000 | [diff] [blame] | 3446 | the type <tt>ty2</tt>.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3447 |  | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3448 | <p>When sign extending from i1, the extension always results in -1 or 0.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3449 |  | 
 | 3450 | <h5>Example:</h5> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3451 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3452 |   %X = sext i8  -1 to i16              <i>; yields i16   :65535</i> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3453 |   %Y = sext i1 true to i32             <i>; yields i32:-1</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3454 | </pre> | 
 | 3455 | </div> | 
 | 3456 |  | 
 | 3457 | <!-- _______________________________________________________________________ --> | 
 | 3458 | <div class="doc_subsubsection"> | 
| Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 3459 |    <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a> | 
 | 3460 | </div> | 
 | 3461 |  | 
 | 3462 | <div class="doc_text"> | 
 | 3463 |  | 
 | 3464 | <h5>Syntax:</h5> | 
 | 3465 |  | 
 | 3466 | <pre> | 
 | 3467 |   <result> = fptrunc <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3468 | </pre> | 
 | 3469 |  | 
 | 3470 | <h5>Overview:</h5> | 
 | 3471 | <p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type | 
 | 3472 | <tt>ty2</tt>.</p> | 
 | 3473 |  | 
 | 3474 |  | 
 | 3475 | <h5>Arguments:</h5> | 
 | 3476 | <p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating | 
 | 3477 |   point</a> value to cast and a <a href="#t_floating">floating point</a> type to | 
 | 3478 | cast it to. The size of <tt>value</tt> must be larger than the size of | 
 | 3479 | <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a  | 
 | 3480 | <i>no-op cast</i>.</p> | 
 | 3481 |  | 
 | 3482 | <h5>Semantics:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3483 | <p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger | 
 | 3484 | <a href="#t_floating">floating point</a> type to a smaller  | 
 | 3485 | <a href="#t_floating">floating point</a> type.  If the value cannot fit within  | 
 | 3486 | the destination type, <tt>ty2</tt>, then the results are undefined.</p> | 
| Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 3487 |  | 
 | 3488 | <h5>Example:</h5> | 
 | 3489 | <pre> | 
 | 3490 |   %X = fptrunc double 123.0 to float         <i>; yields float:123.0</i> | 
 | 3491 |   %Y = fptrunc double 1.0E+300 to float      <i>; yields undefined</i> | 
 | 3492 | </pre> | 
 | 3493 | </div> | 
 | 3494 |  | 
 | 3495 | <!-- _______________________________________________________________________ --> | 
 | 3496 | <div class="doc_subsubsection"> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3497 |    <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a> | 
 | 3498 | </div> | 
 | 3499 | <div class="doc_text"> | 
 | 3500 |  | 
 | 3501 | <h5>Syntax:</h5> | 
 | 3502 | <pre> | 
 | 3503 |   <result> = fpext <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3504 | </pre> | 
 | 3505 |  | 
 | 3506 | <h5>Overview:</h5> | 
 | 3507 | <p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger | 
 | 3508 | floating point value.</p> | 
 | 3509 |  | 
 | 3510 | <h5>Arguments:</h5> | 
 | 3511 | <p>The '<tt>fpext</tt>' instruction takes a  | 
 | 3512 | <a href="#t_floating">floating point</a> <tt>value</tt> to cast,  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3513 | and a <a href="#t_floating">floating point</a> type to cast it to. The source | 
 | 3514 | type must be smaller than the destination type.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3515 |  | 
 | 3516 | <h5>Semantics:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3517 | <p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from a smaller | 
| Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 3518 | <a href="#t_floating">floating point</a> type to a larger  | 
 | 3519 | <a href="#t_floating">floating point</a> type. The <tt>fpext</tt> cannot be  | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3520 | used to make a <i>no-op cast</i> because it always changes bits. Use  | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3521 | <tt>bitcast</tt> to make a <i>no-op cast</i> for a floating point cast.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3522 |  | 
 | 3523 | <h5>Example:</h5> | 
 | 3524 | <pre> | 
 | 3525 |   %X = fpext float 3.1415 to double        <i>; yields double:3.1415</i> | 
 | 3526 |   %Y = fpext float 1.0 to float            <i>; yields float:1.0 (no-op)</i> | 
 | 3527 | </pre> | 
 | 3528 | </div> | 
 | 3529 |  | 
 | 3530 | <!-- _______________________________________________________________________ --> | 
 | 3531 | <div class="doc_subsubsection"> | 
| Reid Spencer | 24d6da5 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 3532 |    <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3533 | </div> | 
 | 3534 | <div class="doc_text"> | 
 | 3535 |  | 
 | 3536 | <h5>Syntax:</h5> | 
 | 3537 | <pre> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3538 |   <result> = fptoui <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3539 | </pre> | 
 | 3540 |  | 
 | 3541 | <h5>Overview:</h5> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3542 | <p>The '<tt>fptoui</tt>' converts a floating point <tt>value</tt> to its | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3543 | unsigned integer equivalent of type <tt>ty2</tt>. | 
 | 3544 | </p> | 
 | 3545 |  | 
 | 3546 | <h5>Arguments:</h5> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3547 | <p>The '<tt>fptoui</tt>' instruction takes a value to cast, which must be a  | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3548 | scalar or vector <a href="#t_floating">floating point</a> value, and a type  | 
 | 3549 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>  | 
 | 3550 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a | 
 | 3551 | vector integer type with the same number of elements as <tt>ty</tt></p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3552 |  | 
 | 3553 | <h5>Semantics:</h5> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3554 | <p> The '<tt>fptoui</tt>' instruction converts its  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3555 | <a href="#t_floating">floating point</a> operand into the nearest (rounding | 
 | 3556 | towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>, | 
 | 3557 | the results are undefined.</p> | 
 | 3558 |  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3559 | <h5>Example:</h5> | 
 | 3560 | <pre> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3561 |   %X = fptoui double 123.0 to i32      <i>; yields i32:123</i> | 
| Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 3562 |   %Y = fptoui float 1.0E+300 to i1     <i>; yields undefined:1</i> | 
| Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3563 |   %X = fptoui float 1.04E+17 to i8     <i>; yields undefined:1</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3564 | </pre> | 
 | 3565 | </div> | 
 | 3566 |  | 
 | 3567 | <!-- _______________________________________________________________________ --> | 
 | 3568 | <div class="doc_subsubsection"> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3569 |    <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3570 | </div> | 
 | 3571 | <div class="doc_text"> | 
 | 3572 |  | 
 | 3573 | <h5>Syntax:</h5> | 
 | 3574 | <pre> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3575 |   <result> = fptosi <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3576 | </pre> | 
 | 3577 |  | 
 | 3578 | <h5>Overview:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3579 | <p>The '<tt>fptosi</tt>' instruction converts  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3580 | <a href="#t_floating">floating point</a> <tt>value</tt> to type <tt>ty2</tt>. | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3581 | </p> | 
 | 3582 |  | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3583 | <h5>Arguments:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3584 | <p> The '<tt>fptosi</tt>' instruction takes a value to cast, which must be a  | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3585 | scalar or vector <a href="#t_floating">floating point</a> value, and a type  | 
 | 3586 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a>  | 
 | 3587 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a | 
 | 3588 | vector integer type with the same number of elements as <tt>ty</tt></p> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3589 |  | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3590 | <h5>Semantics:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3591 | <p>The '<tt>fptosi</tt>' instruction converts its  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3592 | <a href="#t_floating">floating point</a> operand into the nearest (rounding | 
 | 3593 | towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>, | 
 | 3594 | the results are undefined.</p> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3595 |  | 
| Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3596 | <h5>Example:</h5> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3597 | <pre> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3598 |   %X = fptosi double -123.0 to i32      <i>; yields i32:-123</i> | 
| Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 3599 |   %Y = fptosi float 1.0E-247 to i1      <i>; yields undefined:1</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3600 |   %X = fptosi float 1.04E+17 to i8      <i>; yields undefined:1</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3601 | </pre> | 
 | 3602 | </div> | 
 | 3603 |  | 
 | 3604 | <!-- _______________________________________________________________________ --> | 
 | 3605 | <div class="doc_subsubsection"> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3606 |    <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3607 | </div> | 
 | 3608 | <div class="doc_text"> | 
 | 3609 |  | 
 | 3610 | <h5>Syntax:</h5> | 
 | 3611 | <pre> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3612 |   <result> = uitofp <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3613 | </pre> | 
 | 3614 |  | 
 | 3615 | <h5>Overview:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3616 | <p>The '<tt>uitofp</tt>' instruction regards <tt>value</tt> as an unsigned | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3617 | integer and converts that value to the <tt>ty2</tt> type.</p> | 
 | 3618 |  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3619 | <h5>Arguments:</h5> | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3620 | <p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a | 
 | 3621 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it | 
 | 3622 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>  | 
 | 3623 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector | 
 | 3624 | floating point type with the same number of elements as <tt>ty</tt></p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3625 |  | 
 | 3626 | <h5>Semantics:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3627 | <p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3628 | integer quantity and converts it to the corresponding floating point value. If | 
| Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 3629 | the value cannot fit in the floating point value, the results are undefined.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3630 |  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3631 | <h5>Example:</h5> | 
 | 3632 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3633 |   %X = uitofp i32 257 to float         <i>; yields float:257.0</i> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3634 |   %Y = uitofp i8  -1 to double         <i>; yields double:255.0</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3635 | </pre> | 
 | 3636 | </div> | 
 | 3637 |  | 
 | 3638 | <!-- _______________________________________________________________________ --> | 
 | 3639 | <div class="doc_subsubsection"> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3640 |    <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3641 | </div> | 
 | 3642 | <div class="doc_text"> | 
 | 3643 |  | 
 | 3644 | <h5>Syntax:</h5> | 
 | 3645 | <pre> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3646 |   <result> = sitofp <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3647 | </pre> | 
 | 3648 |  | 
 | 3649 | <h5>Overview:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3650 | <p>The '<tt>sitofp</tt>' instruction regards <tt>value</tt> as a signed | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3651 | integer and converts that value to the <tt>ty2</tt> type.</p> | 
 | 3652 |  | 
 | 3653 | <h5>Arguments:</h5> | 
| Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3654 | <p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a | 
 | 3655 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it | 
 | 3656 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a>  | 
 | 3657 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector | 
 | 3658 | floating point type with the same number of elements as <tt>ty</tt></p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3659 |  | 
 | 3660 | <h5>Semantics:</h5> | 
| Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3661 | <p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3662 | integer quantity and converts it to the corresponding floating point value. If | 
| Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 3663 | the value cannot fit in the floating point value, the results are undefined.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3664 |  | 
 | 3665 | <h5>Example:</h5> | 
 | 3666 | <pre> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3667 |   %X = sitofp i32 257 to float         <i>; yields float:257.0</i> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3668 |   %Y = sitofp i8  -1 to double         <i>; yields double:-1.0</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3669 | </pre> | 
 | 3670 | </div> | 
 | 3671 |  | 
 | 3672 | <!-- _______________________________________________________________________ --> | 
 | 3673 | <div class="doc_subsubsection"> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3674 |    <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a> | 
 | 3675 | </div> | 
 | 3676 | <div class="doc_text"> | 
 | 3677 |  | 
 | 3678 | <h5>Syntax:</h5> | 
 | 3679 | <pre> | 
 | 3680 |   <result> = ptrtoint <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3681 | </pre> | 
 | 3682 |  | 
 | 3683 | <h5>Overview:</h5> | 
 | 3684 | <p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to  | 
 | 3685 | the integer type <tt>ty2</tt>.</p> | 
 | 3686 |  | 
 | 3687 | <h5>Arguments:</h5> | 
 | 3688 | <p>The '<tt>ptrtoint</tt>' instruction takes a <tt>value</tt> to cast, which  | 
| Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 3689 | must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3690 | <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.  | 
 | 3691 |  | 
 | 3692 | <h5>Semantics:</h5> | 
 | 3693 | <p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type | 
 | 3694 | <tt>ty2</tt> by interpreting the pointer value as an integer and either  | 
 | 3695 | truncating or zero extending that value to the size of the integer type. If | 
 | 3696 | <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If | 
 | 3697 | <tt>value</tt> is larger than <tt>ty2</tt> then a truncation is done. If they | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3698 | are the same size, then nothing is done (<i>no-op cast</i>) other than a type | 
 | 3699 | change.</p> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3700 |  | 
 | 3701 | <h5>Example:</h5> | 
 | 3702 | <pre> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3703 |   %X = ptrtoint i32* %X to i8           <i>; yields truncation on 32-bit architecture</i> | 
 | 3704 |   %Y = ptrtoint i32* %x to i64          <i>; yields zero extension on 32-bit architecture</i> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3705 | </pre> | 
 | 3706 | </div> | 
 | 3707 |  | 
 | 3708 | <!-- _______________________________________________________________________ --> | 
 | 3709 | <div class="doc_subsubsection"> | 
 | 3710 |    <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a> | 
 | 3711 | </div> | 
 | 3712 | <div class="doc_text"> | 
 | 3713 |  | 
 | 3714 | <h5>Syntax:</h5> | 
 | 3715 | <pre> | 
 | 3716 |   <result> = inttoptr <ty> <value> to <ty2>             <i>; yields ty2</i> | 
 | 3717 | </pre> | 
 | 3718 |  | 
 | 3719 | <h5>Overview:</h5> | 
 | 3720 | <p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to  | 
 | 3721 | a pointer type, <tt>ty2</tt>.</p> | 
 | 3722 |  | 
 | 3723 | <h5>Arguments:</h5> | 
| Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 3724 | <p>The '<tt>inttoptr</tt>' instruction takes an <a href="#t_integer">integer</a> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3725 | value to cast, and a type to cast it to, which must be a  | 
| Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3726 | <a href="#t_pointer">pointer</a> type. | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3727 |  | 
 | 3728 | <h5>Semantics:</h5> | 
 | 3729 | <p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type | 
 | 3730 | <tt>ty2</tt> by applying either a zero extension or a truncation depending on | 
 | 3731 | the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the | 
 | 3732 | size of a pointer then a truncation is done. If <tt>value</tt> is smaller than | 
 | 3733 | the size of a pointer then a zero extension is done. If they are the same size, | 
 | 3734 | nothing is done (<i>no-op cast</i>).</p> | 
 | 3735 |  | 
 | 3736 | <h5>Example:</h5> | 
 | 3737 | <pre> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3738 |   %X = inttoptr i32 255 to i32*          <i>; yields zero extension on 64-bit architecture</i> | 
 | 3739 |   %X = inttoptr i32 255 to i32*          <i>; yields no-op on 32-bit architecture</i> | 
 | 3740 |   %Y = inttoptr i64 0 to i32*            <i>; yields truncation on 32-bit architecture</i> | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3741 | </pre> | 
 | 3742 | </div> | 
 | 3743 |  | 
 | 3744 | <!-- _______________________________________________________________________ --> | 
 | 3745 | <div class="doc_subsubsection"> | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3746 |    <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3747 | </div> | 
 | 3748 | <div class="doc_text"> | 
 | 3749 |  | 
 | 3750 | <h5>Syntax:</h5> | 
 | 3751 | <pre> | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3752 |   <result> = bitcast <ty> <value> to <ty2>             <i>; yields ty2</i> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3753 | </pre> | 
 | 3754 |  | 
 | 3755 | <h5>Overview:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3756 |  | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3757 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3758 | <tt>ty2</tt> without changing any bits.</p> | 
 | 3759 |  | 
 | 3760 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3761 |  | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3762 | <p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be  | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3763 | a first class value, and a type to cast it to, which must also be a <a | 
 | 3764 |   href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt> | 
| Reid Spencer | 19b569f | 2007-01-09 20:08:58 +0000 | [diff] [blame] | 3765 | and the destination type, <tt>ty2</tt>, must be identical. If the source | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3766 | type is a pointer, the destination type must also be a pointer.  This | 
 | 3767 | instruction supports bitwise conversion of vectors to integers and to vectors | 
 | 3768 | of other types (as long as they have the same size).</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3769 |  | 
 | 3770 | <h5>Semantics:</h5> | 
| Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3771 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type | 
| Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3772 | <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with  | 
 | 3773 | this conversion.  The conversion is done as if the <tt>value</tt> had been  | 
 | 3774 | stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be | 
 | 3775 | converted to other pointer types with this instruction. To convert pointers to  | 
 | 3776 | other types, use the <a href="#i_inttoptr">inttoptr</a> or  | 
 | 3777 | <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p> | 
| Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3778 |  | 
 | 3779 | <h5>Example:</h5> | 
 | 3780 | <pre> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3781 |   %X = bitcast i8 255 to i8              <i>; yields i8 :-1</i> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3782 |   %Y = bitcast i32* %x to sint*          <i>; yields sint*:%x</i> | 
 | 3783 |   %Z = bitcast <2xint> %V to i64;        <i>; yields i64: %V</i>    | 
| Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3784 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3785 | </div> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3786 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3787 | <!-- ======================================================================= --> | 
 | 3788 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> | 
 | 3789 | <div class="doc_text"> | 
 | 3790 | <p>The instructions in this category are the "miscellaneous" | 
 | 3791 | instructions, which defy better classification.</p> | 
 | 3792 | </div> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3793 |  | 
 | 3794 | <!-- _______________________________________________________________________ --> | 
 | 3795 | <div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a> | 
 | 3796 | </div> | 
 | 3797 | <div class="doc_text"> | 
 | 3798 | <h5>Syntax:</h5> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3799 | <pre>  <result> = icmp <cond> <ty> <var1>, <var2>   <i>; yields {i1}:result</i> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3800 | </pre> | 
 | 3801 | <h5>Overview:</h5> | 
 | 3802 | <p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison | 
| Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3803 | of its two integer or pointer operands.</p> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3804 | <h5>Arguments:</h5> | 
 | 3805 | <p>The '<tt>icmp</tt>' instruction takes three operands. The first operand is | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3806 | the condition code indicating the kind of comparison to perform. It is not | 
 | 3807 | a value, just a keyword. The possible condition code are: | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3808 | <ol> | 
 | 3809 |   <li><tt>eq</tt>: equal</li> | 
 | 3810 |   <li><tt>ne</tt>: not equal </li> | 
 | 3811 |   <li><tt>ugt</tt>: unsigned greater than</li> | 
 | 3812 |   <li><tt>uge</tt>: unsigned greater or equal</li> | 
 | 3813 |   <li><tt>ult</tt>: unsigned less than</li> | 
 | 3814 |   <li><tt>ule</tt>: unsigned less or equal</li> | 
 | 3815 |   <li><tt>sgt</tt>: signed greater than</li> | 
 | 3816 |   <li><tt>sge</tt>: signed greater or equal</li> | 
 | 3817 |   <li><tt>slt</tt>: signed less than</li> | 
 | 3818 |   <li><tt>sle</tt>: signed less or equal</li> | 
 | 3819 | </ol> | 
| Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 3820 | <p>The remaining two arguments must be <a href="#t_integer">integer</a> or | 
| Reid Spencer | 350f8aa | 2007-01-04 05:19:58 +0000 | [diff] [blame] | 3821 | <a href="#t_pointer">pointer</a> typed. They must also be identical types.</p> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3822 | <h5>Semantics:</h5> | 
 | 3823 | <p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to  | 
 | 3824 | the condition code given as <tt>cond</tt>. The comparison performed always | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3825 | yields a <a href="#t_primitive">i1</a> result, as follows:  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3826 | <ol> | 
 | 3827 |   <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal,  | 
 | 3828 |   <tt>false</tt> otherwise. No sign interpretation is necessary or performed. | 
 | 3829 |   </li> | 
 | 3830 |   <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal,  | 
 | 3831 |   <tt>false</tt> otherwise. No sign interpretation is necessary or performed. | 
 | 3832 |   <li><tt>ugt</tt>: interprets the operands as unsigned values and yields | 
 | 3833 |   <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li> | 
 | 3834 |   <li><tt>uge</tt>: interprets the operands as unsigned values and yields | 
 | 3835 |   <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> | 
 | 3836 |   <li><tt>ult</tt>: interprets the operands as unsigned values and yields | 
 | 3837 |   <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li> | 
 | 3838 |   <li><tt>ule</tt>: interprets the operands as unsigned values and yields | 
 | 3839 |   <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> | 
 | 3840 |   <li><tt>sgt</tt>: interprets the operands as signed values and yields | 
 | 3841 |   <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li> | 
 | 3842 |   <li><tt>sge</tt>: interprets the operands as signed values and yields | 
 | 3843 |   <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> | 
 | 3844 |   <li><tt>slt</tt>: interprets the operands as signed values and yields | 
 | 3845 |   <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li> | 
 | 3846 |   <li><tt>sle</tt>: interprets the operands as signed values and yields | 
 | 3847 |   <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3848 | </ol> | 
 | 3849 | <p>If the operands are <a href="#t_pointer">pointer</a> typed, the pointer | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3850 | values are compared as if they were integers.</p> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3851 |  | 
 | 3852 | <h5>Example:</h5> | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3853 | <pre>  <result> = icmp eq i32 4, 5          <i>; yields: result=false</i> | 
 | 3854 |   <result> = icmp ne float* %X, %X     <i>; yields: result=false</i> | 
 | 3855 |   <result> = icmp ult i16  4, 5        <i>; yields: result=true</i> | 
 | 3856 |   <result> = icmp sgt i16  4, 5        <i>; yields: result=false</i> | 
 | 3857 |   <result> = icmp ule i16 -4, 5        <i>; yields: result=false</i> | 
 | 3858 |   <result> = icmp sge i16  4, 5        <i>; yields: result=false</i> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3859 | </pre> | 
 | 3860 | </div> | 
 | 3861 |  | 
 | 3862 | <!-- _______________________________________________________________________ --> | 
 | 3863 | <div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a> | 
 | 3864 | </div> | 
 | 3865 | <div class="doc_text"> | 
 | 3866 | <h5>Syntax:</h5> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3867 | <pre>  <result> = fcmp <cond> <ty> <var1>, <var2>     <i>; yields {i1}:result</i> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3868 | </pre> | 
 | 3869 | <h5>Overview:</h5> | 
 | 3870 | <p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison | 
 | 3871 | of its floating point operands.</p> | 
 | 3872 | <h5>Arguments:</h5> | 
 | 3873 | <p>The '<tt>fcmp</tt>' instruction takes three operands. The first operand is | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3874 | the condition code indicating the kind of comparison to perform. It is not | 
 | 3875 | a value, just a keyword. The possible condition code are: | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3876 | <ol> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3877 |   <li><tt>false</tt>: no comparison, always returns false</li> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3878 |   <li><tt>oeq</tt>: ordered and equal</li> | 
 | 3879 |   <li><tt>ogt</tt>: ordered and greater than </li> | 
 | 3880 |   <li><tt>oge</tt>: ordered and greater than or equal</li> | 
 | 3881 |   <li><tt>olt</tt>: ordered and less than </li> | 
 | 3882 |   <li><tt>ole</tt>: ordered and less than or equal</li> | 
 | 3883 |   <li><tt>one</tt>: ordered and not equal</li> | 
 | 3884 |   <li><tt>ord</tt>: ordered (no nans)</li> | 
 | 3885 |   <li><tt>ueq</tt>: unordered or equal</li> | 
 | 3886 |   <li><tt>ugt</tt>: unordered or greater than </li> | 
 | 3887 |   <li><tt>uge</tt>: unordered or greater than or equal</li> | 
 | 3888 |   <li><tt>ult</tt>: unordered or less than </li> | 
 | 3889 |   <li><tt>ule</tt>: unordered or less than or equal</li> | 
 | 3890 |   <li><tt>une</tt>: unordered or not equal</li> | 
 | 3891 |   <li><tt>uno</tt>: unordered (either nans)</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3892 |   <li><tt>true</tt>: no comparison, always returns true</li> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3893 | </ol> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3894 | <p><i>Ordered</i> means that neither operand is a QNAN while | 
| Reid Spencer | 93a4985 | 2006-12-06 07:08:07 +0000 | [diff] [blame] | 3895 | <i>unordered</i> means that either operand may be a QNAN.</p> | 
| Reid Spencer | 350f8aa | 2007-01-04 05:19:58 +0000 | [diff] [blame] | 3896 | <p>The <tt>val1</tt> and <tt>val2</tt> arguments must be | 
 | 3897 | <a href="#t_floating">floating point</a> typed.  They must have identical  | 
 | 3898 | types.</p> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3899 | <h5>Semantics:</h5> | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3900 | <p>The '<tt>fcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> | 
 | 3901 | according to the condition code given as <tt>cond</tt>. The comparison performed  | 
 | 3902 | always yields a <a href="#t_primitive">i1</a> result, as follows:  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3903 | <ol> | 
 | 3904 |   <li><tt>false</tt>: always yields <tt>false</tt>, regardless of operands.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3905 |   <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3906 |   <tt>var1</tt> is equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3907 |   <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3908 |   <tt>var1</tt> is greather than <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3909 |   <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3910 |   <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3911 |   <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3912 |   <tt>var1</tt> is less than <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3913 |   <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3914 |   <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3915 |   <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3916 |   <tt>var1</tt> is not equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3917 |   <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li> | 
 | 3918 |   <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3919 |   <tt>var1</tt> is equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3920 |   <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3921 |   <tt>var1</tt> is greater than <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3922 |   <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3923 |   <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3924 |   <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3925 |   <tt>var1</tt> is less than <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3926 |   <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3927 |   <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3928 |   <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or  | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3929 |   <tt>var1</tt> is not equal to <tt>var2</tt>.</li> | 
| Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3930 |   <li><tt>uno</tt>: yields <tt>true</tt> if either operand is a QNAN.</li> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3931 |   <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li> | 
 | 3932 | </ol> | 
| Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3933 |  | 
 | 3934 | <h5>Example:</h5> | 
 | 3935 | <pre>  <result> = fcmp oeq float 4.0, 5.0    <i>; yields: result=false</i> | 
 | 3936 |   <result> = icmp one float 4.0, 5.0    <i>; yields: result=true</i> | 
 | 3937 |   <result> = icmp olt float 4.0, 5.0    <i>; yields: result=true</i> | 
 | 3938 |   <result> = icmp ueq double 1.0, 2.0   <i>; yields: result=false</i> | 
 | 3939 | </pre> | 
 | 3940 | </div> | 
 | 3941 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3942 | <!-- _______________________________________________________________________ --> | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3943 | <div class="doc_subsubsection"> | 
 | 3944 |   <a name="i_vicmp">'<tt>vicmp</tt>' Instruction</a> | 
 | 3945 | </div> | 
 | 3946 | <div class="doc_text"> | 
 | 3947 | <h5>Syntax:</h5> | 
 | 3948 | <pre>  <result> = vicmp <cond> <ty> <var1>, <var2>   <i>; yields {ty}:result</i> | 
 | 3949 | </pre> | 
 | 3950 | <h5>Overview:</h5> | 
 | 3951 | <p>The '<tt>vicmp</tt>' instruction returns an integer vector value based on | 
 | 3952 | element-wise comparison of its two integer vector operands.</p> | 
 | 3953 | <h5>Arguments:</h5> | 
 | 3954 | <p>The '<tt>vicmp</tt>' instruction takes three operands. The first operand is | 
 | 3955 | the condition code indicating the kind of comparison to perform. It is not | 
 | 3956 | a value, just a keyword. The possible condition code are: | 
 | 3957 | <ol> | 
 | 3958 |   <li><tt>eq</tt>: equal</li> | 
 | 3959 |   <li><tt>ne</tt>: not equal </li> | 
 | 3960 |   <li><tt>ugt</tt>: unsigned greater than</li> | 
 | 3961 |   <li><tt>uge</tt>: unsigned greater or equal</li> | 
 | 3962 |   <li><tt>ult</tt>: unsigned less than</li> | 
 | 3963 |   <li><tt>ule</tt>: unsigned less or equal</li> | 
 | 3964 |   <li><tt>sgt</tt>: signed greater than</li> | 
 | 3965 |   <li><tt>sge</tt>: signed greater or equal</li> | 
 | 3966 |   <li><tt>slt</tt>: signed less than</li> | 
 | 3967 |   <li><tt>sle</tt>: signed less or equal</li> | 
 | 3968 | </ol> | 
 | 3969 | <p>The remaining two arguments must be <a href="#t_vector">vector</a> of  | 
 | 3970 | <a href="#t_integer">integer</a> typed. They must also be identical types.</p> | 
 | 3971 | <h5>Semantics:</h5> | 
 | 3972 | <p>The '<tt>vicmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> | 
 | 3973 | according to the condition code given as <tt>cond</tt>. The comparison yields a  | 
 | 3974 | <a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, of | 
 | 3975 | identical type as the values being compared.  The most significant bit in each | 
 | 3976 | element is 1 if the element-wise comparison evaluates to true, and is 0 | 
 | 3977 | otherwise.  All other bits of the result are undefined.  The condition codes | 
 | 3978 | are evaluated identically to the <a href="#i_icmp">'<tt>icmp</tt>' | 
 | 3979 | instruction</a>. | 
 | 3980 |  | 
 | 3981 | <h5>Example:</h5> | 
 | 3982 | <pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3983 |   <result> = vicmp eq <2 x i32> < i32 4, i32 0>, < i32 5, i32 0>   <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i> | 
 | 3984 |   <result> = vicmp ult <2 x i8 > < i8 1, i8 2>, < i8 2, i8 2 >        <i>; yields: result=<2 x i8> < i8 -1, i8 0 ></i> | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3985 | </pre> | 
 | 3986 | </div> | 
 | 3987 |  | 
 | 3988 | <!-- _______________________________________________________________________ --> | 
 | 3989 | <div class="doc_subsubsection"> | 
 | 3990 |   <a name="i_vfcmp">'<tt>vfcmp</tt>' Instruction</a> | 
 | 3991 | </div> | 
 | 3992 | <div class="doc_text"> | 
 | 3993 | <h5>Syntax:</h5> | 
 | 3994 | <pre>  <result> = vfcmp <cond> <ty> <var1>, <var2></pre> | 
 | 3995 | <h5>Overview:</h5> | 
 | 3996 | <p>The '<tt>vfcmp</tt>' instruction returns an integer vector value based on | 
 | 3997 | element-wise comparison of its two floating point vector operands.  The output | 
 | 3998 | elements have the same width as the input elements.</p> | 
 | 3999 | <h5>Arguments:</h5> | 
 | 4000 | <p>The '<tt>vfcmp</tt>' instruction takes three operands. The first operand is | 
 | 4001 | the condition code indicating the kind of comparison to perform. It is not | 
 | 4002 | a value, just a keyword. The possible condition code are: | 
 | 4003 | <ol> | 
 | 4004 |   <li><tt>false</tt>: no comparison, always returns false</li> | 
 | 4005 |   <li><tt>oeq</tt>: ordered and equal</li> | 
 | 4006 |   <li><tt>ogt</tt>: ordered and greater than </li> | 
 | 4007 |   <li><tt>oge</tt>: ordered and greater than or equal</li> | 
 | 4008 |   <li><tt>olt</tt>: ordered and less than </li> | 
 | 4009 |   <li><tt>ole</tt>: ordered and less than or equal</li> | 
 | 4010 |   <li><tt>one</tt>: ordered and not equal</li> | 
 | 4011 |   <li><tt>ord</tt>: ordered (no nans)</li> | 
 | 4012 |   <li><tt>ueq</tt>: unordered or equal</li> | 
 | 4013 |   <li><tt>ugt</tt>: unordered or greater than </li> | 
 | 4014 |   <li><tt>uge</tt>: unordered or greater than or equal</li> | 
 | 4015 |   <li><tt>ult</tt>: unordered or less than </li> | 
 | 4016 |   <li><tt>ule</tt>: unordered or less than or equal</li> | 
 | 4017 |   <li><tt>une</tt>: unordered or not equal</li> | 
 | 4018 |   <li><tt>uno</tt>: unordered (either nans)</li> | 
 | 4019 |   <li><tt>true</tt>: no comparison, always returns true</li> | 
 | 4020 | </ol> | 
 | 4021 | <p>The remaining two arguments must be <a href="#t_vector">vector</a> of  | 
 | 4022 | <a href="#t_floating">floating point</a> typed. They must also be identical | 
 | 4023 | types.</p> | 
 | 4024 | <h5>Semantics:</h5> | 
 | 4025 | <p>The '<tt>vfcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> | 
 | 4026 | according to  the condition code given as <tt>cond</tt>. The comparison yields a  | 
 | 4027 | <a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, with | 
 | 4028 | an identical number of elements as the values being compared, and each element | 
 | 4029 | having identical with to the width of the floating point elements. The most  | 
 | 4030 | significant bit in each element is 1 if the element-wise comparison evaluates to | 
 | 4031 | true, and is 0 otherwise.  All other bits of the result are undefined.  The | 
 | 4032 | condition codes are evaluated identically to the  | 
 | 4033 | <a href="#i_fcmp">'<tt>fcmp</tt>' instruction</a>. | 
 | 4034 |  | 
 | 4035 | <h5>Example:</h5> | 
 | 4036 | <pre> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4037 |   <result> = vfcmp oeq <2 x float> < float 4, float 0 >, < float 5, float 0 >       <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i> | 
 | 4038 |   <result> = vfcmp ult <2 x double> < double 1, double 2 >, < double 2, double 2>   <i>; yields: result=<2 x i64> < i64 -1, i64 0 ></i> | 
| Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 4039 | </pre> | 
 | 4040 | </div> | 
 | 4041 |  | 
 | 4042 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4043 | <div class="doc_subsubsection"> | 
 | 4044 |   <a name="i_phi">'<tt>phi</tt>' Instruction</a> | 
 | 4045 | </div> | 
 | 4046 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4047 | <div class="doc_text"> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4048 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4049 | <h5>Syntax:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4050 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4051 | <pre>  <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> | 
 | 4052 | <h5>Overview:</h5> | 
 | 4053 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in | 
 | 4054 | the SSA graph representing the function.</p> | 
 | 4055 | <h5>Arguments:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4056 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4057 | <p>The type of the incoming values is specified with the first type | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4058 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs | 
 | 4059 | as arguments, with one pair for each predecessor basic block of the | 
 | 4060 | current block.  Only values of <a href="#t_firstclass">first class</a> | 
 | 4061 | type may be used as the value arguments to the PHI node.  Only labels | 
 | 4062 | may be used as the label arguments.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4063 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4064 | <p>There must be no non-phi instructions between the start of a basic | 
 | 4065 | block and the PHI instructions: i.e. PHI instructions must be first in | 
 | 4066 | a basic block.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4067 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4068 | <h5>Semantics:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4069 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4070 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value | 
 | 4071 | specified by the pair corresponding to the predecessor basic block that executed | 
 | 4072 | just prior to the current block.</p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4073 |  | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4074 | <h5>Example:</h5> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4075 | <pre> | 
 | 4076 | Loop:       ; Infinite loop that counts from 0 on up... | 
 | 4077 |   %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] | 
 | 4078 |   %nextindvar = add i32 %indvar, 1 | 
 | 4079 |   br label %Loop | 
 | 4080 | </pre> | 
| Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4081 | </div> | 
 | 4082 |  | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4083 | <!-- _______________________________________________________________________ --> | 
 | 4084 | <div class="doc_subsubsection"> | 
 | 4085 |    <a name="i_select">'<tt>select</tt>' Instruction</a> | 
 | 4086 | </div> | 
 | 4087 |  | 
 | 4088 | <div class="doc_text"> | 
 | 4089 |  | 
 | 4090 | <h5>Syntax:</h5> | 
 | 4091 |  | 
 | 4092 | <pre> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 4093 |   <result> = select i1 <cond>, <ty> <val1>, <ty> <val2>             <i>; yields ty</i> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4094 | </pre> | 
 | 4095 |  | 
 | 4096 | <h5>Overview:</h5> | 
 | 4097 |  | 
 | 4098 | <p> | 
 | 4099 | The '<tt>select</tt>' instruction is used to choose one value based on a | 
 | 4100 | condition, without branching. | 
 | 4101 | </p> | 
 | 4102 |  | 
 | 4103 |  | 
 | 4104 | <h5>Arguments:</h5> | 
 | 4105 |  | 
 | 4106 | <p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4107 | The '<tt>select</tt>' instruction requires an 'i1' value indicating the | 
 | 4108 | condition, and two values of the same <a href="#t_firstclass">first class</a> | 
 | 4109 | type.  If the val1/val2 are vectors, the entire vectors are selected, not | 
 | 4110 | individual elements. | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4111 | </p> | 
 | 4112 |  | 
 | 4113 | <h5>Semantics:</h5> | 
 | 4114 |  | 
 | 4115 | <p> | 
| Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4116 | If the i1 condition evaluates is 1, the instruction returns the first | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4117 | value argument; otherwise, it returns the second value argument. | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4118 | </p> | 
 | 4119 |  | 
 | 4120 | <h5>Example:</h5> | 
 | 4121 |  | 
 | 4122 | <pre> | 
| Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 4123 |   %X = select i1 true, i8 17, i8 42          <i>; yields i8:17</i> | 
| Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4124 | </pre> | 
 | 4125 | </div> | 
 | 4126 |  | 
| Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 4127 |  | 
 | 4128 | <!-- _______________________________________________________________________ --> | 
 | 4129 | <div class="doc_subsubsection"> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4130 |   <a name="i_call">'<tt>call</tt>' Instruction</a> | 
 | 4131 | </div> | 
 | 4132 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4133 | <div class="doc_text"> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4134 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4135 | <h5>Syntax:</h5> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4136 | <pre> | 
| Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 4137 |   <result> = [tail] call [<a href="#callingconv">cconv</a>] <ty> [<fnty>*] <fnptrval>(<param list>) | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4138 | </pre> | 
 | 4139 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4140 | <h5>Overview:</h5> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4141 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4142 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4143 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4144 | <h5>Arguments:</h5> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4145 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4146 | <p>This instruction requires several arguments:</p> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4147 |  | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4148 | <ol> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4149 |   <li> | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4150 |     <p>The optional "tail" marker indicates whether the callee function accesses | 
 | 4151 |     any allocas or varargs in the caller.  If the "tail" marker is present, the | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4152 |     function call is eligible for tail call optimization.  Note that calls may | 
 | 4153 |     be marked "tail" even if they do not occur before a <a | 
 | 4154 |     href="#i_ret"><tt>ret</tt></a> instruction. | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4155 |   </li> | 
 | 4156 |   <li> | 
| Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 4157 |     <p>The optional "cconv" marker indicates which <a href="#callingconv">calling | 
| Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4158 |     convention</a> the call should use.  If none is specified, the call defaults | 
 | 4159 |     to using C calling conventions. | 
 | 4160 |   </li> | 
 | 4161 |   <li> | 
| Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 4162 |     <p>'<tt>ty</tt>': the type of the call instruction itself which is also | 
 | 4163 |     the type of the return value.  Functions that return no value are marked | 
 | 4164 |     <tt><a href="#t_void">void</a></tt>.</p> | 
 | 4165 |   </li> | 
 | 4166 |   <li> | 
 | 4167 |     <p>'<tt>fnty</tt>': shall be the signature of the pointer to function | 
 | 4168 |     value being invoked.  The argument types must match the types implied by | 
 | 4169 |     this signature.  This type can be omitted if the function is not varargs | 
 | 4170 |     and if the function type does not return a pointer to a function.</p> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4171 |   </li> | 
 | 4172 |   <li> | 
 | 4173 |     <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to | 
 | 4174 |     be invoked. In most cases, this is a direct function invocation, but | 
 | 4175 |     indirect <tt>call</tt>s are just as possible, calling an arbitrary pointer | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4176 |     to function value.</p> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4177 |   </li> | 
 | 4178 |   <li> | 
 | 4179 |     <p>'<tt>function args</tt>': argument list whose types match the | 
| Reid Spencer | a7e302a | 2005-05-01 22:22:57 +0000 | [diff] [blame] | 4180 |     function signature argument types. All arguments must be of  | 
 | 4181 |     <a href="#t_firstclass">first class</a> type. If the function signature  | 
 | 4182 |     indicates the function accepts a variable number of arguments, the extra  | 
 | 4183 |     arguments can be specified.</p> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4184 |   </li> | 
| Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4185 | </ol> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4186 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4187 | <h5>Semantics:</h5> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4188 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4189 | <p>The '<tt>call</tt>' instruction is used to cause control flow to | 
 | 4190 | transfer to a specified function, with its incoming arguments bound to | 
 | 4191 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' | 
 | 4192 | instruction in the called function, control flow continues with the | 
 | 4193 | instruction after the function call, and the return value of the | 
| Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 4194 | function is bound to the result argument.  If the callee returns multiple  | 
 | 4195 | values then the return values of the function are only accessible through  | 
 | 4196 | the '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4197 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4198 | <h5>Example:</h5> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4199 |  | 
 | 4200 | <pre> | 
| Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 4201 |   %retval = call i32 @test(i32 %argc) | 
| Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 4202 |   call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42)      <i>; yields i32</i> | 
 | 4203 |   %X = tail call i32 @foo()                                    <i>; yields i32</i> | 
 | 4204 |   %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo()  <i>; yields i32</i> | 
 | 4205 |   call void %foo(i8 97 signext) | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4206 |  | 
 | 4207 |   %struct.A = type { i32, i8 } | 
| Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 4208 |   %r = call %struct.A @foo()                     <i>; yields { 32, i8 }</i> | 
 | 4209 |   %gr = getresult %struct.A %r, 0                <i>; yields i32</i> | 
 | 4210 |   %gr1 = getresult %struct.A %r, 1               <i>; yields i8</i> | 
| Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4211 | </pre> | 
 | 4212 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4213 | </div> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4214 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4215 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4216 | <div class="doc_subsubsection"> | 
| Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 4217 |   <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4218 | </div> | 
 | 4219 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4220 | <div class="doc_text"> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4221 |  | 
| Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4222 | <h5>Syntax:</h5> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4223 |  | 
 | 4224 | <pre> | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4225 |   <resultval> = va_arg <va_list*> <arglist>, <argty> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4226 | </pre> | 
 | 4227 |  | 
| Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4228 | <h5>Overview:</h5> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4229 |  | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4230 | <p>The '<tt>va_arg</tt>' instruction is used to access arguments passed through | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4231 | the "variable argument" area of a function call.  It is used to implement the | 
 | 4232 | <tt>va_arg</tt> macro in C.</p> | 
 | 4233 |  | 
| Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4234 | <h5>Arguments:</h5> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4235 |  | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4236 | <p>This instruction takes a <tt>va_list*</tt> value and the type of | 
 | 4237 | the argument. It returns a value of the specified argument type and | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4238 | increments the <tt>va_list</tt> to point to the next argument.  The | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4239 | actual type of <tt>va_list</tt> is target specific.</p> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4240 |  | 
| Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4241 | <h5>Semantics:</h5> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4242 |  | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4243 | <p>The '<tt>va_arg</tt>' instruction loads an argument of the specified | 
 | 4244 | type from the specified <tt>va_list</tt> and causes the | 
 | 4245 | <tt>va_list</tt> to point to the next argument.  For more information, | 
 | 4246 | see the variable argument handling <a href="#int_varargs">Intrinsic | 
 | 4247 | Functions</a>.</p> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4248 |  | 
 | 4249 | <p>It is legal for this instruction to be called in a function which does not | 
 | 4250 | take a variable number of arguments, for example, the <tt>vfprintf</tt> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4251 | function.</p> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4252 |  | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4253 | <p><tt>va_arg</tt> is an LLVM instruction instead of an <a | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4254 | href="#intrinsics">intrinsic function</a> because it takes a type as an | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4255 | argument.</p> | 
 | 4256 |  | 
| Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4257 | <h5>Example:</h5> | 
| Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4258 |  | 
 | 4259 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> | 
 | 4260 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4261 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4262 |  | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4263 | <!-- _______________________________________________________________________ --> | 
 | 4264 | <div class="doc_subsubsection"> | 
 | 4265 |   <a name="i_getresult">'<tt>getresult</tt>' Instruction</a> | 
 | 4266 | </div> | 
 | 4267 |  | 
 | 4268 | <div class="doc_text"> | 
 | 4269 |  | 
 | 4270 | <h5>Syntax:</h5> | 
 | 4271 | <pre> | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4272 |   <resultval> = getresult <type> <retval>, <index> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4273 | </pre> | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4274 |  | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4275 | <h5>Overview:</h5> | 
 | 4276 |  | 
 | 4277 | <p> The '<tt>getresult</tt>' instruction is used to extract individual values | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4278 | from a '<tt><a href="#i_call">call</a></tt>'  | 
 | 4279 | or '<tt><a href="#i_invoke">invoke</a></tt>' instruction that returns multiple | 
 | 4280 | results.</p> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4281 |  | 
 | 4282 | <h5>Arguments:</h5> | 
 | 4283 |  | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4284 | <p>The '<tt>getresult</tt>' instruction takes a call or invoke value as its  | 
| Chris Lattner | 1c406d7 | 2008-04-23 04:06:52 +0000 | [diff] [blame] | 4285 | first argument, or an undef value.  The value must have <a  | 
 | 4286 | href="#t_struct">structure type</a>.  The second argument is a constant  | 
 | 4287 | unsigned index value which must be in range for the number of values returned  | 
 | 4288 | by the call.</p> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4289 |  | 
 | 4290 | <h5>Semantics:</h5> | 
 | 4291 |  | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4292 | <p>The '<tt>getresult</tt>' instruction extracts the element identified by | 
 | 4293 | '<tt>index</tt>' from the aggregate value.</p> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4294 |  | 
 | 4295 | <h5>Example:</h5> | 
 | 4296 |  | 
 | 4297 | <pre> | 
 | 4298 |   %struct.A = type { i32, i8 } | 
 | 4299 |  | 
 | 4300 |   %r = call %struct.A @foo() | 
| Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4301 |   %gr = getresult %struct.A %r, 0    <i>; yields i32:%gr</i> | 
 | 4302 |   %gr1 = getresult %struct.A %r, 1   <i>; yields i8:%gr1</i> | 
| Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4303 |   add i32 %gr, 42 | 
 | 4304 |   add i8 %gr1, 41 | 
 | 4305 | </pre> | 
 | 4306 |  | 
 | 4307 | </div> | 
 | 4308 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4309 | <!-- *********************************************************************** --> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4310 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> | 
 | 4311 | <!-- *********************************************************************** --> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4312 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4313 | <div class="doc_text"> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4314 |  | 
 | 4315 | <p>LLVM supports the notion of an "intrinsic function".  These functions have | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4316 | well known names and semantics and are required to follow certain restrictions. | 
 | 4317 | Overall, these intrinsics represent an extension mechanism for the LLVM  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4318 | language that does not require changing all of the transformations in LLVM when  | 
| Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 4319 | adding to the language (or the bitcode reader/writer, the parser, etc...).</p> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4320 |  | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4321 | <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4322 | prefix is reserved in LLVM for intrinsic names; thus, function names may not | 
 | 4323 | begin with this prefix.  Intrinsic functions must always be external functions: | 
 | 4324 | you cannot define the body of intrinsic functions.  Intrinsic functions may | 
 | 4325 | only be used in call or invoke instructions: it is illegal to take the address | 
 | 4326 | of an intrinsic function.  Additionally, because intrinsic functions are part | 
 | 4327 | of the LLVM language, it is required if any are added that they be documented | 
 | 4328 | here.</p> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4329 |  | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4330 | <p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents  | 
 | 4331 | a family of functions that perform the same operation but on different data  | 
 | 4332 | types. Because LLVM can represent over 8 million different integer types,  | 
 | 4333 | overloading is used commonly to allow an intrinsic function to operate on any  | 
 | 4334 | integer type. One or more of the argument types or the result type can be  | 
 | 4335 | overloaded to accept any integer type. Argument types may also be defined as  | 
 | 4336 | exactly matching a previous argument's type or the result type. This allows an  | 
 | 4337 | intrinsic function which accepts multiple arguments, but needs all of them to  | 
 | 4338 | be of the same type, to only be overloaded with respect to a single argument or  | 
 | 4339 | the result.</p> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4340 |  | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4341 | <p>Overloaded intrinsics will have the names of its overloaded argument types  | 
 | 4342 | encoded into its function name, each preceded by a period. Only those types  | 
 | 4343 | which are overloaded result in a name suffix. Arguments whose type is matched  | 
 | 4344 | against another type do not. For example, the <tt>llvm.ctpop</tt> function can  | 
 | 4345 | take an integer of any width and returns an integer of exactly the same integer  | 
 | 4346 | width. This leads to a family of functions such as | 
 | 4347 | <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>. | 
 | 4348 | Only one type, the return type, is overloaded, and only one type suffix is  | 
 | 4349 | required. Because the argument's type is matched against the return type, it  | 
 | 4350 | does not require its own name suffix.</p> | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4351 |  | 
 | 4352 | <p>To learn how to add an intrinsic function, please see the  | 
 | 4353 | <a href="ExtendingLLVM.html">Extending LLVM Guide</a>. | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4354 | </p> | 
 | 4355 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4356 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4357 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4358 | <!-- ======================================================================= --> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4359 | <div class="doc_subsection"> | 
 | 4360 |   <a name="int_varargs">Variable Argument Handling Intrinsics</a> | 
 | 4361 | </div> | 
 | 4362 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4363 | <div class="doc_text"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4364 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4365 | <p>Variable argument support is defined in LLVM with the <a | 
| Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 4366 |  href="#i_va_arg"><tt>va_arg</tt></a> instruction and these three | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4367 | intrinsic functions.  These functions are related to the similarly | 
 | 4368 | named macros defined in the <tt><stdarg.h></tt> header file.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4369 |  | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4370 | <p>All of these functions operate on arguments that use a | 
 | 4371 | target-specific value type "<tt>va_list</tt>".  The LLVM assembly | 
 | 4372 | language reference manual does not define what this type is, so all | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4373 | transformations should be prepared to handle these functions regardless of | 
 | 4374 | the type used.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4375 |  | 
| Chris Lattner | 374ab30 | 2006-05-15 17:26:46 +0000 | [diff] [blame] | 4376 | <p>This example shows how the <a href="#i_va_arg"><tt>va_arg</tt></a> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4377 | instruction and the variable argument handling intrinsic functions are | 
 | 4378 | used.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4379 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4380 | <div class="doc_code"> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4381 | <pre> | 
| Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4382 | define i32 @test(i32 %X, ...) { | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4383 |   ; Initialize variable argument processing | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4384 |   %ap = alloca i8* | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4385 |   %ap2 = bitcast i8** %ap to i8* | 
| Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4386 |   call void @llvm.va_start(i8* %ap2) | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4387 |  | 
 | 4388 |   ; Read a single integer argument | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4389 |   %tmp = va_arg i8** %ap, i32 | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4390 |  | 
 | 4391 |   ; Demonstrate usage of llvm.va_copy and llvm.va_end | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4392 |   %aq = alloca i8* | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4393 |   %aq2 = bitcast i8** %aq to i8* | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4394 |   call void @llvm.va_copy(i8* %aq2, i8* %ap2) | 
| Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4395 |   call void @llvm.va_end(i8* %aq2) | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4396 |  | 
 | 4397 |   ; Stop processing of arguments. | 
| Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4398 |   call void @llvm.va_end(i8* %ap2) | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4399 |   ret i32 %tmp | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4400 | } | 
| Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4401 |  | 
 | 4402 | declare void @llvm.va_start(i8*) | 
 | 4403 | declare void @llvm.va_copy(i8*, i8*) | 
 | 4404 | declare void @llvm.va_end(i8*) | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4405 | </pre> | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4406 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4407 |  | 
| Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4408 | </div> | 
 | 4409 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4410 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4411 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4412 |   <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4413 | </div> | 
 | 4414 |  | 
 | 4415 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4416 | <div class="doc_text"> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4417 | <h5>Syntax:</h5> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4418 | <pre>  declare void %llvm.va_start(i8* <arglist>)<br></pre> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4419 | <h5>Overview:</h5> | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4420 | <P>The '<tt>llvm.va_start</tt>' intrinsic initializes | 
 | 4421 | <tt>*<arglist></tt> for subsequent use by <tt><a | 
 | 4422 | href="#i_va_arg">va_arg</a></tt>.</p> | 
 | 4423 |  | 
 | 4424 | <h5>Arguments:</h5> | 
 | 4425 |  | 
 | 4426 | <P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p> | 
 | 4427 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4428 | <h5>Semantics:</h5> | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4429 |  | 
 | 4430 | <P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> | 
 | 4431 | macro available in C.  In a target-dependent way, it initializes the | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4432 | <tt>va_list</tt> element to which the argument points, so that the next call to | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4433 | <tt>va_arg</tt> will produce the first variable argument passed to the function. | 
 | 4434 | Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4435 | last argument of the function as the compiler can figure that out.</p> | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4436 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4437 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4438 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4439 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4440 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4441 |  <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4442 | </div> | 
 | 4443 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4444 | <div class="doc_text"> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4445 | <h5>Syntax:</h5> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4446 | <pre>  declare void @llvm.va_end(i8* <arglist>)<br></pre> | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4447 | <h5>Overview:</h5> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4448 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4449 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*<arglist></tt>, | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4450 | which has been initialized previously with <tt><a href="#int_va_start">llvm.va_start</a></tt> | 
| Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4451 | or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4452 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4453 | <h5>Arguments:</h5> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4454 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4455 | <p>The argument is a pointer to a <tt>va_list</tt> to destroy.</p> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4456 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4457 | <h5>Semantics:</h5> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4458 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4459 | <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt> | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4460 | macro available in C.  In a target-dependent way, it destroys the | 
 | 4461 | <tt>va_list</tt> element to which the argument points.  Calls to <a | 
 | 4462 | href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy"> | 
 | 4463 | <tt>llvm.va_copy</tt></a> must be matched exactly with calls to | 
 | 4464 | <tt>llvm.va_end</tt>.</p> | 
| Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4465 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4466 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4467 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4468 | <!-- _______________________________________________________________________ --> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4469 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4470 |   <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4471 | </div> | 
 | 4472 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4473 | <div class="doc_text"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4474 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4475 | <h5>Syntax:</h5> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4476 |  | 
 | 4477 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4478 |   declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4479 | </pre> | 
 | 4480 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4481 | <h5>Overview:</h5> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4482 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4483 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position | 
 | 4484 | from the source argument list to the destination argument list.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4485 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4486 | <h5>Arguments:</h5> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4487 |  | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4488 | <p>The first argument is a pointer to a <tt>va_list</tt> element to initialize. | 
| Andrew Lenharth | d0a4c62 | 2005-06-22 20:38:11 +0000 | [diff] [blame] | 4489 | The second argument is a pointer to a <tt>va_list</tt> element to copy from.</p> | 
| Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4490 |  | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4491 |  | 
| Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4492 | <h5>Semantics:</h5> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4493 |  | 
| Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4494 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> | 
 | 4495 | macro available in C.  In a target-dependent way, it copies the source | 
 | 4496 | <tt>va_list</tt> element into the destination <tt>va_list</tt> element.  This | 
 | 4497 | intrinsic is necessary because the <tt><a href="#int_va_start"> | 
 | 4498 | llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for | 
 | 4499 | example, memory allocation.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4500 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4501 | </div> | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4502 |  | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4503 | <!-- ======================================================================= --> | 
 | 4504 | <div class="doc_subsection"> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4505 |   <a name="int_gc">Accurate Garbage Collection Intrinsics</a> | 
 | 4506 | </div> | 
 | 4507 |  | 
 | 4508 | <div class="doc_text"> | 
 | 4509 |  | 
 | 4510 | <p> | 
 | 4511 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage | 
 | 4512 | Collection</a> requires the implementation and generation of these intrinsics. | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4513 | These intrinsics allow identification of <a href="#int_gcroot">GC roots on the | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4514 | stack</a>, as well as garbage collector implementations that require <a | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4515 | href="#int_gcread">read</a> and <a href="#int_gcwrite">write</a> barriers. | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4516 | Front-ends for type-safe garbage collected languages should generate these | 
 | 4517 | intrinsics to make use of the LLVM garbage collectors.  For more details, see <a | 
 | 4518 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. | 
 | 4519 | </p> | 
| Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 4520 |  | 
 | 4521 | <p>The garbage collection intrinsics only operate on objects in the generic  | 
 | 4522 | 	address space (address space zero).</p> | 
 | 4523 |  | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4524 | </div> | 
 | 4525 |  | 
 | 4526 | <!-- _______________________________________________________________________ --> | 
 | 4527 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4528 |   <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4529 | </div> | 
 | 4530 |  | 
 | 4531 | <div class="doc_text"> | 
 | 4532 |  | 
 | 4533 | <h5>Syntax:</h5> | 
 | 4534 |  | 
 | 4535 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4536 |   declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4537 | </pre> | 
 | 4538 |  | 
 | 4539 | <h5>Overview:</h5> | 
 | 4540 |  | 
| John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 4541 | <p>The '<tt>llvm.gcroot</tt>' intrinsic declares the existence of a GC root to | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4542 | the code generator, and allows some metadata to be associated with it.</p> | 
 | 4543 |  | 
 | 4544 | <h5>Arguments:</h5> | 
 | 4545 |  | 
 | 4546 | <p>The first argument specifies the address of a stack object that contains the | 
 | 4547 | root pointer.  The second pointer (which must be either a constant or a global | 
 | 4548 | value address) contains the meta-data to be associated with the root.</p> | 
 | 4549 |  | 
 | 4550 | <h5>Semantics:</h5> | 
 | 4551 |  | 
| Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 4552 | <p>At runtime, a call to this intrinsic stores a null pointer into the "ptrloc" | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4553 | location.  At compile-time, the code generator generates information to allow | 
| Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4554 | the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>' | 
 | 4555 | intrinsic may only be used in a function which <a href="#gc">specifies a GC | 
 | 4556 | algorithm</a>.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4557 |  | 
 | 4558 | </div> | 
 | 4559 |  | 
 | 4560 |  | 
 | 4561 | <!-- _______________________________________________________________________ --> | 
 | 4562 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4563 |   <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4564 | </div> | 
 | 4565 |  | 
 | 4566 | <div class="doc_text"> | 
 | 4567 |  | 
 | 4568 | <h5>Syntax:</h5> | 
 | 4569 |  | 
 | 4570 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4571 |   declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4572 | </pre> | 
 | 4573 |  | 
 | 4574 | <h5>Overview:</h5> | 
 | 4575 |  | 
 | 4576 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap | 
 | 4577 | locations, allowing garbage collector implementations that require read | 
 | 4578 | barriers.</p> | 
 | 4579 |  | 
 | 4580 | <h5>Arguments:</h5> | 
 | 4581 |  | 
| Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 4582 | <p>The second argument is the address to read from, which should be an address | 
 | 4583 | allocated from the garbage collector.  The first object is a pointer to the  | 
 | 4584 | start of the referenced object, if needed by the language runtime (otherwise | 
 | 4585 | null).</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4586 |  | 
 | 4587 | <h5>Semantics:</h5> | 
 | 4588 |  | 
 | 4589 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load | 
 | 4590 | instruction, but may be replaced with substantially more complex code by the | 
| Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4591 | garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic | 
 | 4592 | may only be used in a function which <a href="#gc">specifies a GC | 
 | 4593 | algorithm</a>.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4594 |  | 
 | 4595 | </div> | 
 | 4596 |  | 
 | 4597 |  | 
 | 4598 | <!-- _______________________________________________________________________ --> | 
 | 4599 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4600 |   <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4601 | </div> | 
 | 4602 |  | 
 | 4603 | <div class="doc_text"> | 
 | 4604 |  | 
 | 4605 | <h5>Syntax:</h5> | 
 | 4606 |  | 
 | 4607 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4608 |   declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4609 | </pre> | 
 | 4610 |  | 
 | 4611 | <h5>Overview:</h5> | 
 | 4612 |  | 
 | 4613 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap | 
 | 4614 | locations, allowing garbage collector implementations that require write | 
 | 4615 | barriers (such as generational or reference counting collectors).</p> | 
 | 4616 |  | 
 | 4617 | <h5>Arguments:</h5> | 
 | 4618 |  | 
| Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 4619 | <p>The first argument is the reference to store, the second is the start of the | 
 | 4620 | object to store it to, and the third is the address of the field of Obj to  | 
 | 4621 | store to.  If the runtime does not require a pointer to the object, Obj may be | 
 | 4622 | null.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4623 |  | 
 | 4624 | <h5>Semantics:</h5> | 
 | 4625 |  | 
 | 4626 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store | 
 | 4627 | instruction, but may be replaced with substantially more complex code by the | 
| Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4628 | garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic | 
 | 4629 | may only be used in a function which <a href="#gc">specifies a GC | 
 | 4630 | algorithm</a>.</p> | 
| Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4631 |  | 
 | 4632 | </div> | 
 | 4633 |  | 
 | 4634 |  | 
 | 4635 |  | 
 | 4636 | <!-- ======================================================================= --> | 
 | 4637 | <div class="doc_subsection"> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4638 |   <a name="int_codegen">Code Generator Intrinsics</a> | 
 | 4639 | </div> | 
 | 4640 |  | 
 | 4641 | <div class="doc_text"> | 
 | 4642 | <p> | 
 | 4643 | These intrinsics are provided by LLVM to expose special features that may only | 
 | 4644 | be implemented with code generator support. | 
 | 4645 | </p> | 
 | 4646 |  | 
 | 4647 | </div> | 
 | 4648 |  | 
 | 4649 | <!-- _______________________________________________________________________ --> | 
 | 4650 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4651 |   <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4652 | </div> | 
 | 4653 |  | 
 | 4654 | <div class="doc_text"> | 
 | 4655 |  | 
 | 4656 | <h5>Syntax:</h5> | 
 | 4657 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4658 |   declare i8  *@llvm.returnaddress(i32 <level>) | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4659 | </pre> | 
 | 4660 |  | 
 | 4661 | <h5>Overview:</h5> | 
 | 4662 |  | 
 | 4663 | <p> | 
| Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 4664 | The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a  | 
 | 4665 | target-specific value indicating the return address of the current function  | 
 | 4666 | or one of its callers. | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4667 | </p> | 
 | 4668 |  | 
 | 4669 | <h5>Arguments:</h5> | 
 | 4670 |  | 
 | 4671 | <p> | 
 | 4672 | The argument to this intrinsic indicates which function to return the address | 
 | 4673 | for.  Zero indicates the calling function, one indicates its caller, etc.  The | 
 | 4674 | argument is <b>required</b> to be a constant integer value. | 
 | 4675 | </p> | 
 | 4676 |  | 
 | 4677 | <h5>Semantics:</h5> | 
 | 4678 |  | 
 | 4679 | <p> | 
 | 4680 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating | 
 | 4681 | the return address of the specified call frame, or zero if it cannot be | 
 | 4682 | identified.  The value returned by this intrinsic is likely to be incorrect or 0 | 
 | 4683 | for arguments other than zero, so it should only be used for debugging purposes. | 
 | 4684 | </p> | 
 | 4685 |  | 
 | 4686 | <p> | 
 | 4687 | Note that calling this intrinsic does not prevent function inlining or other | 
| Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 4688 | aggressive transformations, so the value returned may not be that of the obvious | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4689 | source-language caller. | 
 | 4690 | </p> | 
 | 4691 | </div> | 
 | 4692 |  | 
 | 4693 |  | 
 | 4694 | <!-- _______________________________________________________________________ --> | 
 | 4695 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4696 |   <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4697 | </div> | 
 | 4698 |  | 
 | 4699 | <div class="doc_text"> | 
 | 4700 |  | 
 | 4701 | <h5>Syntax:</h5> | 
 | 4702 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4703 |   declare i8 *@llvm.frameaddress(i32 <level>) | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4704 | </pre> | 
 | 4705 |  | 
 | 4706 | <h5>Overview:</h5> | 
 | 4707 |  | 
 | 4708 | <p> | 
| Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 4709 | The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the  | 
 | 4710 | target-specific frame pointer value for the specified stack frame. | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4711 | </p> | 
 | 4712 |  | 
 | 4713 | <h5>Arguments:</h5> | 
 | 4714 |  | 
 | 4715 | <p> | 
 | 4716 | The argument to this intrinsic indicates which function to return the frame | 
 | 4717 | pointer for.  Zero indicates the calling function, one indicates its caller, | 
 | 4718 | etc.  The argument is <b>required</b> to be a constant integer value. | 
 | 4719 | </p> | 
 | 4720 |  | 
 | 4721 | <h5>Semantics:</h5> | 
 | 4722 |  | 
 | 4723 | <p> | 
 | 4724 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating | 
 | 4725 | the frame address of the specified call frame, or zero if it cannot be | 
 | 4726 | identified.  The value returned by this intrinsic is likely to be incorrect or 0 | 
 | 4727 | for arguments other than zero, so it should only be used for debugging purposes. | 
 | 4728 | </p> | 
 | 4729 |  | 
 | 4730 | <p> | 
 | 4731 | Note that calling this intrinsic does not prevent function inlining or other | 
| Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 4732 | aggressive transformations, so the value returned may not be that of the obvious | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4733 | source-language caller. | 
 | 4734 | </p> | 
 | 4735 | </div> | 
 | 4736 |  | 
| Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4737 | <!-- _______________________________________________________________________ --> | 
 | 4738 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4739 |   <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a> | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4740 | </div> | 
 | 4741 |  | 
 | 4742 | <div class="doc_text"> | 
 | 4743 |  | 
 | 4744 | <h5>Syntax:</h5> | 
 | 4745 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4746 |   declare i8 *@llvm.stacksave() | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4747 | </pre> | 
 | 4748 |  | 
 | 4749 | <h5>Overview:</h5> | 
 | 4750 |  | 
 | 4751 | <p> | 
 | 4752 | The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4753 | the function stack, for use with <a href="#int_stackrestore"> | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4754 | <tt>llvm.stackrestore</tt></a>.  This is useful for implementing language | 
 | 4755 | features like scoped automatic variable sized arrays in C99. | 
 | 4756 | </p> | 
 | 4757 |  | 
 | 4758 | <h5>Semantics:</h5> | 
 | 4759 |  | 
 | 4760 | <p> | 
 | 4761 | This intrinsic returns a opaque pointer value that can be passed to <a | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4762 | href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>.  When an | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4763 | <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from  | 
 | 4764 | <tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the | 
 | 4765 | state it was in when the <tt>llvm.stacksave</tt> intrinsic executed.  In | 
 | 4766 | practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack | 
 | 4767 | that were allocated after the <tt>llvm.stacksave</tt> was executed. | 
 | 4768 | </p> | 
 | 4769 |  | 
 | 4770 | </div> | 
 | 4771 |  | 
 | 4772 | <!-- _______________________________________________________________________ --> | 
 | 4773 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4774 |   <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a> | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4775 | </div> | 
 | 4776 |  | 
 | 4777 | <div class="doc_text"> | 
 | 4778 |  | 
 | 4779 | <h5>Syntax:</h5> | 
 | 4780 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4781 |   declare void @llvm.stackrestore(i8 * %ptr) | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4782 | </pre> | 
 | 4783 |  | 
 | 4784 | <h5>Overview:</h5> | 
 | 4785 |  | 
 | 4786 | <p> | 
 | 4787 | The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of | 
 | 4788 | the function stack to the state it was in when the corresponding <a | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4789 | href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed.  This is | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4790 | useful for implementing language features like scoped automatic variable sized | 
 | 4791 | arrays in C99. | 
 | 4792 | </p> | 
 | 4793 |  | 
 | 4794 | <h5>Semantics:</h5> | 
 | 4795 |  | 
 | 4796 | <p> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4797 | See the description for <a href="#int_stacksave"><tt>llvm.stacksave</tt></a>. | 
| Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4798 | </p> | 
 | 4799 |  | 
 | 4800 | </div> | 
 | 4801 |  | 
 | 4802 |  | 
 | 4803 | <!-- _______________________________________________________________________ --> | 
 | 4804 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4805 |   <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a> | 
| Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4806 | </div> | 
 | 4807 |  | 
 | 4808 | <div class="doc_text"> | 
 | 4809 |  | 
 | 4810 | <h5>Syntax:</h5> | 
 | 4811 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4812 |   declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>) | 
| Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4813 | </pre> | 
 | 4814 |  | 
 | 4815 | <h5>Overview:</h5> | 
 | 4816 |  | 
 | 4817 |  | 
 | 4818 | <p> | 
 | 4819 | The '<tt>llvm.prefetch</tt>' intrinsic is a hint to the code generator to insert | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4820 | a prefetch instruction if supported; otherwise, it is a noop.  Prefetches have | 
 | 4821 | no | 
 | 4822 | effect on the behavior of the program but can change its performance | 
| Chris Lattner | 2a61536 | 2005-02-28 19:47:14 +0000 | [diff] [blame] | 4823 | characteristics. | 
| Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4824 | </p> | 
 | 4825 |  | 
 | 4826 | <h5>Arguments:</h5> | 
 | 4827 |  | 
 | 4828 | <p> | 
 | 4829 | <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier | 
 | 4830 | determining if the fetch should be for a read (0) or write (1), and | 
 | 4831 | <tt>locality</tt> is a temporal locality specifier ranging from (0) - no | 
| Chris Lattner | aeffb4a | 2005-03-07 20:31:38 +0000 | [diff] [blame] | 4832 | locality, to (3) - extremely local keep in cache.  The <tt>rw</tt> and | 
| Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4833 | <tt>locality</tt> arguments must be constant integers. | 
 | 4834 | </p> | 
 | 4835 |  | 
 | 4836 | <h5>Semantics:</h5> | 
 | 4837 |  | 
 | 4838 | <p> | 
 | 4839 | This intrinsic does not modify the behavior of the program.  In particular, | 
 | 4840 | prefetches cannot trap and do not produce a value.  On targets that support this | 
 | 4841 | intrinsic, the prefetch can provide hints to the processor cache for better | 
 | 4842 | performance. | 
 | 4843 | </p> | 
 | 4844 |  | 
 | 4845 | </div> | 
 | 4846 |  | 
| Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4847 | <!-- _______________________________________________________________________ --> | 
 | 4848 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4849 |   <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a> | 
| Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4850 | </div> | 
 | 4851 |  | 
 | 4852 | <div class="doc_text"> | 
 | 4853 |  | 
 | 4854 | <h5>Syntax:</h5> | 
 | 4855 | <pre> | 
| Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4856 |   declare void @llvm.pcmarker(i32 <id>) | 
| Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4857 | </pre> | 
 | 4858 |  | 
 | 4859 | <h5>Overview:</h5> | 
 | 4860 |  | 
 | 4861 |  | 
 | 4862 | <p> | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4863 | The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter | 
 | 4864 | (PC) in a region of  | 
| Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4865 | code to simulators and other tools.  The method is target specific, but it is  | 
 | 4866 | expected that the marker will use exported symbols to transmit the PC of the marker. | 
| Jeff Cohen | 25d4f7e | 2005-11-11 02:15:27 +0000 | [diff] [blame] | 4867 | The marker makes no guarantees that it will remain with any specific instruction  | 
| Chris Lattner | d07c3f4 | 2005-11-15 06:07:55 +0000 | [diff] [blame] | 4868 | after optimizations.  It is possible that the presence of a marker will inhibit  | 
| Chris Lattner | b3e7afd | 2006-03-24 07:16:10 +0000 | [diff] [blame] | 4869 | optimizations.  The intended use is to be inserted after optimizations to allow | 
| John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4870 | correlations of simulation runs. | 
| Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4871 | </p> | 
 | 4872 |  | 
 | 4873 | <h5>Arguments:</h5> | 
 | 4874 |  | 
 | 4875 | <p> | 
 | 4876 | <tt>id</tt> is a numerical id identifying the marker. | 
 | 4877 | </p> | 
 | 4878 |  | 
 | 4879 | <h5>Semantics:</h5> | 
 | 4880 |  | 
 | 4881 | <p> | 
 | 4882 | This intrinsic does not modify the behavior of the program.  Backends that do not  | 
 | 4883 | support this intrinisic may ignore it. | 
 | 4884 | </p> | 
 | 4885 |  | 
 | 4886 | </div> | 
 | 4887 |  | 
| Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4888 | <!-- _______________________________________________________________________ --> | 
 | 4889 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4890 |   <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a> | 
| Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4891 | </div> | 
 | 4892 |  | 
 | 4893 | <div class="doc_text"> | 
 | 4894 |  | 
 | 4895 | <h5>Syntax:</h5> | 
 | 4896 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4897 |   declare i64 @llvm.readcyclecounter( ) | 
| Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4898 | </pre> | 
 | 4899 |  | 
 | 4900 | <h5>Overview:</h5> | 
 | 4901 |  | 
 | 4902 |  | 
 | 4903 | <p> | 
 | 4904 | The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle  | 
 | 4905 | counter register (or similar low latency, high accuracy clocks) on those targets | 
 | 4906 | that support it.  On X86, it should map to RDTSC.  On Alpha, it should map to RPCC. | 
 | 4907 | As the backing counters overflow quickly (on the order of 9 seconds on alpha), this | 
 | 4908 | should only be used for small timings.   | 
 | 4909 | </p> | 
 | 4910 |  | 
 | 4911 | <h5>Semantics:</h5> | 
 | 4912 |  | 
 | 4913 | <p> | 
 | 4914 | When directly supported, reading the cycle counter should not modify any memory.   | 
 | 4915 | Implementations are allowed to either return a application specific value or a | 
 | 4916 | system wide value.  On backends without support, this is lowered to a constant 0. | 
 | 4917 | </p> | 
 | 4918 |  | 
 | 4919 | </div> | 
 | 4920 |  | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4921 | <!-- ======================================================================= --> | 
 | 4922 | <div class="doc_subsection"> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4923 |   <a name="int_libc">Standard C Library Intrinsics</a> | 
 | 4924 | </div> | 
 | 4925 |  | 
 | 4926 | <div class="doc_text"> | 
 | 4927 | <p> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4928 | LLVM provides intrinsics for a few important standard C library functions. | 
 | 4929 | These intrinsics allow source-language front-ends to pass information about the | 
 | 4930 | alignment of the pointer arguments to the code generator, providing opportunity | 
 | 4931 | for more efficient code generation. | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4932 | </p> | 
 | 4933 |  | 
 | 4934 | </div> | 
 | 4935 |  | 
 | 4936 | <!-- _______________________________________________________________________ --> | 
 | 4937 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4938 |   <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4939 | </div> | 
 | 4940 |  | 
 | 4941 | <div class="doc_text"> | 
 | 4942 |  | 
 | 4943 | <h5>Syntax:</h5> | 
 | 4944 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4945 |   declare void @llvm.memcpy.i32(i8 * <dest>, i8 * <src>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4946 |                                 i32 <len>, i32 <align>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4947 |   declare void @llvm.memcpy.i64(i8 * <dest>, i8 * <src>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4948 |                                 i64 <len>, i32 <align>) | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4949 | </pre> | 
 | 4950 |  | 
 | 4951 | <h5>Overview:</h5> | 
 | 4952 |  | 
 | 4953 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4954 | The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4955 | location to the destination location. | 
 | 4956 | </p> | 
 | 4957 |  | 
 | 4958 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4959 | Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt>  | 
 | 4960 | intrinsics do not return a value, and takes an extra alignment argument. | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4961 | </p> | 
 | 4962 |  | 
 | 4963 | <h5>Arguments:</h5> | 
 | 4964 |  | 
 | 4965 | <p> | 
 | 4966 | The first argument is a pointer to the destination, the second is a pointer to | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4967 | the source.  The third argument is an integer argument | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4968 | specifying the number of bytes to copy, and the fourth argument is the alignment | 
 | 4969 | of the source and destination locations. | 
 | 4970 | </p> | 
 | 4971 |  | 
| Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4972 | <p> | 
 | 4973 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
| Chris Lattner | f0afc2c | 2006-03-04 00:02:10 +0000 | [diff] [blame] | 4974 | the caller guarantees that both the source and destination pointers are aligned | 
 | 4975 | to that boundary. | 
| Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4976 | </p> | 
 | 4977 |  | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4978 | <h5>Semantics:</h5> | 
 | 4979 |  | 
 | 4980 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4981 | The '<tt>llvm.memcpy.*</tt>' intrinsics copy a block of memory from the source | 
| Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4982 | location to the destination location, which are not allowed to overlap.  It | 
 | 4983 | copies "len" bytes of memory over.  If the argument is known to be aligned to | 
 | 4984 | some boundary, this can be specified as the fourth argument, otherwise it should | 
 | 4985 | be set to 0 or 1. | 
 | 4986 | </p> | 
 | 4987 | </div> | 
 | 4988 |  | 
 | 4989 |  | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4990 | <!-- _______________________________________________________________________ --> | 
 | 4991 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4992 |   <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4993 | </div> | 
 | 4994 |  | 
 | 4995 | <div class="doc_text"> | 
 | 4996 |  | 
 | 4997 | <h5>Syntax:</h5> | 
 | 4998 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4999 |   declare void @llvm.memmove.i32(i8 * <dest>, i8 * <src>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5000 |                                  i32 <len>, i32 <align>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5001 |   declare void @llvm.memmove.i64(i8 * <dest>, i8 * <src>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5002 |                                  i64 <len>, i32 <align>) | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5003 | </pre> | 
 | 5004 |  | 
 | 5005 | <h5>Overview:</h5> | 
 | 5006 |  | 
 | 5007 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5008 | The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source | 
 | 5009 | location to the destination location. It is similar to the | 
| Chris Lattner | 4b2cbcf | 2008-01-06 19:51:52 +0000 | [diff] [blame] | 5010 | '<tt>llvm.memcpy</tt>' intrinsic but allows the two memory locations to overlap. | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5011 | </p> | 
 | 5012 |  | 
 | 5013 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5014 | Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt>  | 
 | 5015 | intrinsics do not return a value, and takes an extra alignment argument. | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5016 | </p> | 
 | 5017 |  | 
 | 5018 | <h5>Arguments:</h5> | 
 | 5019 |  | 
 | 5020 | <p> | 
 | 5021 | The first argument is a pointer to the destination, the second is a pointer to | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5022 | the source.  The third argument is an integer argument | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5023 | specifying the number of bytes to copy, and the fourth argument is the alignment | 
 | 5024 | of the source and destination locations. | 
 | 5025 | </p> | 
 | 5026 |  | 
| Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5027 | <p> | 
 | 5028 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
| Chris Lattner | f0afc2c | 2006-03-04 00:02:10 +0000 | [diff] [blame] | 5029 | the caller guarantees that the source and destination pointers are aligned to | 
 | 5030 | that boundary. | 
| Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5031 | </p> | 
 | 5032 |  | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5033 | <h5>Semantics:</h5> | 
 | 5034 |  | 
 | 5035 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5036 | The '<tt>llvm.memmove.*</tt>' intrinsics copy a block of memory from the source | 
| Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5037 | location to the destination location, which may overlap.  It | 
 | 5038 | copies "len" bytes of memory over.  If the argument is known to be aligned to | 
 | 5039 | some boundary, this can be specified as the fourth argument, otherwise it should | 
 | 5040 | be set to 0 or 1. | 
 | 5041 | </p> | 
 | 5042 | </div> | 
 | 5043 |  | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 5044 |  | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5045 | <!-- _______________________________________________________________________ --> | 
 | 5046 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5047 |   <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a> | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5048 | </div> | 
 | 5049 |  | 
 | 5050 | <div class="doc_text"> | 
 | 5051 |  | 
 | 5052 | <h5>Syntax:</h5> | 
 | 5053 | <pre> | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5054 |   declare void @llvm.memset.i32(i8 * <dest>, i8 <val>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5055 |                                 i32 <len>, i32 <align>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5056 |   declare void @llvm.memset.i64(i8 * <dest>, i8 <val>, | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5057 |                                 i64 <len>, i32 <align>) | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5058 | </pre> | 
 | 5059 |  | 
 | 5060 | <h5>Overview:</h5> | 
 | 5061 |  | 
 | 5062 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5063 | The '<tt>llvm.memset.*</tt>' intrinsics fill a block of memory with a particular | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5064 | byte value. | 
 | 5065 | </p> | 
 | 5066 |  | 
 | 5067 | <p> | 
 | 5068 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic | 
 | 5069 | does not return a value, and takes an extra alignment argument. | 
 | 5070 | </p> | 
 | 5071 |  | 
 | 5072 | <h5>Arguments:</h5> | 
 | 5073 |  | 
 | 5074 | <p> | 
 | 5075 | The first argument is a pointer to the destination to fill, the second is the | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5076 | byte value to fill it with, the third argument is an integer | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5077 | argument specifying the number of bytes to fill, and the fourth argument is the | 
 | 5078 | known alignment of destination location. | 
 | 5079 | </p> | 
 | 5080 |  | 
 | 5081 | <p> | 
 | 5082 | If the call to this intrinisic has an alignment value that is not 0 or 1, then | 
| Chris Lattner | f0afc2c | 2006-03-04 00:02:10 +0000 | [diff] [blame] | 5083 | the caller guarantees that the destination pointer is aligned to that boundary. | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5084 | </p> | 
 | 5085 |  | 
 | 5086 | <h5>Semantics:</h5> | 
 | 5087 |  | 
 | 5088 | <p> | 
| Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5089 | The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at | 
 | 5090 | the | 
| Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5091 | destination location.  If the argument is known to be aligned to some boundary, | 
 | 5092 | this can be specified as the fourth argument, otherwise it should be set to 0 or | 
 | 5093 | 1. | 
 | 5094 | </p> | 
 | 5095 | </div> | 
 | 5096 |  | 
 | 5097 |  | 
| Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 5098 | <!-- _______________________________________________________________________ --> | 
 | 5099 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5100 |   <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a> | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5101 | </div> | 
 | 5102 |  | 
 | 5103 | <div class="doc_text"> | 
 | 5104 |  | 
 | 5105 | <h5>Syntax:</h5> | 
| Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5106 | <p>This is an overloaded intrinsic. You can use <tt>llvm.sqrt</tt> on any  | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5107 | floating point or vector of floating point type. Not all targets support all | 
 | 5108 | types however. | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5109 | <pre> | 
| Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5110 |   declare float     @llvm.sqrt.f32(float %Val) | 
 | 5111 |   declare double    @llvm.sqrt.f64(double %Val) | 
 | 5112 |   declare x86_fp80  @llvm.sqrt.f80(x86_fp80 %Val) | 
 | 5113 |   declare fp128     @llvm.sqrt.f128(fp128 %Val) | 
 | 5114 |   declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5115 | </pre> | 
 | 5116 |  | 
 | 5117 | <h5>Overview:</h5> | 
 | 5118 |  | 
 | 5119 | <p> | 
| Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5120 | The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand, | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5121 | returning the same value as the libm '<tt>sqrt</tt>' functions would.  Unlike | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5122 | <tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for | 
| Chris Lattner | 103e2d7 | 2008-01-29 07:00:44 +0000 | [diff] [blame] | 5123 | negative numbers other than -0.0 (which allows for better optimization, because | 
 | 5124 | there is no need to worry about errno being set).  <tt>llvm.sqrt(-0.0)</tt> is | 
 | 5125 | defined to return -0.0 like IEEE sqrt. | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5126 | </p> | 
 | 5127 |  | 
 | 5128 | <h5>Arguments:</h5> | 
 | 5129 |  | 
 | 5130 | <p> | 
 | 5131 | The argument and return value are floating point numbers of the same type. | 
 | 5132 | </p> | 
 | 5133 |  | 
 | 5134 | <h5>Semantics:</h5> | 
 | 5135 |  | 
 | 5136 | <p> | 
| Dan Gohman | d6257fe | 2007-07-16 14:37:41 +0000 | [diff] [blame] | 5137 | This function returns the sqrt of the specified operand if it is a nonnegative | 
| Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5138 | floating point number. | 
 | 5139 | </p> | 
 | 5140 | </div> | 
 | 5141 |  | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5142 | <!-- _______________________________________________________________________ --> | 
 | 5143 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5144 |   <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a> | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5145 | </div> | 
 | 5146 |  | 
 | 5147 | <div class="doc_text"> | 
 | 5148 |  | 
 | 5149 | <h5>Syntax:</h5> | 
| Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5150 | <p>This is an overloaded intrinsic. You can use <tt>llvm.powi</tt> on any  | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5151 | floating point or vector of floating point type. Not all targets support all | 
 | 5152 | types however. | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5153 | <pre> | 
| Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5154 |   declare float     @llvm.powi.f32(float  %Val, i32 %power) | 
 | 5155 |   declare double    @llvm.powi.f64(double %Val, i32 %power) | 
 | 5156 |   declare x86_fp80  @llvm.powi.f80(x86_fp80  %Val, i32 %power) | 
 | 5157 |   declare fp128     @llvm.powi.f128(fp128 %Val, i32 %power) | 
 | 5158 |   declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128  %Val, i32 %power) | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5159 | </pre> | 
 | 5160 |  | 
 | 5161 | <h5>Overview:</h5> | 
 | 5162 |  | 
 | 5163 | <p> | 
 | 5164 | The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the | 
 | 5165 | specified (positive or negative) power.  The order of evaluation of | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5166 | multiplications is not defined.  When a vector of floating point type is | 
 | 5167 | used, the second argument remains a scalar integer value. | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5168 | </p> | 
 | 5169 |  | 
 | 5170 | <h5>Arguments:</h5> | 
 | 5171 |  | 
 | 5172 | <p> | 
 | 5173 | The second argument is an integer power, and the first is a value to raise to | 
 | 5174 | that power. | 
 | 5175 | </p> | 
 | 5176 |  | 
 | 5177 | <h5>Semantics:</h5> | 
 | 5178 |  | 
 | 5179 | <p> | 
 | 5180 | This function returns the first value raised to the second power with an | 
 | 5181 | unspecified sequence of rounding operations.</p> | 
 | 5182 | </div> | 
 | 5183 |  | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5184 | <!-- _______________________________________________________________________ --> | 
 | 5185 | <div class="doc_subsubsection"> | 
 | 5186 |   <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a> | 
 | 5187 | </div> | 
 | 5188 |  | 
 | 5189 | <div class="doc_text"> | 
 | 5190 |  | 
 | 5191 | <h5>Syntax:</h5> | 
 | 5192 | <p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any  | 
 | 5193 | floating point or vector of floating point type. Not all targets support all | 
 | 5194 | types however. | 
 | 5195 | <pre> | 
 | 5196 |   declare float     @llvm.sin.f32(float  %Val) | 
 | 5197 |   declare double    @llvm.sin.f64(double %Val) | 
 | 5198 |   declare x86_fp80  @llvm.sin.f80(x86_fp80  %Val) | 
 | 5199 |   declare fp128     @llvm.sin.f128(fp128 %Val) | 
 | 5200 |   declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128  %Val) | 
 | 5201 | </pre> | 
 | 5202 |  | 
 | 5203 | <h5>Overview:</h5> | 
 | 5204 |  | 
 | 5205 | <p> | 
 | 5206 | The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand. | 
 | 5207 | </p> | 
 | 5208 |  | 
 | 5209 | <h5>Arguments:</h5> | 
 | 5210 |  | 
 | 5211 | <p> | 
 | 5212 | The argument and return value are floating point numbers of the same type. | 
 | 5213 | </p> | 
 | 5214 |  | 
 | 5215 | <h5>Semantics:</h5> | 
 | 5216 |  | 
 | 5217 | <p> | 
 | 5218 | This function returns the sine of the specified operand, returning the | 
 | 5219 | same values as the libm <tt>sin</tt> functions would, and handles error | 
| Dan Gohman | ba83b7e | 2007-10-17 18:05:13 +0000 | [diff] [blame] | 5220 | conditions in the same way.</p> | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5221 | </div> | 
 | 5222 |  | 
 | 5223 | <!-- _______________________________________________________________________ --> | 
 | 5224 | <div class="doc_subsubsection"> | 
 | 5225 |   <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a> | 
 | 5226 | </div> | 
 | 5227 |  | 
 | 5228 | <div class="doc_text"> | 
 | 5229 |  | 
 | 5230 | <h5>Syntax:</h5> | 
 | 5231 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any  | 
 | 5232 | floating point or vector of floating point type. Not all targets support all | 
 | 5233 | types however. | 
 | 5234 | <pre> | 
 | 5235 |   declare float     @llvm.cos.f32(float  %Val) | 
 | 5236 |   declare double    @llvm.cos.f64(double %Val) | 
 | 5237 |   declare x86_fp80  @llvm.cos.f80(x86_fp80  %Val) | 
 | 5238 |   declare fp128     @llvm.cos.f128(fp128 %Val) | 
 | 5239 |   declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128  %Val) | 
 | 5240 | </pre> | 
 | 5241 |  | 
 | 5242 | <h5>Overview:</h5> | 
 | 5243 |  | 
 | 5244 | <p> | 
 | 5245 | The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand. | 
 | 5246 | </p> | 
 | 5247 |  | 
 | 5248 | <h5>Arguments:</h5> | 
 | 5249 |  | 
 | 5250 | <p> | 
 | 5251 | The argument and return value are floating point numbers of the same type. | 
 | 5252 | </p> | 
 | 5253 |  | 
 | 5254 | <h5>Semantics:</h5> | 
 | 5255 |  | 
 | 5256 | <p> | 
 | 5257 | This function returns the cosine of the specified operand, returning the | 
 | 5258 | same values as the libm <tt>cos</tt> functions would, and handles error | 
| Dan Gohman | ba83b7e | 2007-10-17 18:05:13 +0000 | [diff] [blame] | 5259 | conditions in the same way.</p> | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5260 | </div> | 
 | 5261 |  | 
 | 5262 | <!-- _______________________________________________________________________ --> | 
 | 5263 | <div class="doc_subsubsection"> | 
 | 5264 |   <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a> | 
 | 5265 | </div> | 
 | 5266 |  | 
 | 5267 | <div class="doc_text"> | 
 | 5268 |  | 
 | 5269 | <h5>Syntax:</h5> | 
 | 5270 | <p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any  | 
 | 5271 | floating point or vector of floating point type. Not all targets support all | 
 | 5272 | types however. | 
 | 5273 | <pre> | 
 | 5274 |   declare float     @llvm.pow.f32(float  %Val, float %Power) | 
 | 5275 |   declare double    @llvm.pow.f64(double %Val, double %Power) | 
 | 5276 |   declare x86_fp80  @llvm.pow.f80(x86_fp80  %Val, x86_fp80 %Power) | 
 | 5277 |   declare fp128     @llvm.pow.f128(fp128 %Val, fp128 %Power) | 
 | 5278 |   declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128  %Val, ppc_fp128 Power) | 
 | 5279 | </pre> | 
 | 5280 |  | 
 | 5281 | <h5>Overview:</h5> | 
 | 5282 |  | 
 | 5283 | <p> | 
 | 5284 | The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the | 
 | 5285 | specified (positive or negative) power. | 
 | 5286 | </p> | 
 | 5287 |  | 
 | 5288 | <h5>Arguments:</h5> | 
 | 5289 |  | 
 | 5290 | <p> | 
 | 5291 | The second argument is a floating point power, and the first is a value to | 
 | 5292 | raise to that power. | 
 | 5293 | </p> | 
 | 5294 |  | 
 | 5295 | <h5>Semantics:</h5> | 
 | 5296 |  | 
 | 5297 | <p> | 
 | 5298 | This function returns the first value raised to the second power, | 
 | 5299 | returning the | 
 | 5300 | same values as the libm <tt>pow</tt> functions would, and handles error | 
| Dan Gohman | ba83b7e | 2007-10-17 18:05:13 +0000 | [diff] [blame] | 5301 | conditions in the same way.</p> | 
| Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5302 | </div> | 
 | 5303 |  | 
| Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5304 |  | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5305 | <!-- ======================================================================= --> | 
 | 5306 | <div class="doc_subsection"> | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5307 |   <a name="int_manip">Bit Manipulation Intrinsics</a> | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5308 | </div> | 
 | 5309 |  | 
 | 5310 | <div class="doc_text"> | 
 | 5311 | <p> | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5312 | LLVM provides intrinsics for a few important bit manipulation operations. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5313 | These allow efficient code generation for some algorithms. | 
 | 5314 | </p> | 
 | 5315 |  | 
 | 5316 | </div> | 
 | 5317 |  | 
 | 5318 | <!-- _______________________________________________________________________ --> | 
 | 5319 | <div class="doc_subsubsection"> | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5320 |   <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a> | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5321 | </div> | 
 | 5322 |  | 
 | 5323 | <div class="doc_text"> | 
 | 5324 |  | 
 | 5325 | <h5>Syntax:</h5> | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5326 | <p>This is an overloaded intrinsic function. You can use bswap on any integer | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5327 | type that is an even number of bytes (i.e. BitWidth % 16 == 0). | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5328 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5329 |   declare i16 @llvm.bswap.i16(i16 <id>) | 
 | 5330 |   declare i32 @llvm.bswap.i32(i32 <id>) | 
 | 5331 |   declare i64 @llvm.bswap.i64(i64 <id>) | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5332 | </pre> | 
 | 5333 |  | 
 | 5334 | <h5>Overview:</h5> | 
 | 5335 |  | 
 | 5336 | <p> | 
| Reid Spencer | 338ea09 | 2007-04-02 02:25:19 +0000 | [diff] [blame] | 5337 | The '<tt>llvm.bswap</tt>' family of intrinsics is used to byte swap integer  | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5338 | values with an even number of bytes (positive multiple of 16 bits).  These are  | 
 | 5339 | useful for performing operations on data that is not in the target's native  | 
 | 5340 | byte order. | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5341 | </p> | 
 | 5342 |  | 
 | 5343 | <h5>Semantics:</h5> | 
 | 5344 |  | 
 | 5345 | <p> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5346 | The <tt>llvm.bswap.i16</tt> intrinsic returns an i16 value that has the high  | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5347 | and low byte of the input i16 swapped.  Similarly, the <tt>llvm.bswap.i32</tt>  | 
 | 5348 | intrinsic returns an i32 value that has the four bytes of the input i32  | 
 | 5349 | swapped, so that if the input bytes are numbered 0, 1, 2, 3 then the returned  | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5350 | i32 will have its bytes in 3, 2, 1, 0 order.  The <tt>llvm.bswap.i48</tt>,  | 
 | 5351 | <tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5352 | additional even-byte lengths (6 bytes, 8 bytes and more, respectively). | 
| Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5353 | </p> | 
 | 5354 |  | 
 | 5355 | </div> | 
 | 5356 |  | 
 | 5357 | <!-- _______________________________________________________________________ --> | 
 | 5358 | <div class="doc_subsubsection"> | 
| Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5359 |   <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a> | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5360 | </div> | 
 | 5361 |  | 
 | 5362 | <div class="doc_text"> | 
 | 5363 |  | 
 | 5364 | <h5>Syntax:</h5> | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5365 | <p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit | 
 | 5366 | width. Not all targets support all bit widths however. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5367 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5368 |   declare i8 @llvm.ctpop.i8 (i8  <src>) | 
 | 5369 |   declare i16 @llvm.ctpop.i16(i16 <src>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5370 |   declare i32 @llvm.ctpop.i32(i32 <src>) | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5371 |   declare i64 @llvm.ctpop.i64(i64 <src>) | 
 | 5372 |   declare i256 @llvm.ctpop.i256(i256 <src>) | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5373 | </pre> | 
 | 5374 |  | 
 | 5375 | <h5>Overview:</h5> | 
 | 5376 |  | 
 | 5377 | <p> | 
| Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 5378 | The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a  | 
 | 5379 | value. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5380 | </p> | 
 | 5381 |  | 
 | 5382 | <h5>Arguments:</h5> | 
 | 5383 |  | 
 | 5384 | <p> | 
| Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5385 | The only argument is the value to be counted.  The argument may be of any | 
| Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 5386 | integer type.  The return type must match the argument type. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5387 | </p> | 
 | 5388 |  | 
 | 5389 | <h5>Semantics:</h5> | 
 | 5390 |  | 
 | 5391 | <p> | 
 | 5392 | The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable. | 
 | 5393 | </p> | 
 | 5394 | </div> | 
 | 5395 |  | 
 | 5396 | <!-- _______________________________________________________________________ --> | 
 | 5397 | <div class="doc_subsubsection"> | 
| Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5398 |   <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a> | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5399 | </div> | 
 | 5400 |  | 
 | 5401 | <div class="doc_text"> | 
 | 5402 |  | 
 | 5403 | <h5>Syntax:</h5> | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5404 | <p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any  | 
 | 5405 | integer bit width. Not all targets support all bit widths however. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5406 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5407 |   declare i8 @llvm.ctlz.i8 (i8  <src>) | 
 | 5408 |   declare i16 @llvm.ctlz.i16(i16 <src>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5409 |   declare i32 @llvm.ctlz.i32(i32 <src>) | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5410 |   declare i64 @llvm.ctlz.i64(i64 <src>) | 
 | 5411 |   declare i256 @llvm.ctlz.i256(i256 <src>) | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5412 | </pre> | 
 | 5413 |  | 
 | 5414 | <h5>Overview:</h5> | 
 | 5415 |  | 
 | 5416 | <p> | 
| Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5417 | The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of  | 
 | 5418 | leading zeros in a variable. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5419 | </p> | 
 | 5420 |  | 
 | 5421 | <h5>Arguments:</h5> | 
 | 5422 |  | 
 | 5423 | <p> | 
| Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5424 | The only argument is the value to be counted.  The argument may be of any | 
| Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 5425 | integer type. The return type must match the argument type. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5426 | </p> | 
 | 5427 |  | 
 | 5428 | <h5>Semantics:</h5> | 
 | 5429 |  | 
 | 5430 | <p> | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5431 | The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros | 
 | 5432 | in a variable.  If the src == 0 then the result is the size in bits of the type | 
| Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5433 | of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>. | 
| Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5434 | </p> | 
 | 5435 | </div> | 
| Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 5436 |  | 
 | 5437 |  | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5438 |  | 
 | 5439 | <!-- _______________________________________________________________________ --> | 
 | 5440 | <div class="doc_subsubsection"> | 
| Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5441 |   <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a> | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5442 | </div> | 
 | 5443 |  | 
 | 5444 | <div class="doc_text"> | 
 | 5445 |  | 
 | 5446 | <h5>Syntax:</h5> | 
| Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5447 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any  | 
 | 5448 | integer bit width. Not all targets support all bit widths however. | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5449 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5450 |   declare i8 @llvm.cttz.i8 (i8  <src>) | 
 | 5451 |   declare i16 @llvm.cttz.i16(i16 <src>) | 
| Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5452 |   declare i32 @llvm.cttz.i32(i32 <src>) | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5453 |   declare i64 @llvm.cttz.i64(i64 <src>) | 
 | 5454 |   declare i256 @llvm.cttz.i256(i256 <src>) | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5455 | </pre> | 
 | 5456 |  | 
 | 5457 | <h5>Overview:</h5> | 
 | 5458 |  | 
 | 5459 | <p> | 
| Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5460 | The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of  | 
 | 5461 | trailing zeros. | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5462 | </p> | 
 | 5463 |  | 
 | 5464 | <h5>Arguments:</h5> | 
 | 5465 |  | 
 | 5466 | <p> | 
 | 5467 | The only argument is the value to be counted.  The argument may be of any | 
| Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 5468 | integer type.  The return type must match the argument type. | 
| Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5469 | </p> | 
 | 5470 |  | 
 | 5471 | <h5>Semantics:</h5> | 
 | 5472 |  | 
 | 5473 | <p> | 
 | 5474 | The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros | 
 | 5475 | in a variable.  If the src == 0 then the result is the size in bits of the type | 
 | 5476 | of src.  For example, <tt>llvm.cttz(2) = 1</tt>. | 
 | 5477 | </p> | 
 | 5478 | </div> | 
 | 5479 |  | 
| Reid Spencer | 497d93e | 2007-04-01 08:27:01 +0000 | [diff] [blame] | 5480 | <!-- _______________________________________________________________________ --> | 
 | 5481 | <div class="doc_subsubsection"> | 
| Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5482 |   <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a> | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5483 | </div> | 
 | 5484 |  | 
 | 5485 | <div class="doc_text"> | 
 | 5486 |  | 
 | 5487 | <h5>Syntax:</h5> | 
| Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5488 | <p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt>  | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5489 | on any integer bit width. | 
 | 5490 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5491 |   declare i17 @llvm.part.select.i17 (i17 %val, i32 %loBit, i32 %hiBit) | 
 | 5492 |   declare i29 @llvm.part.select.i29 (i29 %val, i32 %loBit, i32 %hiBit) | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5493 | </pre> | 
 | 5494 |  | 
 | 5495 | <h5>Overview:</h5> | 
| Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5496 | <p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5497 | range of bits from an integer value and returns them in the same bit width as | 
 | 5498 | the original value.</p> | 
 | 5499 |  | 
 | 5500 | <h5>Arguments:</h5> | 
 | 5501 | <p>The first argument, <tt>%val</tt> and the result may be integer types of  | 
 | 5502 | any bit width but they must have the same bit width. The second and third  | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5503 | arguments must be <tt>i32</tt> type since they specify only a bit index.</p> | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5504 |  | 
 | 5505 | <h5>Semantics:</h5> | 
| Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5506 | <p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes | 
| Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5507 | of operation: forwards and reverse. If <tt>%loBit</tt> is greater than | 
 | 5508 | <tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it | 
 | 5509 | operates in forward mode.</p> | 
 | 5510 | <p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt> | 
 | 5511 | right by <tt>%loBit</tt> bits and then ANDing it with a mask with | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5512 | only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p> | 
 | 5513 | <ol> | 
 | 5514 |   <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified | 
 | 5515 |   by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li> | 
 | 5516 |   <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value | 
 | 5517 |   to determine the number of bits to retain.</li> | 
 | 5518 |   <li>A mask of the retained bits is created by shifting a -1 value.</li> | 
 | 5519 |   <li>The mask is ANDed with <tt>%val</tt> to produce the result. | 
 | 5520 | </ol> | 
| Reid Spencer | d6a85b5 | 2007-05-14 16:14:57 +0000 | [diff] [blame] | 5521 | <p>In reverse mode, a similar computation is made except that the bits are | 
 | 5522 | returned in the reverse order. So, for example, if <tt>X</tt> has the value | 
 | 5523 | <tt>i16 0x0ACF (101011001111)</tt> and we apply  | 
 | 5524 | <tt>part.select(i16 X, 8, 3)</tt> to it, we get back the value  | 
 | 5525 | <tt>i16 0x0026 (000000100110)</tt>.</p> | 
| Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5526 | </div> | 
 | 5527 |  | 
| Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5528 | <div class="doc_subsubsection"> | 
 | 5529 |   <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a> | 
 | 5530 | </div> | 
 | 5531 |  | 
 | 5532 | <div class="doc_text"> | 
 | 5533 |  | 
 | 5534 | <h5>Syntax:</h5> | 
 | 5535 | <p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt>  | 
 | 5536 | on any integer bit width. | 
 | 5537 | <pre> | 
| Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5538 |   declare i17 @llvm.part.set.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi) | 
 | 5539 |   declare i29 @llvm.part.set.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi) | 
| Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5540 | </pre> | 
 | 5541 |  | 
 | 5542 | <h5>Overview:</h5> | 
 | 5543 | <p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range | 
 | 5544 | of bits in an integer value with another integer value. It returns the integer | 
 | 5545 | with the replaced bits.</p> | 
 | 5546 |  | 
 | 5547 | <h5>Arguments:</h5> | 
 | 5548 | <p>The first argument, <tt>%val</tt> and the result may be integer types of  | 
 | 5549 | any bit width but they must have the same bit width. <tt>%val</tt> is the value | 
 | 5550 | whose bits will be replaced.  The second argument, <tt>%repl</tt> may be an | 
 | 5551 | integer of any bit width. The third and fourth arguments must be <tt>i32</tt>  | 
 | 5552 | type since they specify only a bit index.</p> | 
 | 5553 |  | 
 | 5554 | <h5>Semantics:</h5> | 
 | 5555 | <p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes | 
 | 5556 | of operation: forwards and reverse. If <tt>%lo</tt> is greater than | 
 | 5557 | <tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it | 
 | 5558 | operates in forward mode.</p> | 
 | 5559 | <p>For both modes, the <tt>%repl</tt> value is prepared for use by either | 
 | 5560 | truncating it down to the size of the replacement area or zero extending it  | 
 | 5561 | up to that size.</p> | 
 | 5562 | <p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive) | 
 | 5563 | are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit | 
 | 5564 | in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up | 
 | 5565 | to the <tt>%hi</tt>th bit.  | 
| Reid Spencer | c6749c4 | 2007-05-14 16:50:20 +0000 | [diff] [blame] | 5566 | <p>In reverse mode, a similar computation is made except that the bits are | 
 | 5567 | reversed.  That is, the <tt>0</tt>th bit in <tt>%repl</tt> replaces the  | 
 | 5568 | <tt>%hi</tt> bit in <tt>%val</tt> and etc. down to the <tt>%lo</tt>th bit. | 
| Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5569 | <h5>Examples:</h5> | 
 | 5570 | <pre> | 
| Reid Spencer | f0dbf64 | 2007-04-12 01:03:03 +0000 | [diff] [blame] | 5571 |   llvm.part.set(0xFFFF, 0, 4, 7) -> 0xFF0F | 
| Reid Spencer | c6749c4 | 2007-05-14 16:50:20 +0000 | [diff] [blame] | 5572 |   llvm.part.set(0xFFFF, 0, 7, 4) -> 0xFF0F | 
 | 5573 |   llvm.part.set(0xFFFF, 1, 7, 4) -> 0xFF8F | 
 | 5574 |   llvm.part.set(0xFFFF, F, 8, 3) -> 0xFFE7 | 
| Reid Spencer | f0dbf64 | 2007-04-12 01:03:03 +0000 | [diff] [blame] | 5575 |   llvm.part.set(0xFFFF, 0, 3, 8) -> 0xFE07 | 
| Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 5576 | </pre> | 
| Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5577 | </div> | 
 | 5578 |  | 
| Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 5579 | <!-- ======================================================================= --> | 
 | 5580 | <div class="doc_subsection"> | 
 | 5581 |   <a name="int_debugger">Debugger Intrinsics</a> | 
 | 5582 | </div> | 
 | 5583 |  | 
 | 5584 | <div class="doc_text"> | 
 | 5585 | <p> | 
 | 5586 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), | 
 | 5587 | are described in the <a | 
 | 5588 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level | 
 | 5589 | Debugging</a> document. | 
 | 5590 | </p> | 
 | 5591 | </div> | 
 | 5592 |  | 
 | 5593 |  | 
| Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 5594 | <!-- ======================================================================= --> | 
 | 5595 | <div class="doc_subsection"> | 
 | 5596 |   <a name="int_eh">Exception Handling Intrinsics</a> | 
 | 5597 | </div> | 
 | 5598 |  | 
 | 5599 | <div class="doc_text"> | 
 | 5600 | <p> The LLVM exception handling intrinsics (which all start with | 
 | 5601 | <tt>llvm.eh.</tt> prefix), are described in the <a | 
 | 5602 | href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception | 
 | 5603 | Handling</a> document. </p> | 
 | 5604 | </div> | 
 | 5605 |  | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5606 | <!-- ======================================================================= --> | 
 | 5607 | <div class="doc_subsection"> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5608 |   <a name="int_trampoline">Trampoline Intrinsic</a> | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5609 | </div> | 
 | 5610 |  | 
 | 5611 | <div class="doc_text"> | 
 | 5612 | <p> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5613 |   This intrinsic makes it possible to excise one parameter, marked with | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5614 |   the <tt>nest</tt> attribute, from a function.  The result is a callable | 
 | 5615 |   function pointer lacking the nest parameter - the caller does not need | 
 | 5616 |   to provide a value for it.  Instead, the value to use is stored in | 
 | 5617 |   advance in a "trampoline", a block of memory usually allocated | 
 | 5618 |   on the stack, which also contains code to splice the nest value into the | 
 | 5619 |   argument list.  This is used to implement the GCC nested function address | 
 | 5620 |   extension. | 
 | 5621 | </p> | 
 | 5622 | <p> | 
 | 5623 |   For example, if the function is | 
 | 5624 |   <tt>i32 f(i8* nest  %c, i32 %x, i32 %y)</tt> then the resulting function | 
| Bill Wendling | 03295ca | 2007-09-22 09:23:55 +0000 | [diff] [blame] | 5625 |   pointer has signature <tt>i32 (i32, i32)*</tt>.  It can be created as follows:</p> | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5626 | <pre> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5627 |   %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 | 
 | 5628 |   %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0 | 
 | 5629 |   %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval ) | 
 | 5630 |   %fp = bitcast i8* %p to i32 (i32, i32)* | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5631 | </pre> | 
| Bill Wendling | 03295ca | 2007-09-22 09:23:55 +0000 | [diff] [blame] | 5632 |   <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent | 
 | 5633 |   to <tt>%val = call i32 %f( i8* %nval, i32 %x, i32 %y )</tt>.</p> | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5634 | </div> | 
 | 5635 |  | 
 | 5636 | <!-- _______________________________________________________________________ --> | 
 | 5637 | <div class="doc_subsubsection"> | 
 | 5638 |   <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a> | 
 | 5639 | </div> | 
 | 5640 | <div class="doc_text"> | 
 | 5641 | <h5>Syntax:</h5> | 
 | 5642 | <pre> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5643 | declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5644 | </pre> | 
 | 5645 | <h5>Overview:</h5> | 
 | 5646 | <p> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5647 |   This fills the memory pointed to by <tt>tramp</tt> with code | 
 | 5648 |   and returns a function pointer suitable for executing it. | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5649 | </p> | 
 | 5650 | <h5>Arguments:</h5> | 
 | 5651 | <p> | 
 | 5652 |   The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all | 
 | 5653 |   pointers.  The <tt>tramp</tt> argument must point to a sufficiently large | 
 | 5654 |   and sufficiently aligned block of memory; this memory is written to by the | 
| Duncan Sands | c00c2ba | 2007-08-22 23:39:54 +0000 | [diff] [blame] | 5655 |   intrinsic.  Note that the size and the alignment are target-specific - LLVM | 
 | 5656 |   currently provides no portable way of determining them, so a front-end that | 
 | 5657 |   generates this intrinsic needs to have some target-specific knowledge. | 
 | 5658 |   The <tt>func</tt> argument must hold a function bitcast to an <tt>i8*</tt>. | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5659 | </p> | 
 | 5660 | <h5>Semantics:</h5> | 
 | 5661 | <p> | 
 | 5662 |   The block of memory pointed to by <tt>tramp</tt> is filled with target | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5663 |   dependent code, turning it into a function.  A pointer to this function is | 
 | 5664 |   returned, but needs to be bitcast to an | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5665 |   <a href="#int_trampoline">appropriate function pointer type</a> | 
| Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5666 |   before being called.  The new function's signature is the same as that of | 
 | 5667 |   <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute | 
 | 5668 |   removed.  At most one such <tt>nest</tt> argument is allowed, and it must be | 
 | 5669 |   of pointer type.  Calling the new function is equivalent to calling | 
 | 5670 |   <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the | 
 | 5671 |   missing <tt>nest</tt> argument.  If, after calling | 
 | 5672 |   <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is | 
 | 5673 |   modified, then the effect of any later call to the returned function pointer is | 
 | 5674 |   undefined. | 
| Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5675 | </p> | 
 | 5676 | </div> | 
 | 5677 |  | 
 | 5678 | <!-- ======================================================================= --> | 
 | 5679 | <div class="doc_subsection"> | 
| Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 5680 |   <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a> | 
 | 5681 | </div> | 
 | 5682 |  | 
 | 5683 | <div class="doc_text"> | 
 | 5684 | <p> | 
 | 5685 |   These intrinsic functions expand the "universal IR" of LLVM to represent  | 
 | 5686 |   hardware constructs for atomic operations and memory synchronization.  This  | 
 | 5687 |   provides an interface to the hardware, not an interface to the programmer. It  | 
 | 5688 |   is aimed at a low enough level to allow any programming models or APIs which  | 
 | 5689 |   need atomic behaviors to map cleanly onto it. It is also modeled primarily on  | 
 | 5690 |   hardware behavior. Just as hardware provides a "universal IR" for source  | 
 | 5691 |   languages, it also provides a starting point for developing a "universal"  | 
 | 5692 |   atomic operation and synchronization IR. | 
 | 5693 | </p> | 
 | 5694 | <p> | 
 | 5695 |   These do <em>not</em> form an API such as high-level threading libraries,  | 
 | 5696 |   software transaction memory systems, atomic primitives, and intrinsic  | 
 | 5697 |   functions as found in BSD, GNU libc, atomic_ops, APR, and other system and  | 
 | 5698 |   application libraries.  The hardware interface provided by LLVM should allow  | 
 | 5699 |   a clean implementation of all of these APIs and parallel programming models.  | 
 | 5700 |   No one model or paradigm should be selected above others unless the hardware  | 
 | 5701 |   itself ubiquitously does so. | 
 | 5702 |  | 
 | 5703 | </p> | 
 | 5704 | </div> | 
 | 5705 |  | 
 | 5706 | <!-- _______________________________________________________________________ --> | 
 | 5707 | <div class="doc_subsubsection"> | 
 | 5708 |   <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a> | 
 | 5709 | </div> | 
 | 5710 | <div class="doc_text"> | 
 | 5711 | <h5>Syntax:</h5> | 
 | 5712 | <pre> | 
 | 5713 | declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>, i1 <ss>,  | 
 | 5714 | i1 <device> ) | 
 | 5715 |  | 
 | 5716 | </pre> | 
 | 5717 | <h5>Overview:</h5> | 
 | 5718 | <p> | 
 | 5719 |   The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between  | 
 | 5720 |   specific pairs of memory access types. | 
 | 5721 | </p> | 
 | 5722 | <h5>Arguments:</h5> | 
 | 5723 | <p> | 
 | 5724 |   The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments.  | 
 | 5725 |   The first four arguments enables a specific barrier as listed below.  The fith | 
 | 5726 |   argument specifies that the barrier applies to io or device or uncached memory. | 
 | 5727 |  | 
 | 5728 | </p> | 
 | 5729 |   <ul> | 
 | 5730 |     <li><tt>ll</tt>: load-load barrier</li> | 
 | 5731 |     <li><tt>ls</tt>: load-store barrier</li> | 
 | 5732 |     <li><tt>sl</tt>: store-load barrier</li> | 
 | 5733 |     <li><tt>ss</tt>: store-store barrier</li> | 
 | 5734 |     <li><tt>device</tt>: barrier applies to device and uncached memory also. | 
 | 5735 |   </ul> | 
 | 5736 | <h5>Semantics:</h5> | 
 | 5737 | <p> | 
 | 5738 |   This intrinsic causes the system to enforce some ordering constraints upon  | 
 | 5739 |   the loads and stores of the program. This barrier does not indicate  | 
 | 5740 |   <em>when</em> any events will occur, it only enforces an <em>order</em> in  | 
 | 5741 |   which they occur. For any of the specified pairs of load and store operations  | 
 | 5742 |   (f.ex.  load-load, or store-load), all of the first operations preceding the  | 
 | 5743 |   barrier will complete before any of the second operations succeeding the  | 
 | 5744 |   barrier begin. Specifically the semantics for each pairing is as follows: | 
 | 5745 | </p> | 
 | 5746 |   <ul> | 
 | 5747 |     <li><tt>ll</tt>: All loads before the barrier must complete before any load  | 
 | 5748 |     after the barrier begins.</li> | 
 | 5749 |  | 
 | 5750 |     <li><tt>ls</tt>: All loads before the barrier must complete before any  | 
 | 5751 |     store after the barrier begins.</li> | 
 | 5752 |     <li><tt>ss</tt>: All stores before the barrier must complete before any  | 
 | 5753 |     store after the barrier begins.</li> | 
 | 5754 |     <li><tt>sl</tt>: All stores before the barrier must complete before any  | 
 | 5755 |     load after the barrier begins.</li> | 
 | 5756 |   </ul> | 
 | 5757 | <p> | 
 | 5758 |   These semantics are applied with a logical "and" behavior when more than  one  | 
 | 5759 |   is enabled in a single memory barrier intrinsic.   | 
 | 5760 | </p> | 
 | 5761 | <p> | 
 | 5762 |   Backends may implement stronger barriers than those requested when they do not | 
 | 5763 |   support as fine grained a barrier as requested.  Some architectures do not | 
 | 5764 |   need all types of barriers and on such architectures, these become noops. | 
 | 5765 | </p> | 
 | 5766 | <h5>Example:</h5> | 
 | 5767 | <pre> | 
 | 5768 | %ptr      = malloc i32 | 
 | 5769 |             store i32 4, %ptr | 
 | 5770 |  | 
 | 5771 | %result1  = load i32* %ptr      <i>; yields {i32}:result1 = 4</i> | 
 | 5772 |             call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false ) | 
 | 5773 |                                 <i>; guarantee the above finishes</i> | 
 | 5774 |             store i32 8, %ptr   <i>; before this begins</i> | 
 | 5775 | </pre> | 
 | 5776 | </div> | 
 | 5777 |  | 
| Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 5778 | <!-- _______________________________________________________________________ --> | 
 | 5779 | <div class="doc_subsubsection"> | 
 | 5780 |   <a name="int_atomic_lcs">'<tt>llvm.atomic.lcs.*</tt>' Intrinsic</a> | 
 | 5781 | </div> | 
 | 5782 | <div class="doc_text"> | 
 | 5783 | <h5>Syntax:</h5> | 
 | 5784 | <p> | 
 | 5785 |   This is an overloaded intrinsic. You can use <tt>llvm.atomic.lcs</tt> on any  | 
 | 5786 |   integer bit width. Not all targets support all bit widths however.</p> | 
 | 5787 |  | 
 | 5788 | <pre> | 
 | 5789 | declare i8 @llvm.atomic.lcs.i8( i8* <ptr>, i8 <cmp>, i8 <val> ) | 
 | 5790 | declare i16 @llvm.atomic.lcs.i16( i16* <ptr>, i16 <cmp>, i16 <val> ) | 
 | 5791 | declare i32 @llvm.atomic.lcs.i32( i32* <ptr>, i32 <cmp>, i32 <val> ) | 
 | 5792 | declare i64 @llvm.atomic.lcs.i64( i64* <ptr>, i64 <cmp>, i64 <val> ) | 
 | 5793 |  | 
 | 5794 | </pre> | 
 | 5795 | <h5>Overview:</h5> | 
 | 5796 | <p> | 
 | 5797 |   This loads a value in memory and compares it to a given value. If they are  | 
 | 5798 |   equal, it stores a new value into the memory. | 
 | 5799 | </p> | 
 | 5800 | <h5>Arguments:</h5> | 
 | 5801 | <p> | 
 | 5802 |   The <tt>llvm.atomic.lcs</tt> intrinsic takes three arguments. The result as  | 
 | 5803 |   well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the  | 
 | 5804 |   same bit width. The <tt>ptr</tt> argument must be a pointer to a value of  | 
 | 5805 |   this integer type. While any bit width integer may be used, targets may only  | 
 | 5806 |   lower representations they support in hardware. | 
 | 5807 |  | 
 | 5808 | </p> | 
 | 5809 | <h5>Semantics:</h5> | 
 | 5810 | <p> | 
 | 5811 |   This entire intrinsic must be executed atomically. It first loads the value  | 
 | 5812 |   in memory pointed to by <tt>ptr</tt> and compares it with the value  | 
 | 5813 |   <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The  | 
 | 5814 |   loaded value is yielded in all cases. This provides the equivalent of an  | 
 | 5815 |   atomic compare-and-swap operation within the SSA framework. | 
 | 5816 | </p> | 
 | 5817 | <h5>Examples:</h5> | 
 | 5818 |  | 
 | 5819 | <pre> | 
 | 5820 | %ptr      = malloc i32 | 
 | 5821 |             store i32 4, %ptr | 
 | 5822 |  | 
 | 5823 | %val1     = add i32 4, 4 | 
 | 5824 | %result1  = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 4, %val1 ) | 
 | 5825 |                                           <i>; yields {i32}:result1 = 4</i> | 
 | 5826 | %stored1  = icmp eq i32 %result1, 4       <i>; yields {i1}:stored1 = true</i> | 
 | 5827 | %memval1  = load i32* %ptr                <i>; yields {i32}:memval1 = 8</i> | 
 | 5828 |  | 
 | 5829 | %val2     = add i32 1, 1 | 
 | 5830 | %result2  = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 5, %val2 ) | 
 | 5831 |                                           <i>; yields {i32}:result2 = 8</i> | 
 | 5832 | %stored2  = icmp eq i32 %result2, 5       <i>; yields {i1}:stored2 = false</i> | 
 | 5833 |  | 
 | 5834 | %memval2  = load i32* %ptr                <i>; yields {i32}:memval2 = 8</i> | 
 | 5835 | </pre> | 
 | 5836 | </div> | 
 | 5837 |  | 
 | 5838 | <!-- _______________________________________________________________________ --> | 
 | 5839 | <div class="doc_subsubsection"> | 
 | 5840 |   <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a> | 
 | 5841 | </div> | 
 | 5842 | <div class="doc_text"> | 
 | 5843 | <h5>Syntax:</h5> | 
 | 5844 |  | 
 | 5845 | <p> | 
 | 5846 |   This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any  | 
 | 5847 |   integer bit width. Not all targets support all bit widths however.</p> | 
 | 5848 | <pre> | 
 | 5849 | declare i8 @llvm.atomic.swap.i8( i8* <ptr>, i8 <val> ) | 
 | 5850 | declare i16 @llvm.atomic.swap.i16( i16* <ptr>, i16 <val> ) | 
 | 5851 | declare i32 @llvm.atomic.swap.i32( i32* <ptr>, i32 <val> ) | 
 | 5852 | declare i64 @llvm.atomic.swap.i64( i64* <ptr>, i64 <val> ) | 
 | 5853 |  | 
 | 5854 | </pre> | 
 | 5855 | <h5>Overview:</h5> | 
 | 5856 | <p> | 
 | 5857 |   This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields  | 
 | 5858 |   the value from memory. It then stores the value in <tt>val</tt> in the memory  | 
 | 5859 |   at <tt>ptr</tt>. | 
 | 5860 | </p> | 
 | 5861 | <h5>Arguments:</h5> | 
 | 5862 |  | 
 | 5863 | <p> | 
 | 5864 |   The <tt>llvm.atomic.ls</tt> intrinsic takes two arguments. Both the  | 
 | 5865 |   <tt>val</tt> argument and the result must be integers of the same bit width.  | 
 | 5866 |   The first argument, <tt>ptr</tt>, must be a pointer to a value of this  | 
 | 5867 |   integer type. The targets may only lower integer representations they  | 
 | 5868 |   support. | 
 | 5869 | </p> | 
 | 5870 | <h5>Semantics:</h5> | 
 | 5871 | <p> | 
 | 5872 |   This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and  | 
 | 5873 |   stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the  | 
 | 5874 |   equivalent of an atomic swap operation within the SSA framework. | 
 | 5875 |  | 
 | 5876 | </p> | 
 | 5877 | <h5>Examples:</h5> | 
 | 5878 | <pre> | 
 | 5879 | %ptr      = malloc i32 | 
 | 5880 |             store i32 4, %ptr | 
 | 5881 |  | 
 | 5882 | %val1     = add i32 4, 4 | 
 | 5883 | %result1  = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val1 ) | 
 | 5884 |                                         <i>; yields {i32}:result1 = 4</i> | 
 | 5885 | %stored1  = icmp eq i32 %result1, 4     <i>; yields {i1}:stored1 = true</i> | 
 | 5886 | %memval1  = load i32* %ptr              <i>; yields {i32}:memval1 = 8</i> | 
 | 5887 |  | 
 | 5888 | %val2     = add i32 1, 1 | 
 | 5889 | %result2  = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val2 ) | 
 | 5890 |                                         <i>; yields {i32}:result2 = 8</i> | 
 | 5891 |  | 
 | 5892 | %stored2  = icmp eq i32 %result2, 8     <i>; yields {i1}:stored2 = true</i> | 
 | 5893 | %memval2  = load i32* %ptr              <i>; yields {i32}:memval2 = 2</i> | 
 | 5894 | </pre> | 
 | 5895 | </div> | 
 | 5896 |  | 
 | 5897 | <!-- _______________________________________________________________________ --> | 
 | 5898 | <div class="doc_subsubsection"> | 
 | 5899 |   <a name="int_atomic_las">'<tt>llvm.atomic.las.*</tt>' Intrinsic</a> | 
 | 5900 |  | 
 | 5901 | </div> | 
 | 5902 | <div class="doc_text"> | 
 | 5903 | <h5>Syntax:</h5> | 
 | 5904 | <p> | 
 | 5905 |   This is an overloaded intrinsic. You can use <tt>llvm.atomic.las</tt> on any  | 
 | 5906 |   integer bit width. Not all targets support all bit widths however.</p> | 
 | 5907 | <pre> | 
 | 5908 | declare i8 @llvm.atomic.las.i8.( i8* <ptr>, i8 <delta> ) | 
 | 5909 | declare i16 @llvm.atomic.las.i16.( i16* <ptr>, i16 <delta> ) | 
 | 5910 | declare i32 @llvm.atomic.las.i32.( i32* <ptr>, i32 <delta> ) | 
 | 5911 | declare i64 @llvm.atomic.las.i64.( i64* <ptr>, i64 <delta> ) | 
 | 5912 |  | 
 | 5913 | </pre> | 
 | 5914 | <h5>Overview:</h5> | 
 | 5915 | <p> | 
 | 5916 |   This intrinsic adds <tt>delta</tt> to the value stored in memory at  | 
 | 5917 |   <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>. | 
 | 5918 | </p> | 
 | 5919 | <h5>Arguments:</h5> | 
 | 5920 | <p> | 
 | 5921 |  | 
 | 5922 |   The intrinsic takes two arguments, the first a pointer to an integer value  | 
 | 5923 |   and the second an integer value. The result is also an integer value. These  | 
 | 5924 |   integer types can have any bit width, but they must all have the same bit  | 
 | 5925 |   width. The targets may only lower integer representations they support. | 
 | 5926 | </p> | 
 | 5927 | <h5>Semantics:</h5> | 
 | 5928 | <p> | 
 | 5929 |   This intrinsic does a series of operations atomically. It first loads the  | 
 | 5930 |   value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result  | 
 | 5931 |   to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>. | 
 | 5932 | </p> | 
 | 5933 |  | 
 | 5934 | <h5>Examples:</h5> | 
 | 5935 | <pre> | 
 | 5936 | %ptr      = malloc i32 | 
 | 5937 |         store i32 4, %ptr | 
 | 5938 | %result1  = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 4 ) | 
 | 5939 |                                 <i>; yields {i32}:result1 = 4</i> | 
 | 5940 | %result2  = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 2 ) | 
 | 5941 |                                 <i>; yields {i32}:result2 = 8</i> | 
 | 5942 | %result3  = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 5 ) | 
 | 5943 |                                 <i>; yields {i32}:result3 = 10</i> | 
 | 5944 | %memval   = load i32* %ptr      <i>; yields {i32}:memval1 = 15</i> | 
 | 5945 | </pre> | 
 | 5946 | </div> | 
 | 5947 |  | 
| Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 5948 |  | 
 | 5949 | <!-- ======================================================================= --> | 
 | 5950 | <div class="doc_subsection"> | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5951 |   <a name="int_general">General Intrinsics</a> | 
 | 5952 | </div> | 
 | 5953 |  | 
 | 5954 | <div class="doc_text"> | 
 | 5955 | <p> This class of intrinsics is designed to be generic and has | 
 | 5956 | no specific purpose. </p> | 
 | 5957 | </div> | 
 | 5958 |  | 
 | 5959 | <!-- _______________________________________________________________________ --> | 
 | 5960 | <div class="doc_subsubsection"> | 
 | 5961 |   <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a> | 
 | 5962 | </div> | 
 | 5963 |  | 
 | 5964 | <div class="doc_text"> | 
 | 5965 |  | 
 | 5966 | <h5>Syntax:</h5> | 
 | 5967 | <pre> | 
| Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 5968 |   declare void @llvm.var.annotation(i8* <val>, i8* <str>, i8* <str>, i32  <int> ) | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5969 | </pre> | 
 | 5970 |  | 
 | 5971 | <h5>Overview:</h5> | 
 | 5972 |  | 
 | 5973 | <p> | 
 | 5974 | The '<tt>llvm.var.annotation</tt>' intrinsic | 
 | 5975 | </p> | 
 | 5976 |  | 
 | 5977 | <h5>Arguments:</h5> | 
 | 5978 |  | 
 | 5979 | <p> | 
| Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 5980 | The first argument is a pointer to a value, the second is a pointer to a  | 
 | 5981 | global string, the third is a pointer to a global string which is the source  | 
 | 5982 | file name, and the last argument is the line number. | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5983 | </p> | 
 | 5984 |  | 
 | 5985 | <h5>Semantics:</h5> | 
 | 5986 |  | 
 | 5987 | <p> | 
| Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 5988 | This intrinsic allows annotation of local variables with arbitrary strings. | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5989 | This can be useful for special purpose optimizations that want to look for these | 
| Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 5990 | annotations.  These have no other defined use, they are ignored by code | 
 | 5991 | generation and optimization. | 
 | 5992 | </p> | 
| Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5993 | </div> | 
 | 5994 |  | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5995 | <!-- _______________________________________________________________________ --> | 
 | 5996 | <div class="doc_subsubsection"> | 
| Tanya Lattner | e1a8da0 | 2007-09-21 23:57:59 +0000 | [diff] [blame] | 5997 |   <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a> | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5998 | </div> | 
 | 5999 |  | 
 | 6000 | <div class="doc_text"> | 
 | 6001 |  | 
 | 6002 | <h5>Syntax:</h5> | 
| Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 6003 | <p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on  | 
 | 6004 | any integer bit width.  | 
 | 6005 | </p> | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6006 | <pre> | 
| Tanya Lattner | d3989a8 | 2007-09-22 00:03:01 +0000 | [diff] [blame] | 6007 |   declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32  <int> ) | 
 | 6008 |   declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32  <int> ) | 
 | 6009 |   declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32  <int> ) | 
 | 6010 |   declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32  <int> ) | 
 | 6011 |   declare i256 @llvm.annotation.i256(i256 <val>, i8* <str>, i8* <str>, i32  <int> ) | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6012 | </pre> | 
 | 6013 |  | 
 | 6014 | <h5>Overview:</h5> | 
| Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 6015 |  | 
 | 6016 | <p> | 
 | 6017 | The '<tt>llvm.annotation</tt>' intrinsic. | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6018 | </p> | 
 | 6019 |  | 
 | 6020 | <h5>Arguments:</h5> | 
 | 6021 |  | 
 | 6022 | <p> | 
 | 6023 | The first argument is an integer value (result of some expression),  | 
 | 6024 | the second is a pointer to a global string, the third is a pointer to a global  | 
 | 6025 | string which is the source file name, and the last argument is the line number. | 
| Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 6026 | It returns the value of the first argument. | 
| Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6027 | </p> | 
 | 6028 |  | 
 | 6029 | <h5>Semantics:</h5> | 
 | 6030 |  | 
 | 6031 | <p> | 
 | 6032 | This intrinsic allows annotations to be put on arbitrary expressions | 
 | 6033 | with arbitrary strings.  This can be useful for special purpose optimizations  | 
 | 6034 | that want to look for these annotations.  These have no other defined use, they  | 
 | 6035 | are ignored by code generation and optimization. | 
 | 6036 | </div> | 
| Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 6037 |  | 
| Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 6038 | <!-- _______________________________________________________________________ --> | 
 | 6039 | <div class="doc_subsubsection"> | 
 | 6040 |   <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a> | 
 | 6041 | </div> | 
 | 6042 |  | 
 | 6043 | <div class="doc_text"> | 
 | 6044 |  | 
 | 6045 | <h5>Syntax:</h5> | 
 | 6046 | <pre> | 
 | 6047 |   declare void @llvm.trap() | 
 | 6048 | </pre> | 
 | 6049 |  | 
 | 6050 | <h5>Overview:</h5> | 
 | 6051 |  | 
 | 6052 | <p> | 
 | 6053 | The '<tt>llvm.trap</tt>' intrinsic | 
 | 6054 | </p> | 
 | 6055 |  | 
 | 6056 | <h5>Arguments:</h5> | 
 | 6057 |  | 
 | 6058 | <p> | 
 | 6059 | None | 
 | 6060 | </p> | 
 | 6061 |  | 
 | 6062 | <h5>Semantics:</h5> | 
 | 6063 |  | 
 | 6064 | <p> | 
 | 6065 | This intrinsics is lowered to the target dependent trap instruction. If the | 
 | 6066 | target does not have a trap instruction, this intrinsic will be lowered to the | 
 | 6067 | call of the abort() function. | 
 | 6068 | </p> | 
 | 6069 | </div> | 
 | 6070 |  | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 6071 | <!-- *********************************************************************** --> | 
| Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 6072 | <hr> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 6073 | <address> | 
 | 6074 |   <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
 | 6075 |   src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> | 
 | 6076 |   <a href="http://validator.w3.org/check/referer"><img | 
| Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 6077 |   src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 6078 |  | 
 | 6079 |   <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> | 
| Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 6080 |   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> | 
| Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 6081 |   Last modified: $Date$ | 
 | 6082 | </address> | 
| Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 6083 |  | 
| Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 6084 | </body> | 
 | 6085 | </html> |