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> |
Bill Wendling | 3d10a5a | 2009-07-20 01:03:30 +0000 | [diff] [blame^] | 23 | <li><a href="#linkage">Linkage Types</a> |
| 24 | <ol> |
| 25 | <li><a href="#linkage_private">private</a></li> |
| 26 | <li><a href="#linkage_linker_private">linker_private</a></li> |
| 27 | <li><a href="#linkage_internal">internal</a></li> |
| 28 | <li><a href="#linkage_available_externally">available_externally</a></li> |
| 29 | <li><a href="#linkage_linkonce">linkonce</a></li> |
| 30 | <li><a href="#linkage_common">common</a></li> |
| 31 | <li><a href="#linkage_weak">weak</a></li> |
| 32 | <li><a href="#linkage_appending">appending</a></li> |
| 33 | <li><a href="#linkage_externweak">extern_weak</a></li> |
| 34 | <li><a href="#linkage_linkonce">linkonce_odr</a></li> |
| 35 | <li><a href="#linkage_weak">weak_odr</a></li> |
| 36 | <li><a href="#linkage_external">externally visible</a></li> |
| 37 | <li><a href="#linkage_dllimport">dllimport</a></li> |
| 38 | <li><a href="#linkage_dllexport">dllexport</a></li> |
| 39 | </ol> |
| 40 | </li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 41 | <li><a href="#callingconv">Calling Conventions</a></li> |
Chris Lattner | e7886e4 | 2009-01-11 20:53:49 +0000 | [diff] [blame] | 42 | <li><a href="#namedtypes">Named Types</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 43 | <li><a href="#globalvars">Global Variables</a></li> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 44 | <li><a href="#functionstructure">Functions</a></li> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 45 | <li><a href="#aliasstructure">Aliases</a></li> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 46 | <li><a href="#paramattrs">Parameter Attributes</a></li> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 47 | <li><a href="#fnattrs">Function Attributes</a></li> |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 48 | <li><a href="#gc">Garbage Collector Names</a></li> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 49 | <li><a href="#moduleasm">Module-Level Inline Assembly</a></li> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 50 | <li><a href="#datalayout">Data Layout</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 51 | </ol> |
| 52 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 53 | <li><a href="#typesystem">Type System</a> |
| 54 | <ol> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 55 | <li><a href="#t_classifications">Type Classifications</a></li> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 56 | <li><a href="#t_primitive">Primitive Types</a> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 57 | <ol> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 58 | <li><a href="#t_floating">Floating Point Types</a></li> |
| 59 | <li><a href="#t_void">Void Type</a></li> |
| 60 | <li><a href="#t_label">Label Type</a></li> |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 61 | <li><a href="#t_metadata">Metadata Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 62 | </ol> |
| 63 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 64 | <li><a href="#t_derived">Derived Types</a> |
| 65 | <ol> |
Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 66 | <li><a href="#t_integer">Integer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 67 | <li><a href="#t_array">Array Type</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 68 | <li><a href="#t_function">Function Type</a></li> |
| 69 | <li><a href="#t_pointer">Pointer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 70 | <li><a href="#t_struct">Structure Type</a></li> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 71 | <li><a href="#t_pstruct">Packed Structure Type</a></li> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 72 | <li><a href="#t_vector">Vector Type</a></li> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 73 | <li><a href="#t_opaque">Opaque Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 74 | </ol> |
| 75 | </li> |
Chris Lattner | 242d61d | 2009-02-02 07:32:36 +0000 | [diff] [blame] | 76 | <li><a href="#t_uprefs">Type Up-references</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 77 | </ol> |
| 78 | </li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 79 | <li><a href="#constants">Constants</a> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 80 | <ol> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 81 | <li><a href="#simpleconstants">Simple Constants</a></li> |
Chris Lattner | 7088279 | 2009-02-28 18:32:25 +0000 | [diff] [blame] | 82 | <li><a href="#complexconstants">Complex Constants</a></li> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 83 | <li><a href="#globalconstants">Global Variable and Function Addresses</a></li> |
| 84 | <li><a href="#undefvalues">Undefined Values</a></li> |
| 85 | <li><a href="#constantexprs">Constant Expressions</a></li> |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 86 | <li><a href="#metadata">Embedded Metadata</a></li> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 87 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 88 | </li> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 89 | <li><a href="#othervalues">Other Values</a> |
| 90 | <ol> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 91 | <li><a href="#inlineasm">Inline Assembler Expressions</a></li> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 92 | </ol> |
| 93 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 94 | <li><a href="#instref">Instruction Reference</a> |
| 95 | <ol> |
| 96 | <li><a href="#terminators">Terminator Instructions</a> |
| 97 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 98 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> |
| 99 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 100 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> |
| 101 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 102 | <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 103 | <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 104 | </ol> |
| 105 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 106 | <li><a href="#binaryops">Binary Operations</a> |
| 107 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 108 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 109 | <li><a href="#i_fadd">'<tt>fadd</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 110 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 111 | <li><a href="#i_fsub">'<tt>fsub</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 112 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 113 | <li><a href="#i_fmul">'<tt>fmul</tt>' Instruction</a></li> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 114 | <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li> |
| 115 | <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li> |
| 116 | <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 117 | <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li> |
| 118 | <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li> |
| 119 | <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 120 | </ol> |
| 121 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 122 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> |
| 123 | <ol> |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 124 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> |
| 125 | <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li> |
| 126 | <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 127 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 128 | <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 129 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 130 | </ol> |
| 131 | </li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 132 | <li><a href="#vectorops">Vector Operations</a> |
| 133 | <ol> |
| 134 | <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li> |
| 135 | <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li> |
| 136 | <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 137 | </ol> |
| 138 | </li> |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 139 | <li><a href="#aggregateops">Aggregate Operations</a> |
| 140 | <ol> |
| 141 | <li><a href="#i_extractvalue">'<tt>extractvalue</tt>' Instruction</a></li> |
| 142 | <li><a href="#i_insertvalue">'<tt>insertvalue</tt>' Instruction</a></li> |
| 143 | </ol> |
| 144 | </li> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 145 | <li><a href="#memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 146 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 147 | <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li> |
| 148 | <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li> |
| 149 | <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 150 | <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li> |
| 151 | <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li> |
| 152 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 153 | </ol> |
| 154 | </li> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 155 | <li><a href="#convertops">Conversion Operations</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 156 | <ol> |
| 157 | <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li> |
| 158 | <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li> |
| 159 | <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li> |
| 160 | <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li> |
| 161 | <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 162 | <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li> |
| 163 | <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li> |
| 164 | <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li> |
| 165 | <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 166 | <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li> |
| 167 | <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 168 | <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 169 | </ol> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 170 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 171 | <li><a href="#otherops">Other Operations</a> |
| 172 | <ol> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 173 | <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li> |
| 174 | <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 175 | <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 176 | <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 177 | <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 178 | <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 179 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 180 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 181 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 182 | </li> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 183 | <li><a href="#intrinsics">Intrinsic Functions</a> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 184 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 185 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> |
| 186 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 187 | <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> |
| 188 | <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li> |
| 189 | <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] | 190 | </ol> |
| 191 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 192 | <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> |
| 193 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 194 | <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> |
| 195 | <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> |
| 196 | <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 197 | </ol> |
| 198 | </li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 199 | <li><a href="#int_codegen">Code Generator Intrinsics</a> |
| 200 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 201 | <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> |
| 202 | <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li> |
| 203 | <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li> |
| 204 | <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li> |
| 205 | <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li> |
| 206 | <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li> |
| 207 | <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 208 | </ol> |
| 209 | </li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 210 | <li><a href="#int_libc">Standard C Library Intrinsics</a> |
| 211 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 212 | <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li> |
| 213 | <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li> |
| 214 | <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li> |
| 215 | <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li> |
| 216 | <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 217 | <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li> |
| 218 | <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li> |
| 219 | <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 220 | </ol> |
| 221 | </li> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 222 | <li><a href="#int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 223 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 224 | <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 225 | <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li> |
| 226 | <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li> |
| 227 | <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 228 | </ol> |
| 229 | </li> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 230 | <li><a href="#int_overflow">Arithmetic with Overflow Intrinsics</a> |
| 231 | <ol> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 232 | <li><a href="#int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt> Intrinsics</a></li> |
| 233 | <li><a href="#int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt> Intrinsics</a></li> |
| 234 | <li><a href="#int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt> Intrinsics</a></li> |
| 235 | <li><a href="#int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt> Intrinsics</a></li> |
| 236 | <li><a href="#int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt> Intrinsics</a></li> |
Bill Wendling | 41b485c | 2009-02-08 23:00:09 +0000 | [diff] [blame] | 237 | <li><a href="#int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt> Intrinsics</a></li> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 238 | </ol> |
| 239 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 240 | <li><a href="#int_debugger">Debugger intrinsics</a></li> |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 241 | <li><a href="#int_eh">Exception Handling intrinsics</a></li> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 242 | <li><a href="#int_trampoline">Trampoline Intrinsic</a> |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 243 | <ol> |
| 244 | <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] | 245 | </ol> |
| 246 | </li> |
Bill Wendling | 3c44f5b | 2008-11-18 22:10:53 +0000 | [diff] [blame] | 247 | <li><a href="#int_atomics">Atomic intrinsics</a> |
| 248 | <ol> |
| 249 | <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li> |
| 250 | <li><a href="#int_atomic_cmp_swap"><tt>llvm.atomic.cmp.swap</tt></a></li> |
| 251 | <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li> |
| 252 | <li><a href="#int_atomic_load_add"><tt>llvm.atomic.load.add</tt></a></li> |
| 253 | <li><a href="#int_atomic_load_sub"><tt>llvm.atomic.load.sub</tt></a></li> |
| 254 | <li><a href="#int_atomic_load_and"><tt>llvm.atomic.load.and</tt></a></li> |
| 255 | <li><a href="#int_atomic_load_nand"><tt>llvm.atomic.load.nand</tt></a></li> |
| 256 | <li><a href="#int_atomic_load_or"><tt>llvm.atomic.load.or</tt></a></li> |
| 257 | <li><a href="#int_atomic_load_xor"><tt>llvm.atomic.load.xor</tt></a></li> |
| 258 | <li><a href="#int_atomic_load_max"><tt>llvm.atomic.load.max</tt></a></li> |
| 259 | <li><a href="#int_atomic_load_min"><tt>llvm.atomic.load.min</tt></a></li> |
| 260 | <li><a href="#int_atomic_load_umax"><tt>llvm.atomic.load.umax</tt></a></li> |
| 261 | <li><a href="#int_atomic_load_umin"><tt>llvm.atomic.load.umin</tt></a></li> |
| 262 | </ol> |
| 263 | </li> |
Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 264 | <li><a href="#int_general">General intrinsics</a> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 265 | <ol> |
Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 266 | <li><a href="#int_var_annotation"> |
Bill Wendling | 69e4adb | 2008-11-19 05:56:17 +0000 | [diff] [blame] | 267 | '<tt>llvm.var.annotation</tt>' Intrinsic</a></li> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 268 | <li><a href="#int_annotation"> |
Bill Wendling | 69e4adb | 2008-11-19 05:56:17 +0000 | [diff] [blame] | 269 | '<tt>llvm.annotation.*</tt>' Intrinsic</a></li> |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 270 | <li><a href="#int_trap"> |
Bill Wendling | 69e4adb | 2008-11-19 05:56:17 +0000 | [diff] [blame] | 271 | '<tt>llvm.trap</tt>' Intrinsic</a></li> |
| 272 | <li><a href="#int_stackprotector"> |
| 273 | '<tt>llvm.stackprotector</tt>' Intrinsic</a></li> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 274 | </ol> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 275 | </li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 276 | </ol> |
| 277 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 278 | </ol> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 279 | |
| 280 | <div class="doc_author"> |
| 281 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
| 282 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> |
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_section"> <a name="abstract">Abstract </a></div> |
| 287 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 288 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 289 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 290 | <p>This document is a reference manual for the LLVM assembly language. |
Bill Wendling | 837f39b | 2008-08-05 22:29:16 +0000 | [diff] [blame] | 291 | LLVM is a Static Single Assignment (SSA) based representation that provides |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 292 | type safety, low-level operations, flexibility, and the capability of |
| 293 | representing 'all' high-level languages cleanly. It is the common code |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 294 | representation used throughout all phases of the LLVM compilation |
| 295 | strategy.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 296 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 297 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 298 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 299 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> |
| 300 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 301 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 302 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 303 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 304 | <p>The LLVM code representation is designed to be used in three |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 305 | 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] | 306 | representation (suitable for fast loading by a Just-In-Time compiler), |
| 307 | and as a human readable assembly language representation. This allows |
| 308 | LLVM to provide a powerful intermediate representation for efficient |
| 309 | compiler transformations and analysis, while providing a natural means |
| 310 | to debug and visualize the transformations. The three different forms |
| 311 | of LLVM are all equivalent. This document describes the human readable |
| 312 | representation and notation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 313 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 314 | <p>The LLVM representation aims to be light-weight and low-level |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 315 | while being expressive, typed, and extensible at the same time. It |
| 316 | aims to be a "universal IR" of sorts, by being at a low enough level |
| 317 | that high-level ideas may be cleanly mapped to it (similar to how |
| 318 | microprocessors are "universal IR's", allowing many source languages to |
| 319 | be mapped to them). By providing type information, LLVM can be used as |
| 320 | the target of optimizations: for example, through pointer analysis, it |
| 321 | can be proven that a C automatic variable is never accessed outside of |
| 322 | the current function... allowing it to be promoted to a simple SSA |
| 323 | value instead of a memory location.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 324 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 325 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 326 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 327 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 328 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 329 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 330 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 331 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 332 | <p>It is important to note that this document describes 'well formed' |
| 333 | LLVM assembly language. There is a difference between what the parser |
| 334 | accepts and what is considered 'well formed'. For example, the |
| 335 | following instruction is syntactically okay, but not well formed:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 336 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 337 | <div class="doc_code"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 338 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 339 | %x = <a href="#i_add">add</a> i32 1, %x |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 340 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 341 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 342 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 343 | <p>...because the definition of <tt>%x</tt> does not dominate all of |
| 344 | its uses. The LLVM infrastructure provides a verification pass that may |
| 345 | 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] | 346 | automatically run by the parser after parsing input assembly and by |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 347 | the optimizer before it outputs bitcode. The violations pointed out |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 348 | by the verifier pass indicate bugs in transformation passes or input to |
| 349 | the parser.</p> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 350 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 351 | |
Chris Lattner | cc68939 | 2007-10-03 17:34:29 +0000 | [diff] [blame] | 352 | <!-- Describe the typesetting conventions here. --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 353 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 354 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 355 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 356 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 357 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 358 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 359 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 360 | <p>LLVM identifiers come in two basic types: global and local. Global |
| 361 | identifiers (functions, global variables) begin with the @ character. Local |
| 362 | identifiers (register names, types) begin with the % character. Additionally, |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 363 | there are three different formats for identifiers, for different purposes:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 364 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 365 | <ol> |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 366 | <li>Named values are represented as a string of characters with their prefix. |
| 367 | For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual |
| 368 | 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] | 369 | Identifiers which require other characters in their names can be surrounded |
Daniel Dunbar | 76dea95 | 2008-10-14 23:51:43 +0000 | [diff] [blame] | 370 | with quotes. Special characters may be escaped using "\xx" where xx is the |
| 371 | ASCII code for the character in hexadecimal. In this way, any character can |
| 372 | be used in a name value, even quotes themselves. |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 373 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 374 | <li>Unnamed values are represented as an unsigned numeric value with their |
| 375 | prefix. For example, %12, @2, %44.</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 376 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 377 | <li>Constants, which are described in a <a href="#constants">section about |
| 378 | constants</a>, below.</li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 379 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 380 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 381 | <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] | 382 | don't need to worry about name clashes with reserved words, and the set of |
| 383 | reserved words may be expanded in the future without penalty. Additionally, |
| 384 | unnamed identifiers allow a compiler to quickly come up with a temporary |
| 385 | variable without having to avoid symbol table conflicts.</p> |
| 386 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 387 | <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] | 388 | languages. There are keywords for different opcodes |
| 389 | ('<tt><a href="#i_add">add</a></tt>', |
| 390 | '<tt><a href="#i_bitcast">bitcast</a></tt>', |
| 391 | '<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] | 392 | 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] | 393 | and others. These reserved words cannot conflict with variable names, because |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 394 | none of them start with a prefix character ('%' or '@').</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 395 | |
| 396 | <p>Here is an example of LLVM code to multiply the integer variable |
| 397 | '<tt>%X</tt>' by 8:</p> |
| 398 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 399 | <p>The easy way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 400 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 401 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 402 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 403 | %result = <a href="#i_mul">mul</a> i32 %X, 8 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 404 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 405 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 406 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 407 | <p>After strength reduction:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 408 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 409 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 410 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 411 | %result = <a href="#i_shl">shl</a> i32 %X, i8 3 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 412 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 413 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 414 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 415 | <p>And the hard way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 416 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 417 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 418 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 419 | <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i> |
| 420 | <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i> |
| 421 | %result = <a href="#i_add">add</a> i32 %1, %1 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 422 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 423 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 424 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 425 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several |
| 426 | important lexical features of LLVM:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 427 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 428 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 429 | |
| 430 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end of |
| 431 | line.</li> |
| 432 | |
| 433 | <li>Unnamed temporaries are created when the result of a computation is not |
| 434 | assigned to a named value.</li> |
| 435 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 436 | <li>Unnamed temporaries are numbered sequentially</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 437 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 438 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 439 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 440 | <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] | 441 | demonstrating instructions, we will follow an instruction with a comment that |
| 442 | defines the type and name of value produced. Comments are shown in italic |
| 443 | text.</p> |
| 444 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 445 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 446 | |
| 447 | <!-- *********************************************************************** --> |
| 448 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> |
| 449 | <!-- *********************************************************************** --> |
| 450 | |
| 451 | <!-- ======================================================================= --> |
| 452 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> |
| 453 | </div> |
| 454 | |
| 455 | <div class="doc_text"> |
| 456 | |
| 457 | <p>LLVM programs are composed of "Module"s, each of which is a |
| 458 | translation unit of the input programs. Each module consists of |
| 459 | functions, global variables, and symbol table entries. Modules may be |
| 460 | combined together with the LLVM linker, which merges function (and |
| 461 | global variable) definitions, resolves forward declarations, and merges |
| 462 | symbol table entries. Here is an example of the "hello world" module:</p> |
| 463 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 464 | <div class="doc_code"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 465 | <pre><i>; Declare the string constant as a global constant...</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 466 | <a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a |
| 467 | 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] | 468 | |
| 469 | <i>; External declaration of the puts function</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 470 | <a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 471 | |
| 472 | <i>; Definition of main function</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 473 | define i32 @main() { <i>; i32()* </i> |
Dan Gohman | 2a08c53 | 2009-01-04 23:44:43 +0000 | [diff] [blame] | 474 | <i>; Convert [13 x i8]* to i8 *...</i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 475 | %cast210 = <a |
Dan Gohman | 2a08c53 | 2009-01-04 23:44:43 +0000 | [diff] [blame] | 476 | 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] | 477 | |
| 478 | <i>; Call puts function to write out the string to stdout...</i> |
| 479 | <a |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 480 | href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 481 | <a |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 482 | href="#i_ret">ret</a> i32 0<br>}<br> |
| 483 | </pre> |
| 484 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 485 | |
| 486 | <p>This example is made up of a <a href="#globalvars">global variable</a> |
| 487 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" |
| 488 | function, and a <a href="#functionstructure">function definition</a> |
| 489 | for "<tt>main</tt>".</p> |
| 490 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 491 | <p>In general, a module is made up of a list of global values, |
| 492 | where both functions and global variables are global values. Global values are |
| 493 | represented by a pointer to a memory location (in this case, a pointer to an |
| 494 | array of char, and a pointer to a function), and have one of the following <a |
| 495 | href="#linkage">linkage types</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 496 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 497 | </div> |
| 498 | |
| 499 | <!-- ======================================================================= --> |
| 500 | <div class="doc_subsection"> |
| 501 | <a name="linkage">Linkage Types</a> |
| 502 | </div> |
| 503 | |
| 504 | <div class="doc_text"> |
| 505 | |
| 506 | <p> |
| 507 | All Global Variables and Functions have one of the following types of linkage: |
| 508 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 509 | |
| 510 | <dl> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 511 | |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 512 | <dt><tt><b><a name="linkage_private">private</a></b></tt>: </dt> |
| 513 | |
| 514 | <dd>Global values with private linkage are only directly accessible by |
| 515 | objects in the current module. In particular, linking code into a module with |
| 516 | an private global value may cause the private to be renamed as necessary to |
| 517 | avoid collisions. Because the symbol is private to the module, all |
| 518 | references can be updated. This doesn't show up in any symbol table in the |
| 519 | object file. |
| 520 | </dd> |
| 521 | |
Bill Wendling | 3d10a5a | 2009-07-20 01:03:30 +0000 | [diff] [blame^] | 522 | <dt><tt><b><a name="linkage_linker_private">linker_private</a></b></tt>: </dt> |
| 523 | |
| 524 | <dd>Similar to private, but the symbol is passed through the assembler and |
| 525 | removed by the linker after evaluation.</dd> |
| 526 | |
Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 527 | <dt><tt><b><a name="linkage_internal">internal</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 528 | |
Duncan Sands | 81d05c2 | 2009-01-16 09:29:46 +0000 | [diff] [blame] | 529 | <dd> Similar to private, but the value shows as a local symbol (STB_LOCAL in |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 530 | the case of ELF) in the object file. This corresponds to the notion of the |
Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 531 | '<tt>static</tt>' keyword in C. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 532 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 533 | |
Bill Wendling | 3d10a5a | 2009-07-20 01:03:30 +0000 | [diff] [blame^] | 534 | <dt><tt><b><a name="linkage_available_externally">available_externally</a></b></tt>: |
Chris Lattner | 266c7bb | 2009-04-13 05:44:34 +0000 | [diff] [blame] | 535 | </dt> |
| 536 | |
| 537 | <dd>Globals with "<tt>available_externally</tt>" linkage are never emitted |
| 538 | into the object file corresponding to the LLVM module. They exist to |
| 539 | allow inlining and other optimizations to take place given knowledge of the |
| 540 | definition of the global, which is known to be somewhere outside the module. |
| 541 | Globals with <tt>available_externally</tt> linkage are allowed to be discarded |
| 542 | at will, and are otherwise the same as <tt>linkonce_odr</tt>. This linkage |
| 543 | type is only allowed on definitions, not declarations.</dd> |
| 544 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 545 | <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 546 | |
Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 547 | <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of |
| 548 | the same name when linkage occurs. This is typically used to implement |
| 549 | inline functions, templates, or other code which must be generated in each |
| 550 | translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are |
| 551 | allowed to be discarded. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 552 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 553 | |
Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 554 | <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt> |
| 555 | |
| 556 | <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt> |
| 557 | linkage, except that unreferenced <tt>common</tt> globals may not be |
| 558 | discarded. This is used for globals that may be emitted in multiple |
| 559 | translation units, but that are not guaranteed to be emitted into every |
| 560 | translation unit that uses them. One example of this is tentative |
| 561 | definitions in C, such as "<tt>int X;</tt>" at global scope. |
| 562 | </dd> |
| 563 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 564 | <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 565 | |
Dale Johannesen | 2307a7f | 2008-05-23 23:13:41 +0000 | [diff] [blame] | 566 | <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except |
| 567 | that some targets may choose to emit different assembly sequences for them |
| 568 | for target-dependent reasons. This is used for globals that are declared |
| 569 | "weak" in C source code. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 570 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 571 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 572 | <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 573 | |
| 574 | <dd>"<tt>appending</tt>" linkage may only be applied to global variables of |
| 575 | pointer to array type. When two global variables with appending linkage are |
| 576 | linked together, the two global arrays are appended together. This is the |
| 577 | LLVM, typesafe, equivalent of having the system linker append together |
| 578 | "sections" with identical names when .o files are linked. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 579 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 580 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 581 | <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 582 | |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 583 | <dd>The semantics of this linkage follow the ELF object file model: the |
| 584 | symbol is weak until linked, if not linked, the symbol becomes null instead |
| 585 | of being an undefined reference. |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 586 | </dd> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 587 | |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 588 | <dt><tt><b><a name="linkage_linkonce">linkonce_odr</a></b></tt>: </dt> |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 589 | <dt><tt><b><a name="linkage_weak">weak_odr</a></b></tt>: </dt> |
Chris Lattner | 266c7bb | 2009-04-13 05:44:34 +0000 | [diff] [blame] | 590 | <dd>Some languages allow differing globals to be merged, such as two |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 591 | functions with different semantics. Other languages, such as <tt>C++</tt>, |
| 592 | ensure that only equivalent globals are ever merged (the "one definition |
Chris Lattner | 266c7bb | 2009-04-13 05:44:34 +0000 | [diff] [blame] | 593 | rule" - "ODR"). Such languages can use the <tt>linkonce_odr</tt> |
Duncan Sands | 4dc2b39 | 2009-03-11 20:14:15 +0000 | [diff] [blame] | 594 | and <tt>weak_odr</tt> linkage types to indicate that the global will only |
| 595 | be merged with equivalent globals. These linkage types are otherwise the |
| 596 | same as their non-<tt>odr</tt> versions. |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 597 | </dd> |
| 598 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 599 | <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] | 600 | |
| 601 | <dd>If none of the above identifiers are used, the global is externally |
| 602 | visible, meaning that it participates in linkage and can be used to resolve |
| 603 | external symbol references. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 604 | </dd> |
Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 605 | </dl> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 606 | |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 607 | <p> |
| 608 | The next two types of linkage are targeted for Microsoft Windows platform |
| 609 | only. They are designed to support importing (exporting) symbols from (to) |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 610 | DLLs (Dynamic Link Libraries). |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 611 | </p> |
| 612 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 613 | <dl> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 614 | <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt> |
| 615 | |
| 616 | <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function |
| 617 | or variable via a global pointer to a pointer that is set up by the DLL |
| 618 | exporting the symbol. On Microsoft Windows targets, the pointer name is |
Dan Gohman | 7956412 | 2009-01-12 21:35:55 +0000 | [diff] [blame] | 619 | formed by combining <code>__imp_</code> and the function or variable name. |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 620 | </dd> |
| 621 | |
| 622 | <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt> |
| 623 | |
| 624 | <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global |
| 625 | pointer to a pointer in a DLL, so that it can be referenced with the |
| 626 | <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer |
Dan Gohman | 7956412 | 2009-01-12 21:35:55 +0000 | [diff] [blame] | 627 | name is formed by combining <code>__imp_</code> and the function or variable |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 628 | name. |
| 629 | </dd> |
| 630 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 631 | </dl> |
| 632 | |
Dan Gohman | f003276 | 2008-11-24 17:18:39 +0000 | [diff] [blame] | 633 | <p>For example, since the "<tt>.LC0</tt>" |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 634 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" |
| 635 | variable and was linked with this one, one of the two would be renamed, |
| 636 | preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are |
| 637 | external (i.e., lacking any linkage declarations), they are accessible |
Reid Spencer | ac8d276 | 2007-01-05 00:59:10 +0000 | [diff] [blame] | 638 | outside of the current module.</p> |
| 639 | <p>It is illegal for a function <i>declaration</i> |
Duncan Sands | 5f4ee1f | 2009-03-11 08:08:06 +0000 | [diff] [blame] | 640 | to have any linkage type other than "externally visible", <tt>dllimport</tt> |
| 641 | or <tt>extern_weak</tt>.</p> |
Duncan Sands | 667d4b8 | 2009-03-07 15:45:40 +0000 | [diff] [blame] | 642 | <p>Aliases can have only <tt>external</tt>, <tt>internal</tt>, <tt>weak</tt> |
| 643 | or <tt>weak_odr</tt> linkages.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 644 | </div> |
| 645 | |
| 646 | <!-- ======================================================================= --> |
| 647 | <div class="doc_subsection"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 648 | <a name="callingconv">Calling Conventions</a> |
| 649 | </div> |
| 650 | |
| 651 | <div class="doc_text"> |
| 652 | |
| 653 | <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a> |
| 654 | and <a href="#i_invoke">invokes</a> can all have an optional calling convention |
| 655 | specified for the call. The calling convention of any pair of dynamic |
| 656 | caller/callee must match, or the behavior of the program is undefined. The |
| 657 | following calling conventions are supported by LLVM, and more may be added in |
| 658 | the future:</p> |
| 659 | |
| 660 | <dl> |
| 661 | <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt> |
| 662 | |
| 663 | <dd>This calling convention (the default if no other calling convention is |
| 664 | specified) matches the target C calling conventions. This calling convention |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 665 | supports varargs function calls and tolerates some mismatch in the declared |
Reid Spencer | c28d2bc | 2006-12-31 21:30:18 +0000 | [diff] [blame] | 666 | prototype and implemented declaration of the function (as does normal C). |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 667 | </dd> |
| 668 | |
| 669 | <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt> |
| 670 | |
| 671 | <dd>This calling convention attempts to make calls as fast as possible |
| 672 | (e.g. by passing things in registers). This calling convention allows the |
| 673 | target to use whatever tricks it wants to produce fast code for the target, |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 674 | without having to conform to an externally specified ABI (Application Binary |
| 675 | Interface). Implementations of this convention should allow arbitrary |
Arnold Schwaighofer | 9097d14 | 2008-05-14 09:17:12 +0000 | [diff] [blame] | 676 | <a href="CodeGenerator.html#tailcallopt">tail call optimization</a> to be |
| 677 | supported. This calling convention does not support varargs and requires the |
| 678 | prototype of all callees to exactly match the prototype of the function |
| 679 | definition. |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 680 | </dd> |
| 681 | |
| 682 | <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt> |
| 683 | |
| 684 | <dd>This calling convention attempts to make code in the caller as efficient |
| 685 | as possible under the assumption that the call is not commonly executed. As |
| 686 | such, these calls often preserve all registers so that the call does not break |
| 687 | any live ranges in the caller side. This calling convention does not support |
| 688 | varargs and requires the prototype of all callees to exactly match the |
| 689 | prototype of the function definition. |
| 690 | </dd> |
| 691 | |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 692 | <dt><b>"<tt>cc <<em>n</em>></tt>" - Numbered convention</b>:</dt> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 693 | |
| 694 | <dd>Any calling convention may be specified by number, allowing |
| 695 | target-specific calling conventions to be used. Target specific calling |
| 696 | conventions start at 64. |
| 697 | </dd> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 698 | </dl> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 699 | |
| 700 | <p>More calling conventions can be added/defined on an as-needed basis, to |
| 701 | support pascal conventions or any other well-known target-independent |
| 702 | convention.</p> |
| 703 | |
| 704 | </div> |
| 705 | |
| 706 | <!-- ======================================================================= --> |
| 707 | <div class="doc_subsection"> |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 708 | <a name="visibility">Visibility Styles</a> |
| 709 | </div> |
| 710 | |
| 711 | <div class="doc_text"> |
| 712 | |
| 713 | <p> |
| 714 | All Global Variables and Functions have one of the following visibility styles: |
| 715 | </p> |
| 716 | |
| 717 | <dl> |
| 718 | <dt><b>"<tt>default</tt>" - Default style</b>:</dt> |
| 719 | |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 720 | <dd>On targets that use the ELF object file format, default visibility means |
| 721 | that the declaration is visible to other |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 722 | modules and, in shared libraries, means that the declared entity may be |
| 723 | overridden. On Darwin, default visibility means that the declaration is |
| 724 | visible to other modules. Default visibility corresponds to "external |
| 725 | linkage" in the language. |
| 726 | </dd> |
| 727 | |
| 728 | <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt> |
| 729 | |
| 730 | <dd>Two declarations of an object with hidden visibility refer to the same |
| 731 | object if they are in the same shared object. Usually, hidden visibility |
| 732 | indicates that the symbol will not be placed into the dynamic symbol table, |
| 733 | so no other module (executable or shared library) can reference it |
| 734 | directly. |
| 735 | </dd> |
| 736 | |
Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 737 | <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt> |
| 738 | |
| 739 | <dd>On ELF, protected visibility indicates that the symbol will be placed in |
| 740 | the dynamic symbol table, but that references within the defining module will |
| 741 | bind to the local symbol. That is, the symbol cannot be overridden by another |
| 742 | module. |
| 743 | </dd> |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 744 | </dl> |
| 745 | |
| 746 | </div> |
| 747 | |
| 748 | <!-- ======================================================================= --> |
| 749 | <div class="doc_subsection"> |
Chris Lattner | e7886e4 | 2009-01-11 20:53:49 +0000 | [diff] [blame] | 750 | <a name="namedtypes">Named Types</a> |
| 751 | </div> |
| 752 | |
| 753 | <div class="doc_text"> |
| 754 | |
| 755 | <p>LLVM IR allows you to specify name aliases for certain types. This can make |
| 756 | it easier to read the IR and make the IR more condensed (particularly when |
| 757 | recursive types are involved). An example of a name specification is: |
| 758 | </p> |
| 759 | |
| 760 | <div class="doc_code"> |
| 761 | <pre> |
| 762 | %mytype = type { %mytype*, i32 } |
| 763 | </pre> |
| 764 | </div> |
| 765 | |
| 766 | <p>You may give a name to any <a href="#typesystem">type</a> except "<a |
| 767 | href="t_void">void</a>". Type name aliases may be used anywhere a type is |
| 768 | expected with the syntax "%mytype".</p> |
| 769 | |
| 770 | <p>Note that type names are aliases for the structural type that they indicate, |
| 771 | and that you can therefore specify multiple names for the same type. This often |
| 772 | leads to confusing behavior when dumping out a .ll file. Since LLVM IR uses |
| 773 | structural typing, the name is not part of the type. When printing out LLVM IR, |
| 774 | the printer will pick <em>one name</em> to render all types of a particular |
| 775 | shape. This means that if you have code where two different source types end up |
| 776 | having the same LLVM type, that the dumper will sometimes print the "wrong" or |
| 777 | unexpected type. This is an important design point and isn't going to |
| 778 | change.</p> |
| 779 | |
| 780 | </div> |
| 781 | |
Chris Lattner | e7886e4 | 2009-01-11 20:53:49 +0000 | [diff] [blame] | 782 | <!-- ======================================================================= --> |
| 783 | <div class="doc_subsection"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 784 | <a name="globalvars">Global Variables</a> |
| 785 | </div> |
| 786 | |
| 787 | <div class="doc_text"> |
| 788 | |
Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 789 | <p>Global variables define regions of memory allocated at compilation time |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 790 | instead of run-time. Global variables may optionally be initialized, may have |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 791 | an explicit section to be placed in, and may have an optional explicit alignment |
| 792 | specified. A variable may be defined as "thread_local", which means that it |
| 793 | will not be shared by threads (each thread will have a separated copy of the |
| 794 | variable). A variable may be defined as a global "constant," which indicates |
| 795 | 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] | 796 | optimization, allowing the global data to be placed in the read-only section of |
| 797 | an executable, etc). Note that variables that need runtime initialization |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 798 | 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] | 799 | |
| 800 | <p> |
| 801 | LLVM explicitly allows <em>declarations</em> of global variables to be marked |
| 802 | constant, even if the final definition of the global is not. This capability |
| 803 | can be used to enable slightly better optimization of the program, but requires |
| 804 | the language definition to guarantee that optimizations based on the |
| 805 | 'constantness' are valid for the translation units that do not include the |
| 806 | definition. |
| 807 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 808 | |
| 809 | <p>As SSA values, global variables define pointer values that are in |
| 810 | scope (i.e. they dominate) all basic blocks in the program. Global |
| 811 | variables always define a pointer to their "content" type because they |
| 812 | describe a region of memory, and all memory objects in LLVM are |
| 813 | accessed through pointers.</p> |
| 814 | |
Chris Lattner | 8ad2f98 | 2009-07-18 21:47:15 +0000 | [diff] [blame] | 815 | <p>A global variable may be declared to reside in a target-specific numbered |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 816 | address space. For targets that support them, address spaces may affect how |
| 817 | optimizations are performed and/or what target instructions are used to access |
Christopher Lamb | d49e18d | 2007-12-12 08:44:39 +0000 | [diff] [blame] | 818 | the variable. The default address space is zero. The address space qualifier |
| 819 | must precede any other attributes.</p> |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 820 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 821 | <p>LLVM allows an explicit section to be specified for globals. If the target |
| 822 | supports it, it will emit globals to the section specified.</p> |
| 823 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 824 | <p>An explicit alignment may be specified for a global. If not present, or if |
| 825 | the alignment is set to zero, the alignment of the global is set by the target |
| 826 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 827 | global is forced to have at least that much alignment. All alignments must be |
| 828 | a power of 2.</p> |
| 829 | |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 830 | <p>For example, the following defines a global in a numbered address space with |
| 831 | an initializer, section, and alignment:</p> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 832 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 833 | <div class="doc_code"> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 834 | <pre> |
Dan Gohman | 398873c | 2009-01-11 00:40:00 +0000 | [diff] [blame] | 835 | @G = addrspace(5) constant float 1.0, section "foo", align 4 |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 836 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 837 | </div> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 838 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 839 | </div> |
| 840 | |
| 841 | |
| 842 | <!-- ======================================================================= --> |
| 843 | <div class="doc_subsection"> |
| 844 | <a name="functionstructure">Functions</a> |
| 845 | </div> |
| 846 | |
| 847 | <div class="doc_text"> |
| 848 | |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 849 | <p>LLVM function definitions consist of the "<tt>define</tt>" keyord, |
| 850 | an optional <a href="#linkage">linkage type</a>, an optional |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 851 | <a href="#visibility">visibility style</a>, an optional |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 852 | <a href="#callingconv">calling convention</a>, a return type, an optional |
| 853 | <a href="#paramattrs">parameter attribute</a> for the return type, a function |
| 854 | name, a (possibly empty) argument list (each with optional |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 855 | <a href="#paramattrs">parameter attributes</a>), optional |
| 856 | <a href="#fnattrs">function attributes</a>, an optional section, |
| 857 | an optional alignment, an optional <a href="#gc">garbage collector name</a>, |
Chris Lattner | 0c46a7d | 2008-10-04 18:10:21 +0000 | [diff] [blame] | 858 | an 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] | 859 | |
| 860 | LLVM function declarations consist of the "<tt>declare</tt>" keyword, an |
| 861 | optional <a href="#linkage">linkage type</a>, an optional |
| 862 | <a href="#visibility">visibility style</a>, an optional |
| 863 | <a href="#callingconv">calling convention</a>, a return type, an optional |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 864 | <a href="#paramattrs">parameter attribute</a> for the return type, a function |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 865 | 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] | 866 | <a href="#gc">garbage collector name</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 867 | |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 868 | <p>A function definition contains a list of basic blocks, forming the CFG |
| 869 | (Control Flow Graph) for |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 870 | the function. Each basic block may optionally start with a label (giving the |
| 871 | basic block a symbol table entry), contains a list of instructions, and ends |
| 872 | with a <a href="#terminators">terminator</a> instruction (such as a branch or |
| 873 | function return).</p> |
| 874 | |
Chris Lattner | 4a3c901 | 2007-06-08 16:52:14 +0000 | [diff] [blame] | 875 | <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] | 876 | executed on entrance to the function, and it is not allowed to have predecessor |
| 877 | basic blocks (i.e. there can not be any branches to the entry block of a |
| 878 | function). Because the block can have no predecessors, it also cannot have any |
| 879 | <a href="#i_phi">PHI nodes</a>.</p> |
| 880 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 881 | <p>LLVM allows an explicit section to be specified for functions. If the target |
| 882 | supports it, it will emit functions to the section specified.</p> |
| 883 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 884 | <p>An explicit alignment may be specified for a function. If not present, or if |
| 885 | the alignment is set to zero, the alignment of the function is set by the target |
| 886 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 887 | function is forced to have at least that much alignment. All alignments must be |
| 888 | a power of 2.</p> |
| 889 | |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 890 | <h5>Syntax:</h5> |
| 891 | |
| 892 | <div class="doc_code"> |
Chris Lattner | 50ad45c | 2008-10-13 16:55:18 +0000 | [diff] [blame] | 893 | <tt> |
| 894 | define [<a href="#linkage">linkage</a>] [<a href="#visibility">visibility</a>] |
| 895 | [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] |
| 896 | <ResultType> @<FunctionName> ([argument list]) |
| 897 | [<a href="#fnattrs">fn Attrs</a>] [section "name"] [align N] |
| 898 | [<a href="#gc">gc</a>] { ... } |
| 899 | </tt> |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 900 | </div> |
| 901 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 902 | </div> |
| 903 | |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 904 | |
| 905 | <!-- ======================================================================= --> |
| 906 | <div class="doc_subsection"> |
| 907 | <a name="aliasstructure">Aliases</a> |
| 908 | </div> |
| 909 | <div class="doc_text"> |
| 910 | <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] | 911 | function, global variable, another alias or bitcast of global value). Aliases |
| 912 | may have an optional <a href="#linkage">linkage type</a>, and an |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 913 | optional <a href="#visibility">visibility style</a>.</p> |
| 914 | |
| 915 | <h5>Syntax:</h5> |
| 916 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 917 | <div class="doc_code"> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 918 | <pre> |
Duncan Sands | 0b23ac1 | 2008-09-12 20:48:21 +0000 | [diff] [blame] | 919 | @<Name> = alias [Linkage] [Visibility] <AliaseeTy> @<Aliasee> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 920 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 921 | </div> |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 922 | |
| 923 | </div> |
| 924 | |
| 925 | |
| 926 | |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 927 | <!-- ======================================================================= --> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 928 | <div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div> |
| 929 | <div class="doc_text"> |
| 930 | <p>The return type and each parameter of a function type may have a set of |
| 931 | <i>parameter attributes</i> associated with them. Parameter attributes are |
| 932 | used to communicate additional information about the result or parameters of |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 933 | a function. Parameter attributes are considered to be part of the function, |
| 934 | not of the function type, so functions with different parameter attributes |
| 935 | can have the same function type.</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 936 | |
Reid Spencer | 950e9f8 | 2007-01-15 18:27:39 +0000 | [diff] [blame] | 937 | <p>Parameter attributes are simple keywords that follow the type specified. If |
| 938 | multiple parameter attributes are needed, they are space separated. For |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 939 | example:</p> |
| 940 | |
| 941 | <div class="doc_code"> |
| 942 | <pre> |
Nick Lewycky | b6a7d25 | 2009-02-15 23:06:14 +0000 | [diff] [blame] | 943 | declare i32 @printf(i8* noalias nocapture, ...) |
Chris Lattner | 66d922c | 2008-10-04 18:33:34 +0000 | [diff] [blame] | 944 | declare i32 @atoi(i8 zeroext) |
| 945 | declare signext i8 @returns_signed_char() |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 946 | </pre> |
| 947 | </div> |
| 948 | |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 949 | <p>Note that any attributes for the function result (<tt>nounwind</tt>, |
| 950 | <tt>readonly</tt>) come immediately after the argument list.</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 951 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 952 | <p>Currently, only the following parameter attributes are defined:</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 953 | <dl> |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 954 | <dt><tt>zeroext</tt></dt> |
Chris Lattner | 66d922c | 2008-10-04 18:33:34 +0000 | [diff] [blame] | 955 | <dd>This indicates to the code generator that the parameter or return value |
| 956 | should be zero-extended to a 32-bit value by the caller (for a parameter) |
| 957 | or the callee (for a return value).</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 958 | |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 959 | <dt><tt>signext</tt></dt> |
Chris Lattner | 66d922c | 2008-10-04 18:33:34 +0000 | [diff] [blame] | 960 | <dd>This indicates to the code generator that the parameter or return value |
| 961 | should be sign-extended to a 32-bit value by the caller (for a parameter) |
| 962 | or the callee (for a return value).</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 963 | |
Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 964 | <dt><tt>inreg</tt></dt> |
Dale Johannesen | c9c6da6 | 2008-09-25 20:47:45 +0000 | [diff] [blame] | 965 | <dd>This indicates that this parameter or return value should be treated |
| 966 | in a special target-dependent fashion during while emitting code for a |
| 967 | function call or return (usually, by putting it in a register as opposed |
Chris Lattner | 66d922c | 2008-10-04 18:33:34 +0000 | [diff] [blame] | 968 | to memory, though some targets use it to distinguish between two different |
| 969 | kinds of registers). Use of this attribute is target-specific.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 970 | |
Duncan Sands | edb05df | 2008-10-06 08:14:18 +0000 | [diff] [blame] | 971 | <dt><tt><a name="byval">byval</a></tt></dt> |
Chris Lattner | 0747baa | 2008-01-15 04:34:22 +0000 | [diff] [blame] | 972 | <dd>This indicates that the pointer parameter should really be passed by |
| 973 | value to the function. The attribute implies that a hidden copy of the |
| 974 | pointee is made between the caller and the callee, so the callee is unable |
Chris Lattner | ebec678 | 2008-08-05 18:21:08 +0000 | [diff] [blame] | 975 | to modify the value in the callee. This attribute is only valid on LLVM |
Chris Lattner | 0747baa | 2008-01-15 04:34:22 +0000 | [diff] [blame] | 976 | pointer arguments. It is generally used to pass structs and arrays by |
Duncan Sands | edb05df | 2008-10-06 08:14:18 +0000 | [diff] [blame] | 977 | value, but is also valid on pointers to scalars. The copy is considered to |
| 978 | belong to the caller not the callee (for example, |
| 979 | <tt><a href="#readonly">readonly</a></tt> functions should not write to |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 980 | <tt>byval</tt> parameters). This is not a valid attribute for return |
Chris Lattner | ce459b1 | 2009-02-05 05:42:28 +0000 | [diff] [blame] | 981 | values. The byval attribute also supports specifying an alignment with the |
| 982 | align attribute. This has a target-specific effect on the code generator |
| 983 | that usually indicates a desired alignment for the synthesized stack |
| 984 | slot.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 985 | |
Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 986 | <dt><tt>sret</tt></dt> |
Duncan Sands | e26dec6 | 2008-02-18 04:19:38 +0000 | [diff] [blame] | 987 | <dd>This indicates that the pointer parameter specifies the address of a |
| 988 | structure that is the return value of the function in the source program. |
Chris Lattner | 66d922c | 2008-10-04 18:33:34 +0000 | [diff] [blame] | 989 | This pointer must be guaranteed by the caller to be valid: loads and stores |
| 990 | to the structure may be assumed by the callee to not to trap. This may only |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 991 | be applied to the first parameter. This is not a valid attribute for |
| 992 | return values. </dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 993 | |
Zhou Sheng | febca34 | 2007-06-05 05:28:26 +0000 | [diff] [blame] | 994 | <dt><tt>noalias</tt></dt> |
Nick Lewycky | 02ff308 | 2008-11-24 03:41:24 +0000 | [diff] [blame] | 995 | <dd>This indicates that the pointer does not alias any global or any other |
| 996 | parameter. The caller is responsible for ensuring that this is the |
Nick Lewycky | b2b32fd | 2008-11-24 05:00:44 +0000 | [diff] [blame] | 997 | case. On a function return value, <tt>noalias</tt> additionally indicates |
| 998 | that the pointer does not alias any other pointers visible to the |
Nick Lewycky | f23d0d3 | 2008-12-19 06:39:12 +0000 | [diff] [blame] | 999 | caller. For further details, please see the discussion of the NoAlias |
| 1000 | response in |
| 1001 | <a href="http://llvm.org/docs/AliasAnalysis.html#MustMayNo">alias |
| 1002 | analysis</a>.</dd> |
| 1003 | |
| 1004 | <dt><tt>nocapture</tt></dt> |
| 1005 | <dd>This indicates that the callee does not make any copies of the pointer |
| 1006 | that outlive the callee itself. This is not a valid attribute for return |
| 1007 | values.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 1008 | |
Duncan Sands | 50f19f5 | 2007-07-27 19:57:41 +0000 | [diff] [blame] | 1009 | <dt><tt>nest</tt></dt> |
Duncan Sands | 0789b8b | 2008-07-08 09:27:25 +0000 | [diff] [blame] | 1010 | <dd>This indicates that the pointer parameter can be excised using the |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 1011 | <a href="#int_trampoline">trampoline intrinsics</a>. This is not a valid |
| 1012 | attribute for return values.</dd> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1013 | </dl> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1014 | |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1015 | </div> |
| 1016 | |
| 1017 | <!-- ======================================================================= --> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 1018 | <div class="doc_subsection"> |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 1019 | <a name="gc">Garbage Collector Names</a> |
| 1020 | </div> |
| 1021 | |
| 1022 | <div class="doc_text"> |
| 1023 | <p>Each function may specify a garbage collector name, which is simply a |
| 1024 | string.</p> |
| 1025 | |
| 1026 | <div class="doc_code"><pre |
| 1027 | >define void @f() gc "name" { ...</pre></div> |
| 1028 | |
| 1029 | <p>The compiler declares the supported values of <i>name</i>. Specifying a |
| 1030 | collector which will cause the compiler to alter its output in order to support |
| 1031 | the named garbage collection algorithm.</p> |
| 1032 | </div> |
| 1033 | |
| 1034 | <!-- ======================================================================= --> |
| 1035 | <div class="doc_subsection"> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1036 | <a name="fnattrs">Function Attributes</a> |
Devang Patel | f8b9481 | 2008-09-04 23:05:13 +0000 | [diff] [blame] | 1037 | </div> |
| 1038 | |
| 1039 | <div class="doc_text"> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1040 | |
| 1041 | <p>Function attributes are set to communicate additional information about |
| 1042 | a function. Function attributes are considered to be part of the function, |
| 1043 | not of the function type, so functions with different parameter attributes |
| 1044 | can have the same function type.</p> |
| 1045 | |
| 1046 | <p>Function attributes are simple keywords that follow the type specified. If |
| 1047 | multiple attributes are needed, they are space separated. For |
| 1048 | example:</p> |
Devang Patel | f8b9481 | 2008-09-04 23:05:13 +0000 | [diff] [blame] | 1049 | |
| 1050 | <div class="doc_code"> |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1051 | <pre> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1052 | define void @f() noinline { ... } |
| 1053 | define void @f() alwaysinline { ... } |
| 1054 | define void @f() alwaysinline optsize { ... } |
| 1055 | define void @f() optsize |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1056 | </pre> |
Devang Patel | f8b9481 | 2008-09-04 23:05:13 +0000 | [diff] [blame] | 1057 | </div> |
| 1058 | |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1059 | <dl> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1060 | <dt><tt>alwaysinline</tt></dt> |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1061 | <dd>This attribute indicates that the inliner should attempt to inline this |
| 1062 | function into callers whenever possible, ignoring any active inlining size |
| 1063 | threshold for this caller.</dd> |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1064 | |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1065 | <dt><tt>noinline</tt></dt> |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1066 | <dd>This attribute indicates that the inliner should never inline this function |
Chris Lattner | 94b5f7d | 2008-10-05 17:14:59 +0000 | [diff] [blame] | 1067 | in any situation. This attribute may not be used together with the |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1068 | <tt>alwaysinline</tt> attribute.</dd> |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1069 | |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1070 | <dt><tt>optsize</tt></dt> |
Devang Patel | 66c6c65 | 2008-09-29 18:34:44 +0000 | [diff] [blame] | 1071 | <dd>This attribute suggests that optimization passes and code generator passes |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1072 | make choices that keep the code size of this function low, and otherwise do |
| 1073 | optimizations specifically to reduce code size.</dd> |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1074 | |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1075 | <dt><tt>noreturn</tt></dt> |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1076 | <dd>This function attribute indicates that the function never returns normally. |
| 1077 | This produces undefined behavior at runtime if the function ever does |
| 1078 | dynamically return.</dd> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1079 | |
| 1080 | <dt><tt>nounwind</tt></dt> |
Chris Lattner | 88d4b59 | 2008-10-04 18:23:17 +0000 | [diff] [blame] | 1081 | <dd>This function attribute indicates that the function never returns with an |
| 1082 | unwind or exceptional control flow. If the function does unwind, its runtime |
| 1083 | behavior is undefined.</dd> |
| 1084 | |
| 1085 | <dt><tt>readnone</tt></dt> |
Duncan Sands | 7af1c78 | 2009-05-06 06:49:50 +0000 | [diff] [blame] | 1086 | <dd>This attribute indicates that the function computes its result (or decides to |
| 1087 | unwind an exception) based strictly on its arguments, without dereferencing any |
Duncan Sands | edb05df | 2008-10-06 08:14:18 +0000 | [diff] [blame] | 1088 | pointer arguments or otherwise accessing any mutable state (e.g. memory, control |
| 1089 | registers, etc) visible to caller functions. It does not write through any |
| 1090 | pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments) and |
Duncan Sands | 7af1c78 | 2009-05-06 06:49:50 +0000 | [diff] [blame] | 1091 | never changes any state visible to callers. This means that it cannot unwind |
| 1092 | exceptions by calling the <tt>C++</tt> exception throwing methods, but could |
| 1093 | use the <tt>unwind</tt> instruction.</dd> |
Devang Patel | 2c9c3e7 | 2008-09-26 23:51:19 +0000 | [diff] [blame] | 1094 | |
Duncan Sands | edb05df | 2008-10-06 08:14:18 +0000 | [diff] [blame] | 1095 | <dt><tt><a name="readonly">readonly</a></tt></dt> |
| 1096 | <dd>This attribute indicates that the function does not write through any |
| 1097 | pointer arguments (including <tt><a href="#byval">byval</a></tt> arguments) |
| 1098 | or otherwise modify any state (e.g. memory, control registers, etc) visible to |
| 1099 | caller functions. It may dereference pointer arguments and read state that may |
Duncan Sands | 7af1c78 | 2009-05-06 06:49:50 +0000 | [diff] [blame] | 1100 | be set in the caller. A readonly function always returns the same value (or |
| 1101 | unwinds an exception identically) when called with the same set of arguments |
| 1102 | and global state. It cannot unwind an exception by calling the <tt>C++</tt> |
| 1103 | exception throwing methods, but may use the <tt>unwind</tt> instruction.</dd> |
Bill Wendling | 31359ba | 2008-11-13 01:02:51 +0000 | [diff] [blame] | 1104 | |
| 1105 | <dt><tt><a name="ssp">ssp</a></tt></dt> |
Bill Wendling | baa39d8 | 2008-11-26 19:19:05 +0000 | [diff] [blame] | 1106 | <dd>This attribute indicates that the function should emit a stack smashing |
Bill Wendling | 31359ba | 2008-11-13 01:02:51 +0000 | [diff] [blame] | 1107 | protector. It is in the form of a "canary"—a random value placed on the |
| 1108 | stack before the local variables that's checked upon return from the function to |
| 1109 | see if it has been overwritten. A heuristic is used to determine if a function |
Bill Wendling | baa39d8 | 2008-11-26 19:19:05 +0000 | [diff] [blame] | 1110 | needs stack protectors or not. |
Bill Wendling | 31359ba | 2008-11-13 01:02:51 +0000 | [diff] [blame] | 1111 | |
Devang Patel | 5d96fda | 2009-06-12 19:45:19 +0000 | [diff] [blame] | 1112 | <br><br>If a function that has an <tt>ssp</tt> attribute is inlined into a function |
Bill Wendling | fbaa7ed | 2008-11-26 19:07:40 +0000 | [diff] [blame] | 1113 | that doesn't have an <tt>ssp</tt> attribute, then the resulting function will |
Devang Patel | 5d96fda | 2009-06-12 19:45:19 +0000 | [diff] [blame] | 1114 | have an <tt>ssp</tt> attribute.</dd> |
Bill Wendling | fbaa7ed | 2008-11-26 19:07:40 +0000 | [diff] [blame] | 1115 | |
| 1116 | <dt><tt>sspreq</tt></dt> |
Bill Wendling | baa39d8 | 2008-11-26 19:19:05 +0000 | [diff] [blame] | 1117 | <dd>This attribute indicates that the function should <em>always</em> emit a |
Bill Wendling | 31359ba | 2008-11-13 01:02:51 +0000 | [diff] [blame] | 1118 | stack smashing protector. This overrides the <tt><a href="#ssp">ssp</a></tt> |
Bill Wendling | baa39d8 | 2008-11-26 19:19:05 +0000 | [diff] [blame] | 1119 | function attribute. |
Bill Wendling | fbaa7ed | 2008-11-26 19:07:40 +0000 | [diff] [blame] | 1120 | |
Devang Patel | 5d96fda | 2009-06-12 19:45:19 +0000 | [diff] [blame] | 1121 | If a function that has an <tt>sspreq</tt> attribute is inlined into a |
Bill Wendling | fbaa7ed | 2008-11-26 19:07:40 +0000 | [diff] [blame] | 1122 | function that doesn't have an <tt>sspreq</tt> attribute or which has |
| 1123 | an <tt>ssp</tt> attribute, then the resulting function will have |
Devang Patel | 5d96fda | 2009-06-12 19:45:19 +0000 | [diff] [blame] | 1124 | an <tt>sspreq</tt> attribute.</dd> |
| 1125 | |
| 1126 | <dt><tt>noredzone</tt></dt> |
Dan Gohman | 2185f9e | 2009-06-15 17:37:09 +0000 | [diff] [blame] | 1127 | <dd>This attribute indicates that the code generator should not use a |
Dan Gohman | 125473b | 2009-06-15 21:18:01 +0000 | [diff] [blame] | 1128 | red zone, even if the target-specific ABI normally permits it. |
Dan Gohman | 2185f9e | 2009-06-15 17:37:09 +0000 | [diff] [blame] | 1129 | </dd> |
Devang Patel | 5d96fda | 2009-06-12 19:45:19 +0000 | [diff] [blame] | 1130 | |
| 1131 | <dt><tt>noimplicitfloat</tt></dt> |
| 1132 | <dd>This attributes disables implicit floating point instructions.</dd> |
| 1133 | |
Anton Korobeynikov | c5ec8a7 | 2009-07-17 18:07:26 +0000 | [diff] [blame] | 1134 | <dt><tt>naked</tt></dt> |
Chris Lattner | 0c542ff | 2009-07-17 21:14:28 +0000 | [diff] [blame] | 1135 | <dd>This attribute disables prologue / epilogue emission for the function. |
| 1136 | This can have very system-specific consequences.</dd> |
Anton Korobeynikov | c5ec8a7 | 2009-07-17 18:07:26 +0000 | [diff] [blame] | 1137 | |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1138 | </dl> |
| 1139 | |
Devang Patel | f8b9481 | 2008-09-04 23:05:13 +0000 | [diff] [blame] | 1140 | </div> |
| 1141 | |
| 1142 | <!-- ======================================================================= --> |
| 1143 | <div class="doc_subsection"> |
Chris Lattner | 1eeeb0c | 2006-04-08 04:40:53 +0000 | [diff] [blame] | 1144 | <a name="moduleasm">Module-Level Inline Assembly</a> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 1145 | </div> |
| 1146 | |
| 1147 | <div class="doc_text"> |
| 1148 | <p> |
| 1149 | Modules may contain "module-level inline asm" blocks, which corresponds to the |
| 1150 | GCC "file scope inline asm" blocks. These blocks are internally concatenated by |
| 1151 | LLVM and treated as a single unit, but may be separated in the .ll file if |
| 1152 | desired. The syntax is very simple: |
| 1153 | </p> |
| 1154 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1155 | <div class="doc_code"> |
| 1156 | <pre> |
| 1157 | module asm "inline asm code goes here" |
| 1158 | module asm "more can go here" |
| 1159 | </pre> |
| 1160 | </div> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 1161 | |
| 1162 | <p>The strings can contain any character by escaping non-printable characters. |
| 1163 | The escape sequence used is simply "\xx" where "xx" is the two digit hex code |
| 1164 | for the number. |
| 1165 | </p> |
| 1166 | |
| 1167 | <p> |
| 1168 | The inline asm code is simply printed to the machine code .s file when |
| 1169 | assembly code is generated. |
| 1170 | </p> |
| 1171 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1172 | |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1173 | <!-- ======================================================================= --> |
| 1174 | <div class="doc_subsection"> |
| 1175 | <a name="datalayout">Data Layout</a> |
| 1176 | </div> |
| 1177 | |
| 1178 | <div class="doc_text"> |
| 1179 | <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] | 1180 | data is to be laid out in memory. The syntax for the data layout is simply:</p> |
| 1181 | <pre> target datalayout = "<i>layout specification</i>"</pre> |
| 1182 | <p>The <i>layout specification</i> consists of a list of specifications |
| 1183 | separated by the minus sign character ('-'). Each specification starts with a |
| 1184 | letter and may include other information after the letter to define some |
| 1185 | aspect of the data layout. The specifications accepted are as follows: </p> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1186 | <dl> |
| 1187 | <dt><tt>E</tt></dt> |
| 1188 | <dd>Specifies that the target lays out data in big-endian form. That is, the |
| 1189 | bits with the most significance have the lowest address location.</dd> |
| 1190 | <dt><tt>e</tt></dt> |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 1191 | <dd>Specifies that the target lays out data in little-endian form. That is, |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1192 | the bits with the least significance have the lowest address location.</dd> |
| 1193 | <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1194 | <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and |
| 1195 | <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i> |
| 1196 | alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted |
| 1197 | too.</dd> |
| 1198 | <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1199 | <dd>This specifies the alignment for an integer type of a given bit |
| 1200 | <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd> |
| 1201 | <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1202 | <dd>This specifies the alignment for a vector type of a given bit |
| 1203 | <i>size</i>.</dd> |
| 1204 | <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1205 | <dd>This specifies the alignment for a floating point type of a given bit |
| 1206 | <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64 |
| 1207 | (double).</dd> |
| 1208 | <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1209 | <dd>This specifies the alignment for an aggregate type of a given bit |
| 1210 | <i>size</i>.</dd> |
Daniel Dunbar | 87bde0b | 2009-06-08 22:17:53 +0000 | [diff] [blame] | 1211 | <dt><tt>s<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 1212 | <dd>This specifies the alignment for a stack object of a given bit |
| 1213 | <i>size</i>.</dd> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1214 | </dl> |
| 1215 | <p>When constructing the data layout for a given target, LLVM starts with a |
| 1216 | default set of specifications which are then (possibly) overriden by the |
| 1217 | specifications in the <tt>datalayout</tt> keyword. The default specifications |
| 1218 | are given in this list:</p> |
| 1219 | <ul> |
| 1220 | <li><tt>E</tt> - big endian</li> |
| 1221 | <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li> |
| 1222 | <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li> |
| 1223 | <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li> |
| 1224 | <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li> |
| 1225 | <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li> |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 1226 | <li><tt>i64:32:64</tt> - i64 has ABI alignment of 32-bits but preferred |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1227 | alignment of 64-bits</li> |
| 1228 | <li><tt>f32:32:32</tt> - float is 32-bit aligned</li> |
| 1229 | <li><tt>f64:64:64</tt> - double is 64-bit aligned</li> |
| 1230 | <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li> |
| 1231 | <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li> |
| 1232 | <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li> |
Daniel Dunbar | 87bde0b | 2009-06-08 22:17:53 +0000 | [diff] [blame] | 1233 | <li><tt>s0:64:64</tt> - stack objects are 64-bit aligned</li> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1234 | </ul> |
Chris Lattner | ebec678 | 2008-08-05 18:21:08 +0000 | [diff] [blame] | 1235 | <p>When LLVM is determining the alignment for a given type, it uses the |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 1236 | following rules:</p> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1237 | <ol> |
| 1238 | <li>If the type sought is an exact match for one of the specifications, that |
| 1239 | specification is used.</li> |
| 1240 | <li>If no match is found, and the type sought is an integer type, then the |
| 1241 | smallest integer type that is larger than the bitwidth of the sought type is |
| 1242 | used. If none of the specifications are larger than the bitwidth then the the |
| 1243 | largest integer type is used. For example, given the default specifications |
| 1244 | above, the i7 type will use the alignment of i8 (next largest) while both |
| 1245 | i65 and i256 will use the alignment of i64 (largest specified).</li> |
| 1246 | <li>If no match is found, and the type sought is a vector type, then the |
| 1247 | largest vector type that is smaller than the sought vector type will be used |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 1248 | as a fall back. This happens because <128 x double> can be implemented |
| 1249 | in terms of 64 <2 x double>, for example.</li> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1250 | </ol> |
| 1251 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1252 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1253 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1254 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> |
| 1255 | <!-- *********************************************************************** --> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1256 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1257 | <div class="doc_text"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1258 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1259 | <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] | 1260 | intermediate representation. Being typed enables a number of |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 1261 | optimizations to be performed on the intermediate representation directly, |
| 1262 | without having to do |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1263 | extra analyses on the side before the transformation. A strong type |
| 1264 | system makes it easier to read the generated code and enables novel |
| 1265 | analyses and transformations that are not feasible to perform on normal |
| 1266 | three address code representations.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1267 | |
| 1268 | </div> |
| 1269 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1270 | <!-- ======================================================================= --> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1271 | <div class="doc_subsection"> <a name="t_classifications">Type |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1272 | Classifications</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1273 | <div class="doc_text"> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1274 | <p>The types fall into a few useful |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1275 | classifications:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1276 | |
| 1277 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1278 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1279 | <tr><th>Classification</th><th>Types</th></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1280 | <tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1281 | <td><a href="#t_integer">integer</a></td> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1282 | <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1283 | </tr> |
| 1284 | <tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1285 | <td><a href="#t_floating">floating point</a></td> |
| 1286 | <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1287 | </tr> |
| 1288 | <tr> |
| 1289 | <td><a name="t_firstclass">first class</a></td> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1290 | <td><a href="#t_integer">integer</a>, |
| 1291 | <a href="#t_floating">floating point</a>, |
| 1292 | <a href="#t_pointer">pointer</a>, |
Dan Gohman | 0066db6 | 2008-06-18 18:42:13 +0000 | [diff] [blame] | 1293 | <a href="#t_vector">vector</a>, |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 1294 | <a href="#t_struct">structure</a>, |
| 1295 | <a href="#t_array">array</a>, |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 1296 | <a href="#t_label">label</a>, |
| 1297 | <a href="#t_metadata">metadata</a>. |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1298 | </td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1299 | </tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1300 | <tr> |
| 1301 | <td><a href="#t_primitive">primitive</a></td> |
| 1302 | <td><a href="#t_label">label</a>, |
| 1303 | <a href="#t_void">void</a>, |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 1304 | <a href="#t_floating">floating point</a>, |
| 1305 | <a href="#t_metadata">metadata</a>.</td> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1306 | </tr> |
| 1307 | <tr> |
| 1308 | <td><a href="#t_derived">derived</a></td> |
| 1309 | <td><a href="#t_integer">integer</a>, |
| 1310 | <a href="#t_array">array</a>, |
| 1311 | <a href="#t_function">function</a>, |
| 1312 | <a href="#t_pointer">pointer</a>, |
| 1313 | <a href="#t_struct">structure</a>, |
| 1314 | <a href="#t_pstruct">packed structure</a>, |
| 1315 | <a href="#t_vector">vector</a>, |
| 1316 | <a href="#t_opaque">opaque</a>. |
Dan Gohman | 01ac101 | 2008-10-14 16:32:04 +0000 | [diff] [blame] | 1317 | </td> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1318 | </tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1319 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1320 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1321 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1322 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the |
| 1323 | most important. Values of these types are the only ones which can be |
| 1324 | produced by instructions, passed as arguments, or used as operands to |
Dan Gohman | c4b49eb | 2008-05-23 21:53:15 +0000 | [diff] [blame] | 1325 | instructions.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1326 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1327 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1328 | <!-- ======================================================================= --> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1329 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> |
Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1330 | |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1331 | <div class="doc_text"> |
| 1332 | <p>The primitive types are the fundamental building blocks of the LLVM |
| 1333 | system.</p> |
| 1334 | |
Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1335 | </div> |
| 1336 | |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1337 | <!-- _______________________________________________________________________ --> |
| 1338 | <div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div> |
| 1339 | |
| 1340 | <div class="doc_text"> |
| 1341 | <table> |
| 1342 | <tbody> |
| 1343 | <tr><th>Type</th><th>Description</th></tr> |
| 1344 | <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr> |
| 1345 | <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr> |
| 1346 | <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr> |
| 1347 | <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr> |
| 1348 | <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr> |
| 1349 | </tbody> |
| 1350 | </table> |
| 1351 | </div> |
| 1352 | |
| 1353 | <!-- _______________________________________________________________________ --> |
| 1354 | <div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div> |
| 1355 | |
| 1356 | <div class="doc_text"> |
| 1357 | <h5>Overview:</h5> |
| 1358 | <p>The void type does not represent any value and has no size.</p> |
| 1359 | |
| 1360 | <h5>Syntax:</h5> |
| 1361 | |
| 1362 | <pre> |
| 1363 | void |
| 1364 | </pre> |
| 1365 | </div> |
| 1366 | |
| 1367 | <!-- _______________________________________________________________________ --> |
| 1368 | <div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div> |
| 1369 | |
| 1370 | <div class="doc_text"> |
| 1371 | <h5>Overview:</h5> |
| 1372 | <p>The label type represents code labels.</p> |
| 1373 | |
| 1374 | <h5>Syntax:</h5> |
| 1375 | |
| 1376 | <pre> |
| 1377 | label |
| 1378 | </pre> |
| 1379 | </div> |
| 1380 | |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 1381 | <!-- _______________________________________________________________________ --> |
| 1382 | <div class="doc_subsubsection"> <a name="t_metadata">Metadata Type</a> </div> |
| 1383 | |
| 1384 | <div class="doc_text"> |
| 1385 | <h5>Overview:</h5> |
| 1386 | <p>The metadata type represents embedded metadata. The only derived type that |
| 1387 | may contain metadata is <tt>metadata*</tt> or a function type that returns or |
| 1388 | takes metadata typed parameters, but not pointer to metadata types.</p> |
| 1389 | |
| 1390 | <h5>Syntax:</h5> |
| 1391 | |
| 1392 | <pre> |
| 1393 | metadata |
| 1394 | </pre> |
| 1395 | </div> |
| 1396 | |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1397 | |
| 1398 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1399 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1400 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1401 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1402 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1403 | <p>The real power in LLVM comes from the derived types in the system. |
| 1404 | This is what allows a programmer to represent arrays, functions, |
| 1405 | pointers, and other useful types. Note that these derived types may be |
| 1406 | 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] | 1407 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1408 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1409 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1410 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1411 | <div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div> |
| 1412 | |
| 1413 | <div class="doc_text"> |
| 1414 | |
| 1415 | <h5>Overview:</h5> |
| 1416 | <p>The integer type is a very simple derived type that simply specifies an |
| 1417 | arbitrary bit width for the integer type desired. Any bit width from 1 bit to |
| 1418 | 2^23-1 (about 8 million) can be specified.</p> |
| 1419 | |
| 1420 | <h5>Syntax:</h5> |
| 1421 | |
| 1422 | <pre> |
| 1423 | iN |
| 1424 | </pre> |
| 1425 | |
| 1426 | <p>The number of bits the integer will occupy is specified by the <tt>N</tt> |
| 1427 | value.</p> |
| 1428 | |
| 1429 | <h5>Examples:</h5> |
| 1430 | <table class="layout"> |
Nick Lewycky | 86c4864 | 2009-05-24 02:46:06 +0000 | [diff] [blame] | 1431 | <tr class="layout"> |
| 1432 | <td class="left"><tt>i1</tt></td> |
| 1433 | <td class="left">a single-bit integer.</td> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1434 | </tr> |
Nick Lewycky | 86c4864 | 2009-05-24 02:46:06 +0000 | [diff] [blame] | 1435 | <tr class="layout"> |
| 1436 | <td class="left"><tt>i32</tt></td> |
| 1437 | <td class="left">a 32-bit integer.</td> |
| 1438 | </tr> |
| 1439 | <tr class="layout"> |
| 1440 | <td class="left"><tt>i1942652</tt></td> |
| 1441 | <td class="left">a really big integer of over 1 million bits.</td> |
| 1442 | </tr> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1443 | </table> |
Dan Gohman | d8791e5 | 2009-01-24 15:58:40 +0000 | [diff] [blame] | 1444 | |
| 1445 | <p>Note that the code generator does not yet support large integer types |
| 1446 | to be used as function return types. The specific limit on how large a |
| 1447 | return type the code generator can currently handle is target-dependent; |
| 1448 | currently it's often 64 bits for 32-bit targets and 128 bits for 64-bit |
| 1449 | targets.</p> |
| 1450 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1451 | </div> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1452 | |
| 1453 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1454 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1455 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1456 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1457 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1458 | <h5>Overview:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1459 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1460 | <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] | 1461 | sequentially in memory. The array type requires a size (number of |
| 1462 | elements) and an underlying data type.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1463 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1464 | <h5>Syntax:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1465 | |
| 1466 | <pre> |
| 1467 | [<# elements> x <elementtype>] |
| 1468 | </pre> |
| 1469 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1470 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1471 | be any type with a size.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1472 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1473 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1474 | <table class="layout"> |
| 1475 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1476 | <td class="left"><tt>[40 x i32]</tt></td> |
| 1477 | <td class="left">Array of 40 32-bit integer values.</td> |
| 1478 | </tr> |
| 1479 | <tr class="layout"> |
| 1480 | <td class="left"><tt>[41 x i32]</tt></td> |
| 1481 | <td class="left">Array of 41 32-bit integer values.</td> |
| 1482 | </tr> |
| 1483 | <tr class="layout"> |
| 1484 | <td class="left"><tt>[4 x i8]</tt></td> |
| 1485 | <td class="left">Array of 4 8-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1486 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1487 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1488 | <p>Here are some examples of multidimensional arrays:</p> |
| 1489 | <table class="layout"> |
| 1490 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1491 | <td class="left"><tt>[3 x [4 x i32]]</tt></td> |
| 1492 | <td class="left">3x4 array of 32-bit integer values.</td> |
| 1493 | </tr> |
| 1494 | <tr class="layout"> |
| 1495 | <td class="left"><tt>[12 x [10 x float]]</tt></td> |
| 1496 | <td class="left">12x10 array of single precision floating point values.</td> |
| 1497 | </tr> |
| 1498 | <tr class="layout"> |
| 1499 | <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td> |
| 1500 | <td class="left">2x3x4 array of 16-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1501 | </tr> |
| 1502 | </table> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1503 | |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1504 | <p>Note that 'variable sized arrays' can be implemented in LLVM with a zero |
| 1505 | 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] | 1506 | LLVM (e.g. it is illegal to access the 5th element of a 3 element array). |
| 1507 | As a special case, however, zero length arrays are recognized to be variable |
| 1508 | length. This allows implementation of 'pascal style arrays' with the LLVM |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1509 | type "{ i32, [0 x float]}", for example.</p> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1510 | |
Dan Gohman | d8791e5 | 2009-01-24 15:58:40 +0000 | [diff] [blame] | 1511 | <p>Note that the code generator does not yet support large aggregate types |
| 1512 | to be used as function return types. The specific limit on how large an |
| 1513 | aggregate return type the code generator can currently handle is |
| 1514 | target-dependent, and also dependent on the aggregate element types.</p> |
| 1515 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1516 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1517 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1518 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1519 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1520 | <div class="doc_text"> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1521 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1522 | <h5>Overview:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1523 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1524 | <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] | 1525 | 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] | 1526 | 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] | 1527 | 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] | 1528 | class types, and the struct must have at least one element.</p> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1529 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1530 | <h5>Syntax:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1531 | |
| 1532 | <pre> |
| 1533 | <returntype list> (<parameter list>) |
| 1534 | </pre> |
| 1535 | |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1536 | <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] | 1537 | specifiers. Optionally, the parameter list may include a type <tt>...</tt>, |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1538 | which indicates that the function takes a variable number of arguments. |
| 1539 | Variable argument functions can access their arguments with the <a |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1540 | href="#int_varargs">variable argument handling intrinsic</a> functions. |
| 1541 | '<tt><returntype list></tt>' is a comma-separated list of |
| 1542 | <a href="#t_firstclass">first class</a> type specifiers.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1543 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1544 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1545 | <table class="layout"> |
| 1546 | <tr class="layout"> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1547 | <td class="left"><tt>i32 (i32)</tt></td> |
| 1548 | <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] | 1549 | </td> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1550 | </tr><tr class="layout"> |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 1551 | <td class="left"><tt>float (i16 signext, i32 *) * |
Reid Spencer | f17a0b7 | 2006-12-31 07:20:23 +0000 | [diff] [blame] | 1552 | </tt></td> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1553 | <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes |
| 1554 | an <tt>i16</tt> that should be sign extended and a |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1555 | <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1556 | <tt>float</tt>. |
| 1557 | </td> |
| 1558 | </tr><tr class="layout"> |
| 1559 | <td class="left"><tt>i32 (i8*, ...)</tt></td> |
| 1560 | <td class="left">A vararg function that takes at least one |
Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1561 | <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] | 1562 | which returns an integer. This is the signature for <tt>printf</tt> in |
| 1563 | LLVM. |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1564 | </td> |
Devang Patel | a582f40 | 2008-03-24 05:35:41 +0000 | [diff] [blame] | 1565 | </tr><tr class="layout"> |
| 1566 | <td class="left"><tt>{i32, i32} (i32)</tt></td> |
Misha Brukman | b0a57aa | 2008-11-27 06:41:20 +0000 | [diff] [blame] | 1567 | <td class="left">A function taking an <tt>i32</tt>, returning two |
| 1568 | <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] | 1569 | </td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1570 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1571 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1572 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1573 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1574 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1575 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1576 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1577 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1578 | <p>The structure type is used to represent a collection of data members |
| 1579 | together in memory. The packing of the field types is defined to match |
| 1580 | the ABI of the underlying processor. The elements of a structure may |
| 1581 | be any type that has a size.</p> |
| 1582 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 1583 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 1584 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 1585 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1586 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1587 | <pre> { <type list> }<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1588 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1589 | <table class="layout"> |
| 1590 | <tr class="layout"> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1591 | <td class="left"><tt>{ i32, i32, i32 }</tt></td> |
| 1592 | <td class="left">A triple of three <tt>i32</tt> values</td> |
| 1593 | </tr><tr class="layout"> |
| 1594 | <td class="left"><tt>{ float, i32 (i32) * }</tt></td> |
| 1595 | <td class="left">A pair, where the first element is a <tt>float</tt> and the |
| 1596 | second element is a <a href="#t_pointer">pointer</a> to a |
| 1597 | <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning |
| 1598 | an <tt>i32</tt>.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1599 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1600 | </table> |
Dan Gohman | d8791e5 | 2009-01-24 15:58:40 +0000 | [diff] [blame] | 1601 | |
| 1602 | <p>Note that the code generator does not yet support large aggregate types |
| 1603 | to be used as function return types. The specific limit on how large an |
| 1604 | aggregate return type the code generator can currently handle is |
| 1605 | target-dependent, and also dependent on the aggregate element types.</p> |
| 1606 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1607 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1608 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1609 | <!-- _______________________________________________________________________ --> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1610 | <div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a> |
| 1611 | </div> |
| 1612 | <div class="doc_text"> |
| 1613 | <h5>Overview:</h5> |
| 1614 | <p>The packed structure type is used to represent a collection of data members |
| 1615 | together in memory. There is no padding between fields. Further, the alignment |
| 1616 | of a packed structure is 1 byte. The elements of a packed structure may |
| 1617 | be any type that has a size.</p> |
| 1618 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 1619 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 1620 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 1621 | instruction.</p> |
| 1622 | <h5>Syntax:</h5> |
| 1623 | <pre> < { <type list> } > <br></pre> |
| 1624 | <h5>Examples:</h5> |
| 1625 | <table class="layout"> |
| 1626 | <tr class="layout"> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1627 | <td class="left"><tt>< { i32, i32, i32 } ></tt></td> |
| 1628 | <td class="left">A triple of three <tt>i32</tt> values</td> |
| 1629 | </tr><tr class="layout"> |
Bill Wendling | e36dccc | 2008-09-07 10:26:33 +0000 | [diff] [blame] | 1630 | <td class="left"> |
| 1631 | <tt>< { float, i32 (i32)* } ></tt></td> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1632 | <td class="left">A pair, where the first element is a <tt>float</tt> and the |
| 1633 | second element is a <a href="#t_pointer">pointer</a> to a |
| 1634 | <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning |
| 1635 | an <tt>i32</tt>.</td> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1636 | </tr> |
| 1637 | </table> |
| 1638 | </div> |
| 1639 | |
| 1640 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1641 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1642 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1643 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1644 | <p>As in many languages, the pointer type represents a pointer or |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 1645 | reference to another object, which must live in memory. Pointer types may have |
| 1646 | an optional address space attribute defining the target-specific numbered |
| 1647 | address space where the pointed-to object resides. The default address space is |
| 1648 | zero.</p> |
Chris Lattner | 0fd4a27 | 2009-02-08 19:53:29 +0000 | [diff] [blame] | 1649 | |
| 1650 | <p>Note that LLVM does not permit pointers to void (<tt>void*</tt>) nor does |
Chris Lattner | e220e8c | 2009-02-08 22:21:28 +0000 | [diff] [blame] | 1651 | it permit pointers to labels (<tt>label*</tt>). Use <tt>i8*</tt> instead.</p> |
Chris Lattner | 0fd4a27 | 2009-02-08 19:53:29 +0000 | [diff] [blame] | 1652 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1653 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1654 | <pre> <type> *<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1655 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1656 | <table class="layout"> |
| 1657 | <tr class="layout"> |
Dan Gohman | 2a08c53 | 2009-01-04 23:44:43 +0000 | [diff] [blame] | 1658 | <td class="left"><tt>[4 x i32]*</tt></td> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1659 | <td class="left">A <a href="#t_pointer">pointer</a> to <a |
| 1660 | href="#t_array">array</a> of four <tt>i32</tt> values.</td> |
| 1661 | </tr> |
| 1662 | <tr class="layout"> |
| 1663 | <td class="left"><tt>i32 (i32 *) *</tt></td> |
| 1664 | <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] | 1665 | 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] | 1666 | <tt>i32</tt>.</td> |
| 1667 | </tr> |
| 1668 | <tr class="layout"> |
| 1669 | <td class="left"><tt>i32 addrspace(5)*</tt></td> |
| 1670 | <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value |
| 1671 | that resides in address space #5.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1672 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1673 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1674 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1675 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1676 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1677 | <div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1678 | <div class="doc_text"> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1679 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1680 | <h5>Overview:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1681 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1682 | <p>A vector type is a simple derived type that represents a vector |
| 1683 | of elements. Vector types are used when multiple primitive data |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1684 | are operated in parallel using a single instruction (SIMD). |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1685 | A vector type requires a size (number of |
Chris Lattner | b8d172f | 2005-11-10 01:44:22 +0000 | [diff] [blame] | 1686 | elements) and an underlying primitive data type. Vectors must have a power |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1687 | of two length (1, 2, 4, 8, 16 ...). Vector types are |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1688 | considered <a href="#t_firstclass">first class</a>.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1689 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1690 | <h5>Syntax:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1691 | |
| 1692 | <pre> |
| 1693 | < <# elements> x <elementtype> > |
| 1694 | </pre> |
| 1695 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1696 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1697 | be any integer or floating point type.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1698 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1699 | <h5>Examples:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1700 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1701 | <table class="layout"> |
| 1702 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1703 | <td class="left"><tt><4 x i32></tt></td> |
| 1704 | <td class="left">Vector of 4 32-bit integer values.</td> |
| 1705 | </tr> |
| 1706 | <tr class="layout"> |
| 1707 | <td class="left"><tt><8 x float></tt></td> |
| 1708 | <td class="left">Vector of 8 32-bit floating-point values.</td> |
| 1709 | </tr> |
| 1710 | <tr class="layout"> |
| 1711 | <td class="left"><tt><2 x i64></tt></td> |
| 1712 | <td class="left">Vector of 2 64-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1713 | </tr> |
| 1714 | </table> |
Dan Gohman | d8791e5 | 2009-01-24 15:58:40 +0000 | [diff] [blame] | 1715 | |
| 1716 | <p>Note that the code generator does not yet support large vector types |
| 1717 | to be used as function return types. The specific limit on how large a |
| 1718 | vector return type codegen can currently handle is target-dependent; |
| 1719 | currently it's often a few times longer than a hardware vector register.</p> |
| 1720 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1721 | </div> |
| 1722 | |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1723 | <!-- _______________________________________________________________________ --> |
| 1724 | <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div> |
| 1725 | <div class="doc_text"> |
| 1726 | |
| 1727 | <h5>Overview:</h5> |
| 1728 | |
| 1729 | <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] | 1730 | 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] | 1731 | In LLVM, opaque types can eventually be resolved to any type (not just a |
| 1732 | structure type).</p> |
| 1733 | |
| 1734 | <h5>Syntax:</h5> |
| 1735 | |
| 1736 | <pre> |
| 1737 | opaque |
| 1738 | </pre> |
| 1739 | |
| 1740 | <h5>Examples:</h5> |
| 1741 | |
| 1742 | <table class="layout"> |
| 1743 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1744 | <td class="left"><tt>opaque</tt></td> |
| 1745 | <td class="left">An opaque type.</td> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1746 | </tr> |
| 1747 | </table> |
| 1748 | </div> |
| 1749 | |
Chris Lattner | 242d61d | 2009-02-02 07:32:36 +0000 | [diff] [blame] | 1750 | <!-- ======================================================================= --> |
| 1751 | <div class="doc_subsection"> |
| 1752 | <a name="t_uprefs">Type Up-references</a> |
| 1753 | </div> |
| 1754 | |
| 1755 | <div class="doc_text"> |
| 1756 | <h5>Overview:</h5> |
| 1757 | <p> |
| 1758 | An "up reference" allows you to refer to a lexically enclosing type without |
| 1759 | requiring it to have a name. For instance, a structure declaration may contain a |
| 1760 | pointer to any of the types it is lexically a member of. Example of up |
| 1761 | references (with their equivalent as named type declarations) include:</p> |
| 1762 | |
| 1763 | <pre> |
Chris Lattner | 3060f5b | 2009-02-09 10:00:56 +0000 | [diff] [blame] | 1764 | { \2 * } %x = type { %x* } |
Chris Lattner | 242d61d | 2009-02-02 07:32:36 +0000 | [diff] [blame] | 1765 | { \2 }* %y = type { %y }* |
| 1766 | \1* %z = type %z* |
| 1767 | </pre> |
| 1768 | |
| 1769 | <p> |
| 1770 | An up reference is needed by the asmprinter for printing out cyclic types when |
| 1771 | there is no declared name for a type in the cycle. Because the asmprinter does |
| 1772 | not want to print out an infinite type string, it needs a syntax to handle |
| 1773 | recursive types that have no names (all names are optional in llvm IR). |
| 1774 | </p> |
| 1775 | |
| 1776 | <h5>Syntax:</h5> |
| 1777 | <pre> |
| 1778 | \<level> |
| 1779 | </pre> |
| 1780 | |
| 1781 | <p> |
| 1782 | The level is the count of the lexical type that is being referred to. |
| 1783 | </p> |
| 1784 | |
| 1785 | <h5>Examples:</h5> |
| 1786 | |
| 1787 | <table class="layout"> |
| 1788 | <tr class="layout"> |
| 1789 | <td class="left"><tt>\1*</tt></td> |
| 1790 | <td class="left">Self-referential pointer.</td> |
| 1791 | </tr> |
| 1792 | <tr class="layout"> |
| 1793 | <td class="left"><tt>{ { \3*, i8 }, i32 }</tt></td> |
| 1794 | <td class="left">Recursive structure where the upref refers to the out-most |
| 1795 | structure.</td> |
| 1796 | </tr> |
| 1797 | </table> |
| 1798 | </div> |
| 1799 | |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1800 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1801 | <!-- *********************************************************************** --> |
| 1802 | <div class="doc_section"> <a name="constants">Constants</a> </div> |
| 1803 | <!-- *********************************************************************** --> |
| 1804 | |
| 1805 | <div class="doc_text"> |
| 1806 | |
| 1807 | <p>LLVM has several different basic types of constants. This section describes |
| 1808 | them all and their syntax.</p> |
| 1809 | |
| 1810 | </div> |
| 1811 | |
| 1812 | <!-- ======================================================================= --> |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1813 | <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1814 | |
| 1815 | <div class="doc_text"> |
| 1816 | |
| 1817 | <dl> |
| 1818 | <dt><b>Boolean constants</b></dt> |
| 1819 | |
| 1820 | <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] | 1821 | constants of the <tt><a href="#t_primitive">i1</a></tt> type. |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1822 | </dd> |
| 1823 | |
| 1824 | <dt><b>Integer constants</b></dt> |
| 1825 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1826 | <dd>Standard integers (such as '4') are constants of the <a |
Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1827 | href="#t_integer">integer</a> type. Negative numbers may be used with |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1828 | integer types. |
| 1829 | </dd> |
| 1830 | |
| 1831 | <dt><b>Floating point constants</b></dt> |
| 1832 | |
| 1833 | <dd>Floating point constants use standard decimal notation (e.g. 123.421), |
| 1834 | exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 1835 | notation (see below). The assembler requires the exact decimal value of |
| 1836 | a floating-point constant. For example, the assembler accepts 1.25 but |
| 1837 | rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point |
| 1838 | 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] | 1839 | |
| 1840 | <dt><b>Null pointer constants</b></dt> |
| 1841 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1842 | <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] | 1843 | and must be of <a href="#t_pointer">pointer type</a>.</dd> |
| 1844 | |
| 1845 | </dl> |
| 1846 | |
Dale Johannesen | bd5e5a8 | 2009-02-11 22:14:51 +0000 | [diff] [blame] | 1847 | <p>The one non-intuitive notation for constants is the hexadecimal form |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1848 | of floating point constants. For example, the form '<tt>double |
| 1849 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double |
| 1850 | 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] | 1851 | (and the only time that they are generated by the disassembler) is when a |
| 1852 | floating point constant must be emitted but it cannot be represented as a |
Dale Johannesen | bd5e5a8 | 2009-02-11 22:14:51 +0000 | [diff] [blame] | 1853 | decimal floating point number in a reasonable number of digits. For example, |
| 1854 | NaN's, infinities, and other |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1855 | special values are represented in their IEEE hexadecimal format so that |
| 1856 | assembly and disassembly do not cause any bits to change in the constants.</p> |
Dale Johannesen | bd5e5a8 | 2009-02-11 22:14:51 +0000 | [diff] [blame] | 1857 | <p>When using the hexadecimal form, constants of types float and double are |
| 1858 | represented using the 16-digit form shown above (which matches the IEEE754 |
| 1859 | representation for double); float values must, however, be exactly representable |
| 1860 | as IEE754 single precision. |
| 1861 | Hexadecimal format is always used for long |
| 1862 | double, and there are three forms of long double. The 80-bit |
| 1863 | format used by x86 is represented as <tt>0xK</tt> |
| 1864 | followed by 20 hexadecimal digits. |
| 1865 | The 128-bit format used by PowerPC (two adjacent doubles) is represented |
| 1866 | by <tt>0xM</tt> followed by 32 hexadecimal digits. The IEEE 128-bit |
| 1867 | format is represented |
| 1868 | by <tt>0xL</tt> followed by 32 hexadecimal digits; no currently supported |
| 1869 | target uses this format. Long doubles will only work if they match |
| 1870 | the long double format on your target. All hexadecimal formats are big-endian |
| 1871 | (sign bit at the left).</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1872 | </div> |
| 1873 | |
| 1874 | <!-- ======================================================================= --> |
Chris Lattner | 7088279 | 2009-02-28 18:32:25 +0000 | [diff] [blame] | 1875 | <div class="doc_subsection"> |
| 1876 | <a name="aggregateconstants"> <!-- old anchor --> |
| 1877 | <a name="complexconstants">Complex Constants</a></a> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1878 | </div> |
| 1879 | |
| 1880 | <div class="doc_text"> |
Chris Lattner | 7088279 | 2009-02-28 18:32:25 +0000 | [diff] [blame] | 1881 | <p>Complex constants are a (potentially recursive) combination of simple |
| 1882 | constants and smaller complex constants.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1883 | |
| 1884 | <dl> |
| 1885 | <dt><b>Structure constants</b></dt> |
| 1886 | |
| 1887 | <dd>Structure constants are represented with notation similar to structure |
| 1888 | type definitions (a comma separated list of elements, surrounded by braces |
Chris Lattner | 64910ee | 2007-12-25 20:34:52 +0000 | [diff] [blame] | 1889 | (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>", |
| 1890 | 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] | 1891 | 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] | 1892 | types of elements must match those specified by the type. |
| 1893 | </dd> |
| 1894 | |
| 1895 | <dt><b>Array constants</b></dt> |
| 1896 | |
| 1897 | <dd>Array constants are represented with notation similar to array type |
| 1898 | definitions (a comma separated list of elements, surrounded by square brackets |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1899 | (<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] | 1900 | constants must have <a href="#t_array">array type</a>, and the number and |
| 1901 | types of elements must match those specified by the type. |
| 1902 | </dd> |
| 1903 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1904 | <dt><b>Vector constants</b></dt> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1905 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1906 | <dd>Vector constants are represented with notation similar to vector type |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1907 | definitions (a comma separated list of elements, surrounded by |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1908 | less-than/greater-than's (<tt><></tt>)). For example: "<tt>< i32 42, |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1909 | i32 11, i32 74, i32 100 ></tt>". Vector constants must have <a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1910 | 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] | 1911 | match those specified by the type. |
| 1912 | </dd> |
| 1913 | |
| 1914 | <dt><b>Zero initialization</b></dt> |
| 1915 | |
| 1916 | <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a |
| 1917 | value to zero of <em>any</em> type, including scalar and aggregate types. |
| 1918 | 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] | 1919 | large arrays) and is always exactly equivalent to using explicit zero |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1920 | initializers. |
| 1921 | </dd> |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 1922 | |
| 1923 | <dt><b>Metadata node</b></dt> |
| 1924 | |
Nick Lewycky | 1e8c7a6 | 2009-05-30 16:08:30 +0000 | [diff] [blame] | 1925 | <dd>A metadata node is a structure-like constant with |
| 1926 | <a href="#t_metadata">metadata type</a>. For example: |
| 1927 | "<tt>metadata !{ i32 0, metadata !"test" }</tt>". Unlike other constants |
| 1928 | that are meant to be interpreted as part of the instruction stream, metadata |
| 1929 | is a place to attach additional information such as debug info. |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 1930 | </dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1931 | </dl> |
| 1932 | |
| 1933 | </div> |
| 1934 | |
| 1935 | <!-- ======================================================================= --> |
| 1936 | <div class="doc_subsection"> |
| 1937 | <a name="globalconstants">Global Variable and Function Addresses</a> |
| 1938 | </div> |
| 1939 | |
| 1940 | <div class="doc_text"> |
| 1941 | |
| 1942 | <p>The addresses of <a href="#globalvars">global variables</a> and <a |
| 1943 | href="#functionstructure">functions</a> are always implicitly valid (link-time) |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1944 | constants. These constants are explicitly referenced when the <a |
| 1945 | 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] | 1946 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM |
| 1947 | file:</p> |
| 1948 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1949 | <div class="doc_code"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1950 | <pre> |
Chris Lattner | a18a424 | 2007-06-06 18:28:13 +0000 | [diff] [blame] | 1951 | @X = global i32 17 |
| 1952 | @Y = global i32 42 |
| 1953 | @Z = global [2 x i32*] [ i32* @X, i32* @Y ] |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1954 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1955 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1956 | |
| 1957 | </div> |
| 1958 | |
| 1959 | <!-- ======================================================================= --> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1960 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1961 | <div class="doc_text"> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1962 | <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] | 1963 | 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] | 1964 | a constant is permitted.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1965 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1966 | <p>Undefined values indicate to the compiler that the program is well defined |
| 1967 | no matter what value is used, giving the compiler more freedom to optimize. |
| 1968 | </p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1969 | </div> |
| 1970 | |
| 1971 | <!-- ======================================================================= --> |
| 1972 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> |
| 1973 | </div> |
| 1974 | |
| 1975 | <div class="doc_text"> |
| 1976 | |
| 1977 | <p>Constant expressions are used to allow expressions involving other constants |
| 1978 | to be used as constants. Constant expressions may be of any <a |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1979 | 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] | 1980 | that does not have side effects (e.g. load and call are not supported). The |
| 1981 | following is the syntax for constant expressions:</p> |
| 1982 | |
| 1983 | <dl> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1984 | <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt> |
| 1985 | <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] | 1986 | than the bit size of TYPE. Both types must be integers.</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1987 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1988 | <dt><b><tt>zext ( CST to TYPE )</tt></b></dt> |
| 1989 | <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] | 1990 | 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] | 1991 | |
| 1992 | <dt><b><tt>sext ( CST to TYPE )</tt></b></dt> |
| 1993 | <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] | 1994 | 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] | 1995 | |
| 1996 | <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt> |
| 1997 | <dd>Truncate a floating point constant to another floating point type. The |
| 1998 | size of CST must be larger than the size of TYPE. Both types must be |
| 1999 | floating point.</dd> |
| 2000 | |
| 2001 | <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt> |
| 2002 | <dd>Floating point extend a constant to another type. The size of CST must be |
| 2003 | smaller or equal to the size of TYPE. Both types must be floating point.</dd> |
| 2004 | |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 2005 | <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2006 | <dd>Convert a floating point constant to the corresponding unsigned integer |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 2007 | constant. TYPE must be a scalar or vector integer type. CST must be of scalar |
| 2008 | or vector floating point type. Both CST and TYPE must be scalars, or vectors |
| 2009 | of the same number of elements. If the value won't fit in the integer type, |
| 2010 | the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2011 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 2012 | <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2013 | <dd>Convert a floating point constant to the corresponding signed integer |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 2014 | constant. TYPE must be a scalar or vector integer type. CST must be of scalar |
| 2015 | or vector floating point type. Both CST and TYPE must be scalars, or vectors |
| 2016 | of the same number of elements. If the value won't fit in the integer type, |
| 2017 | the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2018 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 2019 | <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2020 | <dd>Convert an unsigned integer constant to the corresponding floating point |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 2021 | constant. TYPE must be a scalar or vector floating point type. CST must be of |
| 2022 | scalar or vector integer type. Both CST and TYPE must be scalars, or vectors |
| 2023 | of the same number of elements. If the value won't fit in the floating point |
| 2024 | type, the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2025 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 2026 | <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2027 | <dd>Convert a signed integer constant to the corresponding floating point |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 2028 | constant. TYPE must be a scalar or vector floating point type. CST must be of |
| 2029 | scalar or vector integer type. Both CST and TYPE must be scalars, or vectors |
| 2030 | of the same number of elements. If the value won't fit in the floating point |
| 2031 | type, the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2032 | |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 2033 | <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt> |
| 2034 | <dd>Convert a pointer typed constant to the corresponding integer constant |
| 2035 | TYPE must be an integer type. CST must be of pointer type. The CST value is |
| 2036 | zero extended, truncated, or unchanged to make it fit in TYPE.</dd> |
| 2037 | |
| 2038 | <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt> |
| 2039 | <dd>Convert a integer constant to a pointer constant. TYPE must be a |
| 2040 | pointer type. CST must be of integer type. The CST value is zero extended, |
| 2041 | truncated, or unchanged to make it fit in a pointer size. This one is |
| 2042 | <i>really</i> dangerous!</dd> |
| 2043 | |
| 2044 | <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt> |
Chris Lattner | 03bbad6 | 2009-02-28 18:27:03 +0000 | [diff] [blame] | 2045 | <dd>Convert a constant, CST, to another TYPE. The constraints of the operands |
| 2046 | are the same as those for the <a href="#i_bitcast">bitcast |
| 2047 | instruction</a>.</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2048 | |
| 2049 | <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> |
| 2050 | |
| 2051 | <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on |
| 2052 | constants. As with the <a href="#i_getelementptr">getelementptr</a> |
| 2053 | instruction, the index list may have zero or more indexes, which are required |
| 2054 | to make sense for the type of "CSTPTR".</dd> |
| 2055 | |
Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 2056 | <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt> |
| 2057 | |
| 2058 | <dd>Perform the <a href="#i_select">select operation</a> on |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 2059 | constants.</dd> |
| 2060 | |
| 2061 | <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 2062 | <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd> |
| 2063 | |
| 2064 | <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 2065 | <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] | 2066 | |
| 2067 | <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt> |
| 2068 | |
| 2069 | <dd>Perform the <a href="#i_extractelement">extractelement |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 2070 | operation</a> on constants.</dd> |
Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 2071 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 2072 | <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt> |
| 2073 | |
| 2074 | <dd>Perform the <a href="#i_insertelement">insertelement |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 2075 | operation</a> on constants.</dd> |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 2076 | |
Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 2077 | |
| 2078 | <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt> |
| 2079 | |
| 2080 | <dd>Perform the <a href="#i_shufflevector">shufflevector |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 2081 | operation</a> on constants.</dd> |
Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 2082 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2083 | <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> |
| 2084 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 2085 | <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may |
| 2086 | 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] | 2087 | binary</a> operations. The constraints on operands are the same as those for |
| 2088 | the corresponding instruction (e.g. no bitwise operations on floating point |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 2089 | values are allowed).</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2090 | </dl> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2091 | </div> |
Chris Lattner | 9ee5d22 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 2092 | |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2093 | <!-- ======================================================================= --> |
| 2094 | <div class="doc_subsection"><a name="metadata">Embedded Metadata</a> |
| 2095 | </div> |
| 2096 | |
| 2097 | <div class="doc_text"> |
| 2098 | |
| 2099 | <p>Embedded metadata provides a way to attach arbitrary data to the |
| 2100 | instruction stream without affecting the behaviour of the program. There are |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 2101 | two metadata primitives, strings and nodes. All metadata has the |
| 2102 | <tt>metadata</tt> type and is identified in syntax by a preceding exclamation |
| 2103 | point ('<tt>!</tt>'). |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2104 | </p> |
| 2105 | |
| 2106 | <p>A metadata string is a string surrounded by double quotes. It can contain |
| 2107 | any character by escaping non-printable characters with "\xx" where "xx" is |
| 2108 | the two digit hex code. For example: "<tt>!"test\00"</tt>". |
| 2109 | </p> |
| 2110 | |
| 2111 | <p>Metadata nodes are represented with notation similar to structure constants |
| 2112 | (a comma separated list of elements, surrounded by braces and preceeded by an |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 2113 | exclamation point). For example: "<tt>!{ metadata !"test\00", i32 10}</tt>". |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2114 | </p> |
| 2115 | |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 2116 | <p>A metadata node will attempt to track changes to the values it holds. In |
| 2117 | the event that a value is deleted, it will be replaced with a typeless |
Nick Lewycky | 7a0370f | 2009-05-30 05:06:04 +0000 | [diff] [blame] | 2118 | "<tt>null</tt>", such as "<tt>metadata !{null, i32 10}</tt>".</p> |
Nick Lewycky | cb33799 | 2009-05-10 20:57:05 +0000 | [diff] [blame] | 2119 | |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 2120 | <p>Optimizations may rely on metadata to provide additional information about |
| 2121 | the program that isn't available in the instructions, or that isn't easily |
| 2122 | computable. Similarly, the code generator may expect a certain metadata format |
| 2123 | to be used to express debugging information.</p> |
| 2124 | </div> |
| 2125 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2126 | <!-- *********************************************************************** --> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2127 | <div class="doc_section"> <a name="othervalues">Other Values</a> </div> |
| 2128 | <!-- *********************************************************************** --> |
| 2129 | |
| 2130 | <!-- ======================================================================= --> |
| 2131 | <div class="doc_subsection"> |
| 2132 | <a name="inlineasm">Inline Assembler Expressions</a> |
| 2133 | </div> |
| 2134 | |
| 2135 | <div class="doc_text"> |
| 2136 | |
| 2137 | <p> |
| 2138 | LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm"> |
| 2139 | Module-Level Inline Assembly</a>) through the use of a special value. This |
| 2140 | value represents the inline assembler as a string (containing the instructions |
| 2141 | to emit), a list of operand constraints (stored as a string), and a flag that |
| 2142 | indicates whether or not the inline asm expression has side effects. An example |
| 2143 | inline assembler expression is: |
| 2144 | </p> |
| 2145 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2146 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2147 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2148 | i32 (i32) asm "bswap $0", "=r,r" |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2149 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2150 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2151 | |
| 2152 | <p> |
| 2153 | Inline assembler expressions may <b>only</b> be used as the callee operand of |
| 2154 | a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have: |
| 2155 | </p> |
| 2156 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2157 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2158 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2159 | %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] | 2160 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2161 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2162 | |
| 2163 | <p> |
| 2164 | Inline asms with side effects not visible in the constraint list must be marked |
| 2165 | as having side effects. This is done through the use of the |
| 2166 | '<tt>sideeffect</tt>' keyword, like so: |
| 2167 | </p> |
| 2168 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2169 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2170 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2171 | call void asm sideeffect "eieio", ""() |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2172 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2173 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2174 | |
| 2175 | <p>TODO: The format of the asm and constraints string still need to be |
| 2176 | documented here. Constraints on what can be done (e.g. duplication, moving, etc |
Chris Lattner | 4f99335 | 2008-10-04 18:36:02 +0000 | [diff] [blame] | 2177 | need to be documented). This is probably best done by reference to another |
| 2178 | document that covers inline asm from a holistic perspective. |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 2179 | </p> |
| 2180 | |
| 2181 | </div> |
| 2182 | |
| 2183 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2184 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> |
| 2185 | <!-- *********************************************************************** --> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2186 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2187 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2188 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2189 | <p>The LLVM instruction set consists of several different |
| 2190 | classifications of instructions: <a href="#terminators">terminator |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2191 | instructions</a>, <a href="#binaryops">binary instructions</a>, |
| 2192 | <a href="#bitwiseops">bitwise binary instructions</a>, <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2193 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other |
| 2194 | instructions</a>.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2195 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2196 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2197 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2198 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2199 | <div class="doc_subsection"> <a name="terminators">Terminator |
| 2200 | Instructions</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2201 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2202 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2203 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2204 | <p>As mentioned <a href="#functionstructure">previously</a>, every |
| 2205 | basic block in a program ends with a "Terminator" instruction, which |
| 2206 | indicates which block should be executed after the current block is |
| 2207 | finished. These terminator instructions typically yield a '<tt>void</tt>' |
| 2208 | value: they produce control flow, not values (the one exception being |
| 2209 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2210 | <p>There are six different terminator instructions: the '<a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2211 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' |
| 2212 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2213 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a |
| 2214 | href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a |
| 2215 | href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2216 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2217 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 2218 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2219 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2220 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' |
| 2221 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2222 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2223 | <h5>Syntax:</h5> |
Dan Gohman | b1e6b96 | 2008-10-04 19:00:07 +0000 | [diff] [blame] | 2224 | <pre> |
| 2225 | 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] | 2226 | ret void <i>; Return from void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2227 | </pre> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2228 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2229 | <h5>Overview:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2230 | |
Dan Gohman | b1e6b96 | 2008-10-04 19:00:07 +0000 | [diff] [blame] | 2231 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and |
| 2232 | optionally a value) from a function back to the caller.</p> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 2233 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that |
Dan Gohman | b1e6b96 | 2008-10-04 19:00:07 +0000 | [diff] [blame] | 2234 | returns a value and then causes control flow, and one that just causes |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2235 | control flow to occur.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2236 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2237 | <h5>Arguments:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2238 | |
Dan Gohman | b1e6b96 | 2008-10-04 19:00:07 +0000 | [diff] [blame] | 2239 | <p>The '<tt>ret</tt>' instruction optionally accepts a single argument, |
| 2240 | the return value. The type of the return value must be a |
| 2241 | '<a href="#t_firstclass">first class</a>' type.</p> |
| 2242 | |
| 2243 | <p>A function is not <a href="#wellformed">well formed</a> if |
| 2244 | it it has a non-void return type and contains a '<tt>ret</tt>' |
| 2245 | instruction with no return value or a return value with a type that |
| 2246 | does not match its type, or if it has a void return type and contains |
| 2247 | a '<tt>ret</tt>' instruction with a return value.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2248 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2249 | <h5>Semantics:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2250 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2251 | <p>When the '<tt>ret</tt>' instruction is executed, control flow |
| 2252 | 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] | 2253 | href="#i_call"><tt>call</tt></a>" instruction, execution continues at |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2254 | the instruction after the call. If the caller was an "<a |
| 2255 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 2256 | at the beginning of the "normal" destination block. If the instruction |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2257 | returns a value, that value shall set the call or invoke instruction's |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 2258 | return value.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2259 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2260 | <h5>Example:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 2261 | |
| 2262 | <pre> |
| 2263 | ret i32 5 <i>; Return an integer value of 5</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2264 | ret void <i>; Return from a void function</i> |
Bill Wendling | 0a4bbbf | 2009-02-28 22:12:54 +0000 | [diff] [blame] | 2265 | ret { i32, i8 } { i32 4, i8 2 } <i>; Return a struct of values 4 and 2</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2266 | </pre> |
Dan Gohman | f3e60bd | 2009-01-12 23:12:39 +0000 | [diff] [blame] | 2267 | |
Dan Gohman | d8791e5 | 2009-01-24 15:58:40 +0000 | [diff] [blame] | 2268 | <p>Note that the code generator does not yet fully support large |
| 2269 | return values. The specific sizes that are currently supported are |
| 2270 | dependent on the target. For integers, on 32-bit targets the limit |
| 2271 | is often 64 bits, and on 64-bit targets the limit is often 128 bits. |
| 2272 | For aggregate types, the current limits are dependent on the element |
| 2273 | types; for example targets are often limited to 2 total integer |
| 2274 | elements and 2 total floating-point elements.</p> |
Dan Gohman | f3e60bd | 2009-01-12 23:12:39 +0000 | [diff] [blame] | 2275 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2276 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2277 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2278 | <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] | 2279 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2280 | <h5>Syntax:</h5> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 2281 | <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] | 2282 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2283 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2284 | <p>The '<tt>br</tt>' instruction is used to cause control flow to |
| 2285 | transfer to a different basic block in the current function. There are |
| 2286 | two forms of this instruction, corresponding to a conditional branch |
| 2287 | and an unconditional branch.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2288 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2289 | <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] | 2290 | single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 2291 | unconditional form of the '<tt>br</tt>' instruction takes a single |
| 2292 | '<tt>label</tt>' value as a target.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2293 | <h5>Semantics:</h5> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 2294 | <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] | 2295 | argument is evaluated. If the value is <tt>true</tt>, control flows |
| 2296 | to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>, |
| 2297 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2298 | <h5>Example:</h5> |
Chris Lattner | 60150a3 | 2009-05-09 18:11:50 +0000 | [diff] [blame] | 2299 | <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] | 2300 | 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] | 2301 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2302 | <!-- _______________________________________________________________________ --> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2303 | <div class="doc_subsubsection"> |
| 2304 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> |
| 2305 | </div> |
| 2306 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2307 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2308 | <h5>Syntax:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2309 | |
| 2310 | <pre> |
| 2311 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] |
| 2312 | </pre> |
| 2313 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2314 | <h5>Overview:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2315 | |
| 2316 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of |
| 2317 | several different places. It is a generalization of the '<tt>br</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2318 | instruction, allowing a branch to occur to one of many possible |
| 2319 | destinations.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2320 | |
| 2321 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2322 | <h5>Arguments:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2323 | |
| 2324 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer |
| 2325 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and |
| 2326 | an array of pairs of comparison value constants and '<tt>label</tt>'s. The |
| 2327 | table is not allowed to contain duplicate constant entries.</p> |
| 2328 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2329 | <h5>Semantics:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2330 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2331 | <p>The <tt>switch</tt> instruction specifies a table of values and |
| 2332 | destinations. When the '<tt>switch</tt>' instruction is executed, this |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 2333 | table is searched for the given value. If the value is found, control flow is |
| 2334 | transfered to the corresponding destination; otherwise, control flow is |
| 2335 | transfered to the default destination.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2336 | |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2337 | <h5>Implementation:</h5> |
| 2338 | |
| 2339 | <p>Depending on properties of the target machine and the particular |
| 2340 | <tt>switch</tt> instruction, this instruction may be code generated in different |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 2341 | ways. For example, it could be generated as a series of chained conditional |
| 2342 | branches or with a lookup table.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2343 | |
| 2344 | <h5>Example:</h5> |
| 2345 | |
| 2346 | <pre> |
| 2347 | <i>; Emulate a conditional br instruction</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 2348 | %Val = <a href="#i_zext">zext</a> i1 %value to i32 |
Dan Gohman | 2a08c53 | 2009-01-04 23:44:43 +0000 | [diff] [blame] | 2349 | switch i32 %Val, label %truedest [ i32 0, label %falsedest ] |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2350 | |
| 2351 | <i>; Emulate an unconditional br instruction</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2352 | switch i32 0, label %dest [ ] |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 2353 | |
| 2354 | <i>; Implement a jump table:</i> |
Dan Gohman | 2a08c53 | 2009-01-04 23:44:43 +0000 | [diff] [blame] | 2355 | switch i32 %val, label %otherwise [ i32 0, label %onzero |
| 2356 | i32 1, label %onone |
| 2357 | i32 2, label %ontwo ] |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2358 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2359 | </div> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2360 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2361 | <!-- _______________________________________________________________________ --> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2362 | <div class="doc_subsubsection"> |
| 2363 | <a name="i_invoke">'<tt>invoke</tt>' Instruction</a> |
| 2364 | </div> |
| 2365 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2366 | <div class="doc_text"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2367 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2368 | <h5>Syntax:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2369 | |
| 2370 | <pre> |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 2371 | <result> = invoke [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] <ptr to function ty> <function ptr val>(<function args>) [<a href="#fnattrs">fn attrs</a>] |
Chris Lattner | 76b8a33 | 2006-05-14 18:23:06 +0000 | [diff] [blame] | 2372 | to label <normal label> unwind label <exception label> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2373 | </pre> |
| 2374 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2375 | <h5>Overview:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2376 | |
| 2377 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified |
| 2378 | function, with the possibility of control flow transfer to either the |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 2379 | '<tt>normal</tt>' label or the |
| 2380 | '<tt>exception</tt>' label. If the callee function returns with the |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2381 | "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the |
| 2382 | "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] | 2383 | href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 2384 | continued at the dynamically nearest "exception" label.</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2385 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2386 | <h5>Arguments:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2387 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2388 | <p>This instruction requires several arguments:</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2389 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2390 | <ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2391 | <li> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 2392 | The optional "cconv" marker indicates which <a href="#callingconv">calling |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2393 | convention</a> the call should use. If none is specified, the call defaults |
| 2394 | to using C calling conventions. |
| 2395 | </li> |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 2396 | |
| 2397 | <li>The optional <a href="#paramattrs">Parameter Attributes</a> list for |
| 2398 | return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', |
| 2399 | and '<tt>inreg</tt>' attributes are valid here.</li> |
| 2400 | |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2401 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to |
| 2402 | function value being invoked. In most cases, this is a direct function |
| 2403 | invocation, but indirect <tt>invoke</tt>s are just as possible, branching off |
| 2404 | an arbitrary pointer to function value. |
| 2405 | </li> |
| 2406 | |
| 2407 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a |
| 2408 | function to be invoked. </li> |
| 2409 | |
| 2410 | <li>'<tt>function args</tt>': argument list whose types match the function |
| 2411 | signature argument types. If the function signature indicates the function |
| 2412 | accepts a variable number of arguments, the extra arguments can be |
| 2413 | specified. </li> |
| 2414 | |
| 2415 | <li>'<tt>normal label</tt>': the label reached when the called function |
| 2416 | executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> |
| 2417 | |
| 2418 | <li>'<tt>exception label</tt>': the label reached when a callee returns with |
| 2419 | the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> |
| 2420 | |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 2421 | <li>The optional <a href="#fnattrs">function attributes</a> list. Only |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 2422 | '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and |
| 2423 | '<tt>readnone</tt>' attributes are valid here.</li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2424 | </ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2425 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2426 | <h5>Semantics:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2427 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2428 | <p>This instruction is designed to operate as a standard '<tt><a |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2429 | href="#i_call">call</a></tt>' instruction in most regards. The primary |
| 2430 | difference is that it establishes an association with a label, which is used by |
| 2431 | the runtime library to unwind the stack.</p> |
| 2432 | |
| 2433 | <p>This instruction is used in languages with destructors to ensure that proper |
| 2434 | cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown |
| 2435 | exception. Additionally, this is important for implementation of |
| 2436 | '<tt>catch</tt>' clauses in high-level languages that support them.</p> |
| 2437 | |
Jay Foad | d244909 | 2009-06-03 10:20:10 +0000 | [diff] [blame] | 2438 | <p>For the purposes of the SSA form, the definition of the value |
| 2439 | returned by the '<tt>invoke</tt>' instruction is deemed to occur on |
| 2440 | the edge from the current block to the "normal" label. If the callee |
| 2441 | unwinds then no return value is available.</p> |
Dan Gohman | f96a499 | 2009-05-22 21:47:08 +0000 | [diff] [blame] | 2442 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2443 | <h5>Example:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2444 | <pre> |
Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2445 | %retval = invoke i32 @Test(i32 15) to label %Continue |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2446 | unwind label %TestCleanup <i>; {i32}:retval set</i> |
Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2447 | %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] | 2448 | unwind label %TestCleanup <i>; {i32}:retval set</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2449 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2450 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2451 | |
| 2452 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2453 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2454 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2455 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' |
| 2456 | Instruction</a> </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2457 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2458 | <div class="doc_text"> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2459 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2460 | <h5>Syntax:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2461 | <pre> |
| 2462 | unwind |
| 2463 | </pre> |
| 2464 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2465 | <h5>Overview:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2466 | |
| 2467 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow |
| 2468 | at the first callee in the dynamic call stack which used an <a |
| 2469 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is |
| 2470 | primarily used to implement exception handling.</p> |
| 2471 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2472 | <h5>Semantics:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2473 | |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2474 | <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] | 2475 | immediately halt. The dynamic call stack is then searched for the first <a |
| 2476 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found, |
| 2477 | execution continues at the "exceptional" destination block specified by the |
| 2478 | <tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the |
| 2479 | dynamic call chain, undefined behavior results.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2480 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2481 | |
| 2482 | <!-- _______________________________________________________________________ --> |
| 2483 | |
| 2484 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' |
| 2485 | Instruction</a> </div> |
| 2486 | |
| 2487 | <div class="doc_text"> |
| 2488 | |
| 2489 | <h5>Syntax:</h5> |
| 2490 | <pre> |
| 2491 | unreachable |
| 2492 | </pre> |
| 2493 | |
| 2494 | <h5>Overview:</h5> |
| 2495 | |
| 2496 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics. This |
| 2497 | instruction is used to inform the optimizer that a particular portion of the |
| 2498 | code is not reachable. This can be used to indicate that the code after a |
| 2499 | no-return function cannot be reached, and other facts.</p> |
| 2500 | |
| 2501 | <h5>Semantics:</h5> |
| 2502 | |
| 2503 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> |
| 2504 | </div> |
| 2505 | |
| 2506 | |
| 2507 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2508 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2509 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2510 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2511 | <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] | 2512 | 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] | 2513 | produce a single value. The operands might represent |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2514 | 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] | 2515 | The result value has the same type as its operands.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2516 | <p>There are several different binary operators:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2517 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2518 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2519 | <div class="doc_subsubsection"> |
| 2520 | <a name="i_add">'<tt>add</tt>' Instruction</a> |
| 2521 | </div> |
| 2522 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2523 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2524 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2525 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2526 | |
| 2527 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2528 | <result> = add <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2529 | </pre> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2530 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2531 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2532 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2533 | <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] | 2534 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2535 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2536 | |
| 2537 | <p>The two arguments to the '<tt>add</tt>' instruction must be <a |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2538 | href="#t_integer">integer</a> or |
| 2539 | <a href="#t_vector">vector</a> of integer values. Both arguments must |
| 2540 | have identical types.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2541 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2542 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2543 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2544 | <p>The value produced is the integer sum of the two operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2545 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2546 | <p>If the sum has unsigned overflow, the result returned is the |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2547 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of |
| 2548 | the result.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2549 | |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2550 | <p>Because LLVM integers use a two's complement representation, this |
| 2551 | instruction is appropriate for both signed and unsigned integers.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2552 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2553 | <h5>Example:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2554 | |
| 2555 | <pre> |
| 2556 | <result> = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2557 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2558 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2559 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2560 | <div class="doc_subsubsection"> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2561 | <a name="i_fadd">'<tt>fadd</tt>' Instruction</a> |
| 2562 | </div> |
| 2563 | |
| 2564 | <div class="doc_text"> |
| 2565 | |
| 2566 | <h5>Syntax:</h5> |
| 2567 | |
| 2568 | <pre> |
| 2569 | <result> = fadd <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
| 2570 | </pre> |
| 2571 | |
| 2572 | <h5>Overview:</h5> |
| 2573 | |
| 2574 | <p>The '<tt>fadd</tt>' instruction returns the sum of its two operands.</p> |
| 2575 | |
| 2576 | <h5>Arguments:</h5> |
| 2577 | |
| 2578 | <p>The two arguments to the '<tt>fadd</tt>' instruction must be |
| 2579 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> of |
| 2580 | floating point values. Both arguments must have identical types.</p> |
| 2581 | |
| 2582 | <h5>Semantics:</h5> |
| 2583 | |
| 2584 | <p>The value produced is the floating point sum of the two operands.</p> |
| 2585 | |
| 2586 | <h5>Example:</h5> |
| 2587 | |
| 2588 | <pre> |
| 2589 | <result> = fadd float 4.0, %var <i>; yields {float}:result = 4.0 + %var</i> |
| 2590 | </pre> |
| 2591 | </div> |
| 2592 | <!-- _______________________________________________________________________ --> |
| 2593 | <div class="doc_subsubsection"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2594 | <a name="i_sub">'<tt>sub</tt>' Instruction</a> |
| 2595 | </div> |
| 2596 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2597 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2598 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2599 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2600 | |
| 2601 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2602 | <result> = sub <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2603 | </pre> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2604 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2605 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2606 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2607 | <p>The '<tt>sub</tt>' instruction returns the difference of its two |
| 2608 | operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2609 | |
| 2610 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the |
| 2611 | '<tt>neg</tt>' instruction present in most other intermediate |
| 2612 | representations.</p> |
| 2613 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2614 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2615 | |
| 2616 | <p>The two arguments to the '<tt>sub</tt>' instruction must be <a |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2617 | href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of |
| 2618 | integer values. Both arguments must have identical types.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2619 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2620 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2621 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2622 | <p>The value produced is the integer difference of the two operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2623 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2624 | <p>If the difference has unsigned overflow, the result returned is the |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2625 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of |
| 2626 | the result.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2627 | |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2628 | <p>Because LLVM integers use a two's complement representation, this |
| 2629 | instruction is appropriate for both signed and unsigned integers.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2630 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2631 | <h5>Example:</h5> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 2632 | <pre> |
| 2633 | <result> = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2634 | <result> = sub i32 0, %val <i>; yields {i32}:result = -%var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2635 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2636 | </div> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2637 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2638 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2639 | <div class="doc_subsubsection"> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2640 | <a name="i_fsub">'<tt>fsub</tt>' Instruction</a> |
| 2641 | </div> |
| 2642 | |
| 2643 | <div class="doc_text"> |
| 2644 | |
| 2645 | <h5>Syntax:</h5> |
| 2646 | |
| 2647 | <pre> |
| 2648 | <result> = fsub <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
| 2649 | </pre> |
| 2650 | |
| 2651 | <h5>Overview:</h5> |
| 2652 | |
| 2653 | <p>The '<tt>fsub</tt>' instruction returns the difference of its two |
| 2654 | operands.</p> |
| 2655 | |
| 2656 | <p>Note that the '<tt>fsub</tt>' instruction is used to represent the |
| 2657 | '<tt>fneg</tt>' instruction present in most other intermediate |
| 2658 | representations.</p> |
| 2659 | |
| 2660 | <h5>Arguments:</h5> |
| 2661 | |
| 2662 | <p>The two arguments to the '<tt>fsub</tt>' instruction must be <a |
| 2663 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> |
| 2664 | of floating point values. Both arguments must have identical types.</p> |
| 2665 | |
| 2666 | <h5>Semantics:</h5> |
| 2667 | |
| 2668 | <p>The value produced is the floating point difference of the two operands.</p> |
| 2669 | |
| 2670 | <h5>Example:</h5> |
| 2671 | <pre> |
| 2672 | <result> = fsub float 4.0, %var <i>; yields {float}:result = 4.0 - %var</i> |
| 2673 | <result> = fsub float -0.0, %val <i>; yields {float}:result = -%var</i> |
| 2674 | </pre> |
| 2675 | </div> |
| 2676 | |
| 2677 | <!-- _______________________________________________________________________ --> |
| 2678 | <div class="doc_subsubsection"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2679 | <a name="i_mul">'<tt>mul</tt>' Instruction</a> |
| 2680 | </div> |
| 2681 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2682 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2683 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2684 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2685 | <pre> <result> = mul <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2686 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2687 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2688 | <p>The '<tt>mul</tt>' instruction returns the product of its two |
| 2689 | operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2690 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2691 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2692 | |
| 2693 | <p>The two arguments to the '<tt>mul</tt>' instruction must be <a |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2694 | href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 2695 | values. Both arguments must have identical types.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2696 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2697 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2698 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2699 | <p>The value produced is the integer product of the two operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2700 | |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2701 | <p>If the result of the multiplication has unsigned overflow, |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2702 | the result returned is the mathematical result modulo |
| 2703 | 2<sup>n</sup>, where n is the bit width of the result.</p> |
| 2704 | <p>Because LLVM integers use a two's complement representation, and the |
| 2705 | result is the same width as the operands, this instruction returns the |
| 2706 | correct result for both signed and unsigned integers. If a full product |
| 2707 | (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands |
| 2708 | should be sign-extended or zero-extended as appropriate to the |
| 2709 | width of the full product.</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> = mul i32 4, %var <i>; yields {i32}:result = 4 * %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2712 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2713 | </div> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2714 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2715 | <!-- _______________________________________________________________________ --> |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 2716 | <div class="doc_subsubsection"> |
| 2717 | <a name="i_fmul">'<tt>fmul</tt>' Instruction</a> |
| 2718 | </div> |
| 2719 | |
| 2720 | <div class="doc_text"> |
| 2721 | |
| 2722 | <h5>Syntax:</h5> |
| 2723 | <pre> <result> = fmul <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
| 2724 | </pre> |
| 2725 | <h5>Overview:</h5> |
| 2726 | <p>The '<tt>fmul</tt>' instruction returns the product of its two |
| 2727 | operands.</p> |
| 2728 | |
| 2729 | <h5>Arguments:</h5> |
| 2730 | |
| 2731 | <p>The two arguments to the '<tt>fmul</tt>' instruction must be |
| 2732 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> |
| 2733 | of floating point values. Both arguments must have identical types.</p> |
| 2734 | |
| 2735 | <h5>Semantics:</h5> |
| 2736 | |
| 2737 | <p>The value produced is the floating point product of the two operands.</p> |
| 2738 | |
| 2739 | <h5>Example:</h5> |
| 2740 | <pre> <result> = fmul float 4.0, %var <i>; yields {float}:result = 4.0 * %var</i> |
| 2741 | </pre> |
| 2742 | </div> |
| 2743 | |
| 2744 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2745 | <div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction |
| 2746 | </a></div> |
| 2747 | <div class="doc_text"> |
| 2748 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2749 | <pre> <result> = udiv <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2750 | </pre> |
| 2751 | <h5>Overview:</h5> |
| 2752 | <p>The '<tt>udiv</tt>' instruction returns the quotient of its two |
| 2753 | operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2754 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2755 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2756 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2757 | <p>The two arguments to the '<tt>udiv</tt>' instruction must be |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2758 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 2759 | values. Both arguments must have identical types.</p> |
| 2760 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2761 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2762 | |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2763 | <p>The value produced is the unsigned integer quotient of the two operands.</p> |
| 2764 | <p>Note that unsigned integer division and signed integer division are distinct |
| 2765 | operations; for signed integer division, use '<tt>sdiv</tt>'.</p> |
| 2766 | <p>Division by zero leads to undefined behavior.</p> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2767 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2768 | <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] | 2769 | </pre> |
| 2770 | </div> |
| 2771 | <!-- _______________________________________________________________________ --> |
| 2772 | <div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction |
| 2773 | </a> </div> |
| 2774 | <div class="doc_text"> |
| 2775 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2776 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2777 | <result> = sdiv <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2778 | </pre> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2779 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2780 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2781 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2782 | <p>The '<tt>sdiv</tt>' instruction returns the quotient of its two |
| 2783 | operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2784 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2785 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2786 | |
| 2787 | <p>The two arguments to the '<tt>sdiv</tt>' instruction must be |
| 2788 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 2789 | values. Both arguments must have identical types.</p> |
| 2790 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2791 | <h5>Semantics:</h5> |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2792 | <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] | 2793 | <p>Note that signed integer division and unsigned integer division are distinct |
| 2794 | operations; for unsigned integer division, use '<tt>udiv</tt>'.</p> |
| 2795 | <p>Division by zero leads to undefined behavior. Overflow also leads to |
| 2796 | undefined behavior; this is a rare case, but can occur, for example, |
| 2797 | by doing a 32-bit division of -2147483648 by -1.</p> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2798 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2799 | <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] | 2800 | </pre> |
| 2801 | </div> |
| 2802 | <!-- _______________________________________________________________________ --> |
| 2803 | <div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2804 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2805 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2806 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2807 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2808 | <result> = fdiv <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2809 | </pre> |
| 2810 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2811 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2812 | <p>The '<tt>fdiv</tt>' instruction returns the quotient of its two |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2813 | operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2814 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2815 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2816 | |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2817 | <p>The two arguments to the '<tt>fdiv</tt>' instruction must be |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2818 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> |
| 2819 | of floating point values. Both arguments must have identical types.</p> |
| 2820 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2821 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2822 | |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2823 | <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] | 2824 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2825 | <h5>Example:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2826 | |
| 2827 | <pre> |
| 2828 | <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] | 2829 | </pre> |
| 2830 | </div> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2831 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2832 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2833 | <div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a> |
| 2834 | </div> |
| 2835 | <div class="doc_text"> |
| 2836 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2837 | <pre> <result> = urem <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2838 | </pre> |
| 2839 | <h5>Overview:</h5> |
| 2840 | <p>The '<tt>urem</tt>' instruction returns the remainder from the |
| 2841 | unsigned division of its two arguments.</p> |
| 2842 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2843 | <p>The two arguments to the '<tt>urem</tt>' instruction must be |
| 2844 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 2845 | values. Both arguments must have identical types.</p> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2846 | <h5>Semantics:</h5> |
| 2847 | <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] | 2848 | This instruction always performs an unsigned division to get the remainder.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2849 | <p>Note that unsigned integer remainder and signed integer remainder are |
| 2850 | distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p> |
| 2851 | <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] | 2852 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2853 | <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] | 2854 | </pre> |
| 2855 | |
| 2856 | </div> |
| 2857 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2858 | <div class="doc_subsubsection"> |
| 2859 | <a name="i_srem">'<tt>srem</tt>' Instruction</a> |
| 2860 | </div> |
| 2861 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2862 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2863 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2864 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2865 | |
| 2866 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2867 | <result> = srem <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2868 | </pre> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2869 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2870 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2871 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2872 | <p>The '<tt>srem</tt>' instruction returns the remainder from the |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 2873 | signed division of its two operands. This instruction can also take |
| 2874 | <a href="#t_vector">vector</a> versions of the values in which case |
| 2875 | the elements must be integers.</p> |
Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 2876 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2877 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2878 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2879 | <p>The two arguments to the '<tt>srem</tt>' instruction must be |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2880 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 2881 | values. Both arguments must have identical types.</p> |
| 2882 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2883 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2884 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2885 | <p>This instruction returns the <i>remainder</i> of a division (where the result |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2886 | has the same sign as the dividend, <tt>op1</tt>), not the <i>modulo</i> |
| 2887 | operator (where the result has the same sign as the divisor, <tt>op2</tt>) of |
Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2888 | a value. For more information about the difference, see <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2889 | 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] | 2890 | 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] | 2891 | please see <a href="http://en.wikipedia.org/wiki/Modulo_operation"> |
Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2892 | Wikipedia: modulo operation</a>.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2893 | <p>Note that signed integer remainder and unsigned integer remainder are |
| 2894 | distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p> |
| 2895 | <p>Taking the remainder of a division by zero leads to undefined behavior. |
| 2896 | Overflow also leads to undefined behavior; this is a rare case, but can occur, |
| 2897 | for example, by taking the remainder of a 32-bit division of -2147483648 by -1. |
| 2898 | (The remainder doesn't actually overflow, but this rule lets srem be |
| 2899 | implemented using instructions that return both the result of the division |
| 2900 | and the remainder.)</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2901 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2902 | <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] | 2903 | </pre> |
| 2904 | |
| 2905 | </div> |
| 2906 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2907 | <div class="doc_subsubsection"> |
| 2908 | <a name="i_frem">'<tt>frem</tt>' Instruction</a> </div> |
| 2909 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2910 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2911 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2912 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2913 | <pre> <result> = frem <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2914 | </pre> |
| 2915 | <h5>Overview:</h5> |
| 2916 | <p>The '<tt>frem</tt>' instruction returns the remainder from the |
| 2917 | division of its two operands.</p> |
| 2918 | <h5>Arguments:</h5> |
| 2919 | <p>The two arguments to the '<tt>frem</tt>' instruction must be |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2920 | <a href="#t_floating">floating point</a> or <a href="#t_vector">vector</a> |
| 2921 | of floating point values. Both arguments must have identical types.</p> |
| 2922 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2923 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2924 | |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2925 | <p>This instruction returns the <i>remainder</i> of a division. |
| 2926 | The remainder has the same sign as the dividend.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2927 | |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2928 | <h5>Example:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 2929 | |
| 2930 | <pre> |
| 2931 | <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] | 2932 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2933 | </div> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 2934 | |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2935 | <!-- ======================================================================= --> |
| 2936 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary |
| 2937 | Operations</a> </div> |
| 2938 | <div class="doc_text"> |
| 2939 | <p>Bitwise binary operators are used to do various forms of |
| 2940 | bit-twiddling in a program. They are generally very efficient |
| 2941 | instructions and can commonly be strength reduced from other |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2942 | instructions. They require two operands of the same type, execute an operation on them, |
| 2943 | 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] | 2944 | </div> |
| 2945 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2946 | <!-- _______________________________________________________________________ --> |
| 2947 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' |
| 2948 | Instruction</a> </div> |
| 2949 | <div class="doc_text"> |
| 2950 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2951 | <pre> <result> = shl <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2952 | </pre> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2953 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2954 | <h5>Overview:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2955 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2956 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to |
| 2957 | the left a specified number of bits.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2958 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2959 | <h5>Arguments:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2960 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2961 | <p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 2962 | href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2963 | type. '<tt>op2</tt>' is treated as an unsigned value.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2964 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2965 | <h5>Semantics:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2966 | |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2967 | <p>The value produced is <tt>op1</tt> * 2<sup><tt>op2</tt></sup> mod 2<sup>n</sup>, |
| 2968 | where n is the width of the result. If <tt>op2</tt> is (statically or dynamically) negative or |
Mon P Wang | 01f8d09 | 2008-12-10 08:55:09 +0000 | [diff] [blame] | 2969 | equal to or larger than the number of bits in <tt>op1</tt>, the result is undefined. |
| 2970 | If the arguments are vectors, each vector element of <tt>op1</tt> is shifted by the |
| 2971 | corresponding shift amount in <tt>op2</tt>.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2972 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2973 | <h5>Example:</h5><pre> |
| 2974 | <result> = shl i32 4, %var <i>; yields {i32}: 4 << %var</i> |
| 2975 | <result> = shl i32 4, 2 <i>; yields {i32}: 16</i> |
| 2976 | <result> = shl i32 1, 10 <i>; yields {i32}: 1024</i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2977 | <result> = shl i32 1, 32 <i>; undefined</i> |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 2978 | <result> = shl <2 x i32> < i32 1, i32 1>, < i32 1, i32 2> <i>; yields: result=<2 x i32> < i32 2, i32 4></i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2979 | </pre> |
| 2980 | </div> |
| 2981 | <!-- _______________________________________________________________________ --> |
| 2982 | <div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>' |
| 2983 | Instruction</a> </div> |
| 2984 | <div class="doc_text"> |
| 2985 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2986 | <pre> <result> = lshr <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2987 | </pre> |
| 2988 | |
| 2989 | <h5>Overview:</h5> |
| 2990 | <p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2991 | 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] | 2992 | |
| 2993 | <h5>Arguments:</h5> |
| 2994 | <p>Both arguments to the '<tt>lshr</tt>' instruction must be the same |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 2995 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 2996 | type. '<tt>op2</tt>' is treated as an unsigned value.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2997 | |
| 2998 | <h5>Semantics:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2999 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3000 | <p>This instruction always performs a logical shift right operation. The most |
| 3001 | significant bits of the result will be filled with zero bits after the |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3002 | shift. If <tt>op2</tt> is (statically or dynamically) equal to or larger than |
Mon P Wang | 01f8d09 | 2008-12-10 08:55:09 +0000 | [diff] [blame] | 3003 | the number of bits in <tt>op1</tt>, the result is undefined. If the arguments are |
| 3004 | vectors, each vector element of <tt>op1</tt> is shifted by the corresponding shift |
| 3005 | amount in <tt>op2</tt>.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3006 | |
| 3007 | <h5>Example:</h5> |
| 3008 | <pre> |
| 3009 | <result> = lshr i32 4, 1 <i>; yields {i32}:result = 2</i> |
| 3010 | <result> = lshr i32 4, 2 <i>; yields {i32}:result = 1</i> |
| 3011 | <result> = lshr i8 4, 3 <i>; yields {i8}:result = 0</i> |
| 3012 | <result> = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 3013 | <result> = lshr i32 1, 32 <i>; undefined</i> |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 3014 | <result> = lshr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 2> <i>; yields: result=<2 x i32> < i32 0x7FFFFFFF, i32 1></i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3015 | </pre> |
| 3016 | </div> |
| 3017 | |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 3018 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3019 | <div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>' |
| 3020 | Instruction</a> </div> |
| 3021 | <div class="doc_text"> |
| 3022 | |
| 3023 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3024 | <pre> <result> = ashr <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3025 | </pre> |
| 3026 | |
| 3027 | <h5>Overview:</h5> |
| 3028 | <p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3029 | 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] | 3030 | |
| 3031 | <h5>Arguments:</h5> |
| 3032 | <p>Both arguments to the '<tt>ashr</tt>' instruction must be the same |
Nate Begeman | 5bc1ea0 | 2008-07-29 15:49:41 +0000 | [diff] [blame] | 3033 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3034 | type. '<tt>op2</tt>' is treated as an unsigned value.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3035 | |
| 3036 | <h5>Semantics:</h5> |
| 3037 | <p>This instruction always performs an arithmetic shift right operation, |
| 3038 | The most significant bits of the result will be filled with the sign bit |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3039 | of <tt>op1</tt>. If <tt>op2</tt> is (statically or dynamically) equal to or |
Mon P Wang | 01f8d09 | 2008-12-10 08:55:09 +0000 | [diff] [blame] | 3040 | larger than the number of bits in <tt>op1</tt>, the result is undefined. If the |
| 3041 | arguments are vectors, each vector element of <tt>op1</tt> is shifted by the |
| 3042 | corresponding shift amount in <tt>op2</tt>.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3043 | |
| 3044 | <h5>Example:</h5> |
| 3045 | <pre> |
| 3046 | <result> = ashr i32 4, 1 <i>; yields {i32}:result = 2</i> |
| 3047 | <result> = ashr i32 4, 2 <i>; yields {i32}:result = 1</i> |
| 3048 | <result> = ashr i8 4, 3 <i>; yields {i8}:result = 0</i> |
| 3049 | <result> = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 3050 | <result> = ashr i32 1, 32 <i>; undefined</i> |
Mon P Wang | e9f1015 | 2008-12-09 05:46:39 +0000 | [diff] [blame] | 3051 | <result> = ashr <2 x i32> < i32 -2, i32 4>, < i32 1, i32 3> <i>; yields: result=<2 x i32> < i32 -1, i32 0></i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 3052 | </pre> |
| 3053 | </div> |
| 3054 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3055 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3056 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' |
| 3057 | Instruction</a> </div> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3058 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3059 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3060 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3061 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3062 | |
| 3063 | <pre> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3064 | <result> = and <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3065 | </pre> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3066 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3067 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3068 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3069 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of |
| 3070 | its two operands.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3071 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3072 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3073 | |
| 3074 | <p>The two arguments to the '<tt>and</tt>' instruction must be |
| 3075 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 3076 | values. Both arguments must have identical types.</p> |
| 3077 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3078 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3079 | <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] | 3080 | <p> </p> |
Bill Wendling | c7e4c4d | 2008-09-07 10:29:20 +0000 | [diff] [blame] | 3081 | <div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3082 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3083 | <tbody> |
| 3084 | <tr> |
| 3085 | <td>In0</td> |
| 3086 | <td>In1</td> |
| 3087 | <td>Out</td> |
| 3088 | </tr> |
| 3089 | <tr> |
| 3090 | <td>0</td> |
| 3091 | <td>0</td> |
| 3092 | <td>0</td> |
| 3093 | </tr> |
| 3094 | <tr> |
| 3095 | <td>0</td> |
| 3096 | <td>1</td> |
| 3097 | <td>0</td> |
| 3098 | </tr> |
| 3099 | <tr> |
| 3100 | <td>1</td> |
| 3101 | <td>0</td> |
| 3102 | <td>0</td> |
| 3103 | </tr> |
| 3104 | <tr> |
| 3105 | <td>1</td> |
| 3106 | <td>1</td> |
| 3107 | <td>1</td> |
| 3108 | </tr> |
| 3109 | </tbody> |
| 3110 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 3111 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3112 | <h5>Example:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3113 | <pre> |
| 3114 | <result> = and i32 4, %var <i>; yields {i32}:result = 4 & %var</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3115 | <result> = and i32 15, 40 <i>; yields {i32}:result = 8</i> |
| 3116 | <result> = and i32 4, 8 <i>; yields {i32}:result = 0</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3117 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3118 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3119 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3120 | <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] | 3121 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3122 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3123 | <pre> <result> = or <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3124 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3125 | <h5>Overview:</h5> |
| 3126 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive |
| 3127 | or of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3128 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3129 | |
| 3130 | <p>The two arguments to the '<tt>or</tt>' instruction must be |
| 3131 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 3132 | values. Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3133 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3134 | <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] | 3135 | <p> </p> |
Bill Wendling | c7e4c4d | 2008-09-07 10:29:20 +0000 | [diff] [blame] | 3136 | <div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3137 | <table border="1" cellspacing="0" cellpadding="4"> |
| 3138 | <tbody> |
| 3139 | <tr> |
| 3140 | <td>In0</td> |
| 3141 | <td>In1</td> |
| 3142 | <td>Out</td> |
| 3143 | </tr> |
| 3144 | <tr> |
| 3145 | <td>0</td> |
| 3146 | <td>0</td> |
| 3147 | <td>0</td> |
| 3148 | </tr> |
| 3149 | <tr> |
| 3150 | <td>0</td> |
| 3151 | <td>1</td> |
| 3152 | <td>1</td> |
| 3153 | </tr> |
| 3154 | <tr> |
| 3155 | <td>1</td> |
| 3156 | <td>0</td> |
| 3157 | <td>1</td> |
| 3158 | </tr> |
| 3159 | <tr> |
| 3160 | <td>1</td> |
| 3161 | <td>1</td> |
| 3162 | <td>1</td> |
| 3163 | </tr> |
| 3164 | </tbody> |
| 3165 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 3166 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3167 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3168 | <pre> <result> = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i> |
| 3169 | <result> = or i32 15, 40 <i>; yields {i32}:result = 47</i> |
| 3170 | <result> = or i32 4, 8 <i>; yields {i32}:result = 12</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3171 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3172 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3173 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3174 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' |
| 3175 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3176 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3177 | <h5>Syntax:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 3178 | <pre> <result> = xor <ty> <op1>, <op2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3179 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3180 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3181 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive |
| 3182 | or of its two operands. The <tt>xor</tt> is used to implement the |
| 3183 | "one's complement" operation, which is the "~" operator in C.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3184 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3185 | <p>The two arguments to the '<tt>xor</tt>' instruction must be |
| 3186 | <a href="#t_integer">integer</a> or <a href="#t_vector">vector</a> of integer |
| 3187 | values. Both arguments must have identical types.</p> |
| 3188 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3189 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 3190 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3191 | <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] | 3192 | <p> </p> |
Bill Wendling | c7e4c4d | 2008-09-07 10:29:20 +0000 | [diff] [blame] | 3193 | <div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3194 | <table border="1" cellspacing="0" cellpadding="4"> |
| 3195 | <tbody> |
| 3196 | <tr> |
| 3197 | <td>In0</td> |
| 3198 | <td>In1</td> |
| 3199 | <td>Out</td> |
| 3200 | </tr> |
| 3201 | <tr> |
| 3202 | <td>0</td> |
| 3203 | <td>0</td> |
| 3204 | <td>0</td> |
| 3205 | </tr> |
| 3206 | <tr> |
| 3207 | <td>0</td> |
| 3208 | <td>1</td> |
| 3209 | <td>1</td> |
| 3210 | </tr> |
| 3211 | <tr> |
| 3212 | <td>1</td> |
| 3213 | <td>0</td> |
| 3214 | <td>1</td> |
| 3215 | </tr> |
| 3216 | <tr> |
| 3217 | <td>1</td> |
| 3218 | <td>1</td> |
| 3219 | <td>0</td> |
| 3220 | </tr> |
| 3221 | </tbody> |
| 3222 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 3223 | </div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3224 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3225 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3226 | <pre> <result> = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i> |
| 3227 | <result> = xor i32 15, 40 <i>; yields {i32}:result = 39</i> |
| 3228 | <result> = xor i32 4, 8 <i>; yields {i32}:result = 12</i> |
| 3229 | <result> = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3230 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3231 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3232 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3233 | <!-- ======================================================================= --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3234 | <div class="doc_subsection"> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3235 | <a name="vectorops">Vector Operations</a> |
| 3236 | </div> |
| 3237 | |
| 3238 | <div class="doc_text"> |
| 3239 | |
| 3240 | <p>LLVM supports several instructions to represent vector operations in a |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3241 | target-independent manner. These instructions cover the element-access and |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3242 | vector-specific operations needed to process vectors effectively. While LLVM |
| 3243 | does directly support these vector operations, many sophisticated algorithms |
| 3244 | will want to use target-specific intrinsics to take full advantage of a specific |
| 3245 | target.</p> |
| 3246 | |
| 3247 | </div> |
| 3248 | |
| 3249 | <!-- _______________________________________________________________________ --> |
| 3250 | <div class="doc_subsubsection"> |
| 3251 | <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a> |
| 3252 | </div> |
| 3253 | |
| 3254 | <div class="doc_text"> |
| 3255 | |
| 3256 | <h5>Syntax:</h5> |
| 3257 | |
| 3258 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3259 | <result> = extractelement <n x <ty>> <val>, i32 <idx> <i>; yields <ty></i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3260 | </pre> |
| 3261 | |
| 3262 | <h5>Overview:</h5> |
| 3263 | |
| 3264 | <p> |
| 3265 | The '<tt>extractelement</tt>' instruction extracts a single scalar |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 3266 | element from a vector at a specified index. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3267 | </p> |
| 3268 | |
| 3269 | |
| 3270 | <h5>Arguments:</h5> |
| 3271 | |
| 3272 | <p> |
| 3273 | The first operand of an '<tt>extractelement</tt>' instruction is a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 3274 | 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] | 3275 | an index indicating the position from which to extract the element. |
| 3276 | The index may be a variable.</p> |
| 3277 | |
| 3278 | <h5>Semantics:</h5> |
| 3279 | |
| 3280 | <p> |
| 3281 | The result is a scalar of the same type as the element type of |
| 3282 | <tt>val</tt>. Its value is the value at position <tt>idx</tt> of |
| 3283 | <tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the |
| 3284 | results are undefined. |
| 3285 | </p> |
| 3286 | |
| 3287 | <h5>Example:</h5> |
| 3288 | |
| 3289 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3290 | %result = extractelement <4 x i32> %vec, i32 0 <i>; yields i32</i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3291 | </pre> |
| 3292 | </div> |
| 3293 | |
| 3294 | |
| 3295 | <!-- _______________________________________________________________________ --> |
| 3296 | <div class="doc_subsubsection"> |
| 3297 | <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a> |
| 3298 | </div> |
| 3299 | |
| 3300 | <div class="doc_text"> |
| 3301 | |
| 3302 | <h5>Syntax:</h5> |
| 3303 | |
| 3304 | <pre> |
Dan Gohman | f3480b9 | 2008-05-12 23:38:42 +0000 | [diff] [blame] | 3305 | <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] | 3306 | </pre> |
| 3307 | |
| 3308 | <h5>Overview:</h5> |
| 3309 | |
| 3310 | <p> |
| 3311 | The '<tt>insertelement</tt>' instruction inserts a scalar |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 3312 | element into a vector at a specified index. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3313 | </p> |
| 3314 | |
| 3315 | |
| 3316 | <h5>Arguments:</h5> |
| 3317 | |
| 3318 | <p> |
| 3319 | The first operand of an '<tt>insertelement</tt>' instruction is a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 3320 | 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] | 3321 | scalar value whose type must equal the element type of the first |
| 3322 | operand. The third operand is an index indicating the position at |
| 3323 | which to insert the value. The index may be a variable.</p> |
| 3324 | |
| 3325 | <h5>Semantics:</h5> |
| 3326 | |
| 3327 | <p> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 3328 | 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] | 3329 | element values are those of <tt>val</tt> except at position |
| 3330 | <tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt> |
| 3331 | exceeds the length of <tt>val</tt>, the results are undefined. |
| 3332 | </p> |
| 3333 | |
| 3334 | <h5>Example:</h5> |
| 3335 | |
| 3336 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3337 | %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] | 3338 | </pre> |
| 3339 | </div> |
| 3340 | |
| 3341 | <!-- _______________________________________________________________________ --> |
| 3342 | <div class="doc_subsubsection"> |
| 3343 | <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a> |
| 3344 | </div> |
| 3345 | |
| 3346 | <div class="doc_text"> |
| 3347 | |
| 3348 | <h5>Syntax:</h5> |
| 3349 | |
| 3350 | <pre> |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3351 | <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <m x i32> <mask> <i>; yields <m x <ty>></i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3352 | </pre> |
| 3353 | |
| 3354 | <h5>Overview:</h5> |
| 3355 | |
| 3356 | <p> |
| 3357 | The '<tt>shufflevector</tt>' instruction constructs a permutation of elements |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3358 | from two input vectors, returning a vector with the same element type as |
| 3359 | the input and length that is the same as the shuffle mask. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3360 | </p> |
| 3361 | |
| 3362 | <h5>Arguments:</h5> |
| 3363 | |
| 3364 | <p> |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3365 | The first two operands of a '<tt>shufflevector</tt>' instruction are vectors |
| 3366 | with types that match each other. The third argument is a shuffle mask whose |
| 3367 | element type is always 'i32'. The result of the instruction is a vector whose |
| 3368 | length is the same as the shuffle mask and whose element type is the same as |
| 3369 | the element type of the first two operands. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3370 | </p> |
| 3371 | |
| 3372 | <p> |
| 3373 | The shuffle mask operand is required to be a constant vector with either |
| 3374 | constant integer or undef values. |
| 3375 | </p> |
| 3376 | |
| 3377 | <h5>Semantics:</h5> |
| 3378 | |
| 3379 | <p> |
| 3380 | The elements of the two input vectors are numbered from left to right across |
| 3381 | both of the vectors. The shuffle mask operand specifies, for each element of |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3382 | the result vector, which element of the two input vectors the result element |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3383 | gets. The element selector may be undef (meaning "don't care") and the second |
| 3384 | operand may be undef if performing a shuffle from only one vector. |
| 3385 | </p> |
| 3386 | |
| 3387 | <h5>Example:</h5> |
| 3388 | |
| 3389 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3390 | %result = shufflevector <4 x i32> %v1, <4 x i32> %v2, |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3391 | <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] | 3392 | %result = shufflevector <4 x i32> %v1, <4 x i32> undef, |
| 3393 | <4 x i32> <i32 0, i32 1, i32 2, i32 3> <i>; yields <4 x i32></i> - Identity shuffle. |
Mon P Wang | aeb06d2 | 2008-11-10 04:46:22 +0000 | [diff] [blame] | 3394 | %result = shufflevector <8 x i32> %v1, <8 x i32> undef, |
| 3395 | <4 x i32> <i32 0, i32 1, i32 2, i32 3> <i>; yields <4 x i32></i> |
| 3396 | %result = shufflevector <4 x i32> %v1, <4 x i32> %v2, |
| 3397 | <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7 > <i>; yields <8 x i32></i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3398 | </pre> |
| 3399 | </div> |
| 3400 | |
Tanya Lattner | 0947429 | 2006-04-14 19:24:33 +0000 | [diff] [blame] | 3401 | |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 3402 | <!-- ======================================================================= --> |
| 3403 | <div class="doc_subsection"> |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3404 | <a name="aggregateops">Aggregate Operations</a> |
| 3405 | </div> |
| 3406 | |
| 3407 | <div class="doc_text"> |
| 3408 | |
| 3409 | <p>LLVM supports several instructions for working with aggregate values. |
| 3410 | </p> |
| 3411 | |
| 3412 | </div> |
| 3413 | |
| 3414 | <!-- _______________________________________________________________________ --> |
| 3415 | <div class="doc_subsubsection"> |
| 3416 | <a name="i_extractvalue">'<tt>extractvalue</tt>' Instruction</a> |
| 3417 | </div> |
| 3418 | |
| 3419 | <div class="doc_text"> |
| 3420 | |
| 3421 | <h5>Syntax:</h5> |
| 3422 | |
| 3423 | <pre> |
| 3424 | <result> = extractvalue <aggregate type> <val>, <idx>{, <idx>}* |
| 3425 | </pre> |
| 3426 | |
| 3427 | <h5>Overview:</h5> |
| 3428 | |
| 3429 | <p> |
Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 3430 | The '<tt>extractvalue</tt>' instruction extracts the value of a struct field |
| 3431 | or array element from an aggregate value. |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3432 | </p> |
| 3433 | |
| 3434 | |
| 3435 | <h5>Arguments:</h5> |
| 3436 | |
| 3437 | <p> |
| 3438 | The first operand of an '<tt>extractvalue</tt>' instruction is a |
| 3439 | 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] | 3440 | type. The operands are constant indices to specify which value to extract |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 3441 | in a similar manner as indices in a |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3442 | '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. |
| 3443 | </p> |
| 3444 | |
| 3445 | <h5>Semantics:</h5> |
| 3446 | |
| 3447 | <p> |
| 3448 | The result is the value at the position in the aggregate specified by |
| 3449 | the index operands. |
| 3450 | </p> |
| 3451 | |
| 3452 | <h5>Example:</h5> |
| 3453 | |
| 3454 | <pre> |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 3455 | %result = extractvalue {i32, float} %agg, 0 <i>; yields i32</i> |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3456 | </pre> |
| 3457 | </div> |
| 3458 | |
| 3459 | |
| 3460 | <!-- _______________________________________________________________________ --> |
| 3461 | <div class="doc_subsubsection"> |
| 3462 | <a name="i_insertvalue">'<tt>insertvalue</tt>' Instruction</a> |
| 3463 | </div> |
| 3464 | |
| 3465 | <div class="doc_text"> |
| 3466 | |
| 3467 | <h5>Syntax:</h5> |
| 3468 | |
| 3469 | <pre> |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 3470 | <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] | 3471 | </pre> |
| 3472 | |
| 3473 | <h5>Overview:</h5> |
| 3474 | |
| 3475 | <p> |
| 3476 | The '<tt>insertvalue</tt>' instruction inserts a value |
Dan Gohman | c3dac5c | 2008-05-13 18:16:06 +0000 | [diff] [blame] | 3477 | into a struct field or array element in an aggregate. |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3478 | </p> |
| 3479 | |
| 3480 | |
| 3481 | <h5>Arguments:</h5> |
| 3482 | |
| 3483 | <p> |
| 3484 | The first operand of an '<tt>insertvalue</tt>' instruction is a |
| 3485 | value of <a href="#t_struct">struct</a> or <a href="#t_array">array</a> type. |
| 3486 | The second operand is a first-class value to insert. |
Dan Gohman | c4b49eb | 2008-05-23 21:53:15 +0000 | [diff] [blame] | 3487 | The following operands are constant indices |
Dan Gohman | 81a0c0b | 2008-05-31 00:58:22 +0000 | [diff] [blame] | 3488 | 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] | 3489 | indices in a |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3490 | '<tt><a href="#i_getelementptr">getelementptr</a></tt>' instruction. |
| 3491 | 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] | 3492 | by the indices. |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 3493 | </p> |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3494 | |
| 3495 | <h5>Semantics:</h5> |
| 3496 | |
| 3497 | <p> |
| 3498 | The result is an aggregate of the same type as <tt>val</tt>. Its |
| 3499 | 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] | 3500 | specified by the indices is that of <tt>elt</tt>. |
Dan Gohman | a334d5f | 2008-05-12 23:51:09 +0000 | [diff] [blame] | 3501 | </p> |
| 3502 | |
| 3503 | <h5>Example:</h5> |
| 3504 | |
| 3505 | <pre> |
Dan Gohman | 52bb2db | 2008-06-23 15:26:37 +0000 | [diff] [blame] | 3506 | %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] | 3507 | </pre> |
| 3508 | </div> |
| 3509 | |
| 3510 | |
| 3511 | <!-- ======================================================================= --> |
| 3512 | <div class="doc_subsection"> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 3513 | <a name="memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3514 | </div> |
| 3515 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3516 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3517 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3518 | <p>A key design point of an SSA-based representation is how it |
| 3519 | represents memory. In LLVM, no memory locations are in SSA form, which |
| 3520 | makes things very simple. This section describes how to read, write, |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3521 | allocate, and free memory in LLVM.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3522 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3523 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3524 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3525 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3526 | <div class="doc_subsubsection"> |
| 3527 | <a name="i_malloc">'<tt>malloc</tt>' Instruction</a> |
| 3528 | </div> |
| 3529 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3530 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3531 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3532 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3533 | |
| 3534 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3535 | <result> = malloc <type>[, i32 <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3536 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3537 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3538 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3539 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3540 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 3541 | heap and returns a pointer to it. The object is always allocated in the generic |
| 3542 | address space (address space zero).</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3543 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3544 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3545 | |
| 3546 | <p>The '<tt>malloc</tt>' instruction allocates |
| 3547 | <tt>sizeof(<type>)*NumElements</tt> |
John Criswell | 6e4ca61 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 3548 | 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] | 3549 | appropriate type to the program. If "NumElements" is specified, it is the |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3550 | number of elements allocated, otherwise "NumElements" is defaulted to be one. |
Duncan Sands | 434ca80 | 2009-06-20 13:26:06 +0000 | [diff] [blame] | 3551 | If a constant alignment is specified, the value result of the allocation is |
| 3552 | guaranteed to be aligned to at least that boundary. If not specified, or if |
| 3553 | zero, the target can choose to align the allocation on any convenient boundary |
| 3554 | compatible with the type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3555 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3556 | <p>'<tt>type</tt>' must be a sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3557 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3558 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3559 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3560 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and |
Nick Lewycky | 02ff308 | 2008-11-24 03:41:24 +0000 | [diff] [blame] | 3561 | a pointer is returned. The result of a zero byte allocation is undefined. The |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 3562 | result is null if there is insufficient memory available.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3563 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3564 | <h5>Example:</h5> |
| 3565 | |
| 3566 | <pre> |
Dan Gohman | 81e2167 | 2009-01-04 23:49:44 +0000 | [diff] [blame] | 3567 | %array = malloc [4 x i8] <i>; yields {[%4 x i8]*}:array</i> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3568 | |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 3569 | %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i> |
| 3570 | %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i> |
| 3571 | %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i> |
| 3572 | %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i> |
| 3573 | %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3574 | </pre> |
Dan Gohman | f3e60bd | 2009-01-12 23:12:39 +0000 | [diff] [blame] | 3575 | |
| 3576 | <p>Note that the code generator does not yet respect the |
| 3577 | alignment value.</p> |
| 3578 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3579 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3580 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3581 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3582 | <div class="doc_subsubsection"> |
| 3583 | <a name="i_free">'<tt>free</tt>' Instruction</a> |
| 3584 | </div> |
| 3585 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3586 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3587 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3588 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3589 | |
| 3590 | <pre> |
Dan Gohman | 81e2167 | 2009-01-04 23:49:44 +0000 | [diff] [blame] | 3591 | free <type> <value> <i>; yields {void}</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3592 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3593 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3594 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3595 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3596 | <p>The '<tt>free</tt>' instruction returns memory back to the unused |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3597 | memory heap to be reallocated in the future.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3598 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3599 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3600 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3601 | <p>'<tt>value</tt>' shall be a pointer value that points to a value |
| 3602 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' |
| 3603 | instruction.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3604 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3605 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3606 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3607 | <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] | 3608 | after this instruction executes. If the pointer is null, the operation |
| 3609 | is a noop.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3610 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3611 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3612 | |
| 3613 | <pre> |
Dan Gohman | 81e2167 | 2009-01-04 23:49:44 +0000 | [diff] [blame] | 3614 | %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3615 | free [4 x i8]* %array |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3616 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3617 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3618 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3619 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3620 | <div class="doc_subsubsection"> |
| 3621 | <a name="i_alloca">'<tt>alloca</tt>' Instruction</a> |
| 3622 | </div> |
| 3623 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3624 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3625 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3626 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3627 | |
| 3628 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3629 | <result> = alloca <type>[, i32 <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3630 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3631 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3632 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3633 | |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3634 | <p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the |
| 3635 | currently executing function, to be automatically released when this function |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 3636 | returns to its caller. The object is always allocated in the generic address |
| 3637 | space (address space zero).</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3638 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3639 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3640 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3641 | <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3642 | bytes of memory on the runtime stack, returning a pointer of the |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 3643 | appropriate type to the program. If "NumElements" is specified, it is the |
| 3644 | number of elements allocated, otherwise "NumElements" is defaulted to be one. |
Duncan Sands | 434ca80 | 2009-06-20 13:26:06 +0000 | [diff] [blame] | 3645 | If a constant alignment is specified, the value result of the allocation is |
| 3646 | guaranteed to be aligned to at least that boundary. If not specified, or if |
| 3647 | zero, the target can choose to align the allocation on any convenient boundary |
| 3648 | compatible with the type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3649 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3650 | <p>'<tt>type</tt>' may be any sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3651 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3652 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3653 | |
Bill Wendling | 871eb0a | 2009-05-08 20:49:29 +0000 | [diff] [blame] | 3654 | <p>Memory is allocated; a pointer is returned. The operation is undefined if |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 3655 | there is insufficient stack space for the allocation. '<tt>alloca</tt>'d |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3656 | memory is automatically released when the function returns. The '<tt>alloca</tt>' |
| 3657 | instruction is commonly used to represent automatic variables that must |
| 3658 | 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] | 3659 | 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] | 3660 | instructions), the memory is reclaimed. Allocating zero bytes |
| 3661 | is legal, but the result is undefined.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3662 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3663 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3664 | |
| 3665 | <pre> |
Dan Gohman | 81e2167 | 2009-01-04 23:49:44 +0000 | [diff] [blame] | 3666 | %ptr = alloca i32 <i>; yields {i32*}:ptr</i> |
| 3667 | %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i> |
| 3668 | %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i> |
| 3669 | %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3670 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3671 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 3672 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3673 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3674 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' |
| 3675 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3676 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3677 | <h5>Syntax:</h5> |
Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 3678 | <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] | 3679 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3680 | <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] | 3681 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3682 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 3683 | address from which to load. The pointer must point to a <a |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 3684 | 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] | 3685 | 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] | 3686 | the number or order of execution of this <tt>load</tt> with other |
| 3687 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> |
| 3688 | instructions. </p> |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3689 | <p> |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3690 | The optional constant "align" argument specifies the alignment of the operation |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3691 | (that is, the alignment of the memory address). A value of 0 or an |
| 3692 | omitted "align" argument means that the operation has the preferential |
| 3693 | alignment for the target. It is the responsibility of the code emitter |
| 3694 | to ensure that the alignment information is correct. Overestimating |
| 3695 | the alignment results in an undefined behavior. Underestimating the |
| 3696 | alignment may produce less efficient code. An alignment of 1 is always |
| 3697 | safe. |
| 3698 | </p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3699 | <h5>Semantics:</h5> |
Duncan Sands | 19527c6 | 2009-03-22 11:33:16 +0000 | [diff] [blame] | 3700 | <p>The location of memory pointed to is loaded. If the value being loaded |
| 3701 | is of scalar type then the number of bytes read does not exceed the minimum |
| 3702 | number of bytes needed to hold all bits of the type. For example, loading an |
| 3703 | <tt>i24</tt> reads at most three bytes. When loading a value of a type like |
| 3704 | <tt>i20</tt> with a size that is not an integral number of bytes, the result |
| 3705 | is undefined if the value was not originally written using a store of the |
| 3706 | same type.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3707 | <h5>Examples:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3708 | <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] | 3709 | <a |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3710 | href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i> |
| 3711 | %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3712 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3713 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3714 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3715 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' |
| 3716 | Instruction</a> </div> |
Reid Spencer | 035ab57 | 2006-11-09 21:18:01 +0000 | [diff] [blame] | 3717 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3718 | <h5>Syntax:</h5> |
Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 3719 | <pre> store <ty> <value>, <ty>* <pointer>[, align <alignment>] <i>; yields {void}</i> |
| 3720 | volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>] <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3721 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3722 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3723 | <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] | 3724 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3725 | <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] | 3726 | 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] | 3727 | operand must be a pointer to the <a href="#t_firstclass">first class</a> type |
| 3728 | of the '<tt><value></tt>' |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3729 | 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] | 3730 | optimizer is not allowed to modify the number or order of execution of |
| 3731 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a |
| 3732 | href="#i_store">store</a></tt> instructions.</p> |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3733 | <p> |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3734 | The optional constant "align" argument specifies the alignment of the operation |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 3735 | (that is, the alignment of the memory address). A value of 0 or an |
| 3736 | omitted "align" argument means that the operation has the preferential |
| 3737 | alignment for the target. It is the responsibility of the code emitter |
| 3738 | to ensure that the alignment information is correct. Overestimating |
| 3739 | the alignment results in an undefined behavior. Underestimating the |
| 3740 | alignment may produce less efficient code. An alignment of 1 is always |
| 3741 | safe. |
| 3742 | </p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3743 | <h5>Semantics:</h5> |
| 3744 | <p>The contents of memory are updated to contain '<tt><value></tt>' |
Duncan Sands | 19527c6 | 2009-03-22 11:33:16 +0000 | [diff] [blame] | 3745 | at the location specified by the '<tt><pointer></tt>' operand. |
| 3746 | If '<tt><value></tt>' is of scalar type then the number of bytes |
| 3747 | written does not exceed the minimum number of bytes needed to hold all |
| 3748 | bits of the type. For example, storing an <tt>i24</tt> writes at most |
| 3749 | three bytes. When writing a value of a type like <tt>i20</tt> with a |
| 3750 | size that is not an integral number of bytes, it is unspecified what |
| 3751 | happens to the extra bits that do not belong to the type, but they will |
| 3752 | typically be overwritten.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3753 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3754 | <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] | 3755 | store i32 3, i32* %ptr <i>; yields {void}</i> |
| 3756 | %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] | 3757 | </pre> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3758 | </div> |
| 3759 | |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3760 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3761 | <div class="doc_subsubsection"> |
| 3762 | <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> |
| 3763 | </div> |
| 3764 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3765 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3766 | <h5>Syntax:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3767 | <pre> |
Matthijs Kooijman | e49d0bc | 2008-10-13 13:44:15 +0000 | [diff] [blame] | 3768 | <result> = getelementptr <pty>* <ptrval>{, <ty> <idx>}* |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3769 | </pre> |
| 3770 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3771 | <h5>Overview:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3772 | |
| 3773 | <p> |
| 3774 | The '<tt>getelementptr</tt>' instruction is used to get the address of a |
Matthijs Kooijman | e49d0bc | 2008-10-13 13:44:15 +0000 | [diff] [blame] | 3775 | subelement of an aggregate data structure. It performs address calculation only |
| 3776 | and does not access memory.</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3777 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3778 | <h5>Arguments:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3779 | |
Matthijs Kooijman | e49d0bc | 2008-10-13 13:44:15 +0000 | [diff] [blame] | 3780 | <p>The first argument is always a pointer, and forms the basis of the |
| 3781 | calculation. The remaining arguments are indices, that indicate which of the |
| 3782 | elements of the aggregate object are indexed. The interpretation of each index |
| 3783 | is dependent on the type being indexed into. The first index always indexes the |
| 3784 | pointer value given as the first argument, the second index indexes a value of |
| 3785 | the type pointed to (not necessarily the value directly pointed to, since the |
| 3786 | first index can be non-zero), etc. The first type indexed into must be a pointer |
| 3787 | value, subsequent types can be arrays, vectors and structs. Note that subsequent |
| 3788 | types being indexed into can never be pointers, since that would require loading |
| 3789 | the pointer before continuing calculation.</p> |
| 3790 | |
| 3791 | <p>The type of each index argument depends on the type it is indexing into. |
| 3792 | When indexing into a (packed) structure, only <tt>i32</tt> integer |
| 3793 | <b>constants</b> are allowed. When indexing into an array, pointer or vector, |
Sanjiv Gupta | 23c70f4 | 2009-04-27 03:21:00 +0000 | [diff] [blame] | 3794 | integers of any width are allowed (also non-constants).</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3795 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3796 | <p>For example, let's consider a C code fragment and how it gets |
| 3797 | compiled to LLVM:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3798 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3799 | <div class="doc_code"> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3800 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3801 | struct RT { |
| 3802 | char A; |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3803 | int B[10][20]; |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3804 | char C; |
| 3805 | }; |
| 3806 | struct ST { |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3807 | int X; |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3808 | double Y; |
| 3809 | struct RT Z; |
| 3810 | }; |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3811 | |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3812 | int *foo(struct ST *s) { |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3813 | return &s[1].Z.B[5][13]; |
| 3814 | } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3815 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3816 | </div> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3817 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3818 | <p>The LLVM code generated by the GCC frontend is:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3819 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3820 | <div class="doc_code"> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3821 | <pre> |
Chris Lattner | e7886e4 | 2009-01-11 20:53:49 +0000 | [diff] [blame] | 3822 | %RT = <a href="#namedtypes">type</a> { i8 , [10 x [20 x i32]], i8 } |
| 3823 | %ST = <a href="#namedtypes">type</a> { i32, double, %RT } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3824 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3825 | define i32* %foo(%ST* %s) { |
| 3826 | entry: |
| 3827 | %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 |
| 3828 | ret i32* %reg |
| 3829 | } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3830 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3831 | </div> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3832 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3833 | <h5>Semantics:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3834 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3835 | <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] | 3836 | 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] | 3837 | }</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] | 3838 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]], |
| 3839 | i8 }</tt>' type, another structure. The third index indexes into the second |
| 3840 | 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] | 3841 | array. The two dimensions of the array are subscripted into, yielding an |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3842 | '<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer |
| 3843 | 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] | 3844 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3845 | <p>Note that it is perfectly legal to index partially through a |
| 3846 | structure, returning a pointer to an inner element. Because of this, |
| 3847 | the LLVM code for the given testcase is equivalent to:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3848 | |
| 3849 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3850 | define i32* %foo(%ST* %s) { |
| 3851 | %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3852 | %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i> |
| 3853 | %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] | 3854 | %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i> |
| 3855 | %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i> |
| 3856 | ret i32* %t5 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3857 | } |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3858 | </pre> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3859 | |
Chris Lattner | 8c0e62c | 2009-03-09 20:55:18 +0000 | [diff] [blame] | 3860 | <p>Note that it is undefined to access an array out of bounds: array |
| 3861 | and pointer indexes must always be within the defined bounds of the |
| 3862 | array type when accessed with an instruction that dereferences the |
| 3863 | pointer (e.g. a load or store instruction). The one exception for |
| 3864 | this rule is zero length arrays. These arrays are defined to be |
| 3865 | accessible as variable length arrays, which requires access beyond the |
| 3866 | zero'th element.</p> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3867 | |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 3868 | <p>The getelementptr instruction is often confusing. For some more insight |
| 3869 | into how it works, see <a href="GetElementPtr.html">the getelementptr |
| 3870 | FAQ</a>.</p> |
| 3871 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3872 | <h5>Example:</h5> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3873 | |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3874 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3875 | <i>; yields [12 x i8]*:aptr</i> |
Matthijs Kooijman | e49d0bc | 2008-10-13 13:44:15 +0000 | [diff] [blame] | 3876 | %aptr = getelementptr {i32, [12 x i8]}* %saptr, i64 0, i32 1 |
| 3877 | <i>; yields i8*:vptr</i> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 3878 | %vptr = getelementptr {i32, <2 x i8>}* %svptr, i64 0, i32 1, i32 1 |
Matthijs Kooijman | e49d0bc | 2008-10-13 13:44:15 +0000 | [diff] [blame] | 3879 | <i>; yields i8*:eptr</i> |
| 3880 | %eptr = getelementptr [12 x i8]* %aptr, i64 0, i32 1 |
Sanjiv Gupta | 9f805c2 | 2009-04-25 07:27:44 +0000 | [diff] [blame] | 3881 | <i>; yields i32*:iptr</i> |
Sanjiv Gupta | 16ffa80 | 2009-04-24 16:38:13 +0000 | [diff] [blame] | 3882 | %iptr = getelementptr [10 x i32]* @arr, i16 0, i16 0 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3883 | </pre> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3884 | </div> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3885 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3886 | <!-- ======================================================================= --> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3887 | <div class="doc_subsection"> <a name="convertops">Conversion Operations</a> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3888 | </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3889 | <div class="doc_text"> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3890 | <p>The instructions in this category are the conversion instructions (casting) |
| 3891 | which all take a single operand and a type. They perform various bit conversions |
| 3892 | on the operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3893 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3894 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3895 | <!-- _______________________________________________________________________ --> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3896 | <div class="doc_subsubsection"> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3897 | <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a> |
| 3898 | </div> |
| 3899 | <div class="doc_text"> |
| 3900 | |
| 3901 | <h5>Syntax:</h5> |
| 3902 | <pre> |
| 3903 | <result> = trunc <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3904 | </pre> |
| 3905 | |
| 3906 | <h5>Overview:</h5> |
| 3907 | <p> |
| 3908 | The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>. |
| 3909 | </p> |
| 3910 | |
| 3911 | <h5>Arguments:</h5> |
| 3912 | <p> |
| 3913 | The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must |
| 3914 | 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] | 3915 | 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] | 3916 | type. The bit size of <tt>value</tt> must be larger than the bit size of |
| 3917 | <tt>ty2</tt>. Equal sized types are not allowed.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3918 | |
| 3919 | <h5>Semantics:</h5> |
| 3920 | <p> |
| 3921 | 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] | 3922 | and converts the remaining bits to <tt>ty2</tt>. Since the source size must be |
| 3923 | larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>. |
| 3924 | It will always truncate bits.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3925 | |
| 3926 | <h5>Example:</h5> |
| 3927 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3928 | %X = trunc i32 257 to i8 <i>; yields i8:1</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3929 | %Y = trunc i32 123 to i1 <i>; yields i1:true</i> |
| 3930 | %Y = trunc i32 122 to i1 <i>; yields i1:false</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3931 | </pre> |
| 3932 | </div> |
| 3933 | |
| 3934 | <!-- _______________________________________________________________________ --> |
| 3935 | <div class="doc_subsubsection"> |
| 3936 | <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a> |
| 3937 | </div> |
| 3938 | <div class="doc_text"> |
| 3939 | |
| 3940 | <h5>Syntax:</h5> |
| 3941 | <pre> |
| 3942 | <result> = zext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3943 | </pre> |
| 3944 | |
| 3945 | <h5>Overview:</h5> |
| 3946 | <p>The '<tt>zext</tt>' instruction zero extends its operand to type |
| 3947 | <tt>ty2</tt>.</p> |
| 3948 | |
| 3949 | |
| 3950 | <h5>Arguments:</h5> |
| 3951 | <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] | 3952 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must |
| 3953 | 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] | 3954 | <tt>value</tt> must be smaller than the bit size of the destination type, |
| 3955 | <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3956 | |
| 3957 | <h5>Semantics:</h5> |
| 3958 | <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] | 3959 | 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] | 3960 | |
Reid Spencer | b592952 | 2007-01-12 15:46:11 +0000 | [diff] [blame] | 3961 | <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] | 3962 | |
| 3963 | <h5>Example:</h5> |
| 3964 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3965 | %X = zext i32 257 to i64 <i>; yields i64:257</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3966 | %Y = zext i1 true to i32 <i>; yields i32:1</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3967 | </pre> |
| 3968 | </div> |
| 3969 | |
| 3970 | <!-- _______________________________________________________________________ --> |
| 3971 | <div class="doc_subsubsection"> |
| 3972 | <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a> |
| 3973 | </div> |
| 3974 | <div class="doc_text"> |
| 3975 | |
| 3976 | <h5>Syntax:</h5> |
| 3977 | <pre> |
| 3978 | <result> = sext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3979 | </pre> |
| 3980 | |
| 3981 | <h5>Overview:</h5> |
| 3982 | <p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p> |
| 3983 | |
| 3984 | <h5>Arguments:</h5> |
| 3985 | <p> |
| 3986 | 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] | 3987 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must |
| 3988 | 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] | 3989 | <tt>value</tt> must be smaller than the bit size of the destination type, |
| 3990 | <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3991 | |
| 3992 | <h5>Semantics:</h5> |
| 3993 | <p> |
| 3994 | The '<tt>sext</tt>' instruction performs a sign extension by copying the sign |
| 3995 | 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] | 3996 | the type <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3997 | |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3998 | <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] | 3999 | |
| 4000 | <h5>Example:</h5> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4001 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4002 | %X = sext i8 -1 to i16 <i>; yields i16 :65535</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 4003 | %Y = sext i1 true to i32 <i>; yields i32:-1</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4004 | </pre> |
| 4005 | </div> |
| 4006 | |
| 4007 | <!-- _______________________________________________________________________ --> |
| 4008 | <div class="doc_subsubsection"> |
Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 4009 | <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a> |
| 4010 | </div> |
| 4011 | |
| 4012 | <div class="doc_text"> |
| 4013 | |
| 4014 | <h5>Syntax:</h5> |
| 4015 | |
| 4016 | <pre> |
| 4017 | <result> = fptrunc <ty> <value> to <ty2> <i>; yields ty2</i> |
| 4018 | </pre> |
| 4019 | |
| 4020 | <h5>Overview:</h5> |
| 4021 | <p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type |
| 4022 | <tt>ty2</tt>.</p> |
| 4023 | |
| 4024 | |
| 4025 | <h5>Arguments:</h5> |
| 4026 | <p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating |
| 4027 | point</a> value to cast and a <a href="#t_floating">floating point</a> type to |
| 4028 | cast it to. The size of <tt>value</tt> must be larger than the size of |
| 4029 | <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a |
| 4030 | <i>no-op cast</i>.</p> |
| 4031 | |
| 4032 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4033 | <p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger |
| 4034 | <a href="#t_floating">floating point</a> type to a smaller |
| 4035 | <a href="#t_floating">floating point</a> type. If the value cannot fit within |
| 4036 | the destination type, <tt>ty2</tt>, then the results are undefined.</p> |
Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 4037 | |
| 4038 | <h5>Example:</h5> |
| 4039 | <pre> |
| 4040 | %X = fptrunc double 123.0 to float <i>; yields float:123.0</i> |
| 4041 | %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i> |
| 4042 | </pre> |
| 4043 | </div> |
| 4044 | |
| 4045 | <!-- _______________________________________________________________________ --> |
| 4046 | <div class="doc_subsubsection"> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4047 | <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a> |
| 4048 | </div> |
| 4049 | <div class="doc_text"> |
| 4050 | |
| 4051 | <h5>Syntax:</h5> |
| 4052 | <pre> |
| 4053 | <result> = fpext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 4054 | </pre> |
| 4055 | |
| 4056 | <h5>Overview:</h5> |
| 4057 | <p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger |
| 4058 | floating point value.</p> |
| 4059 | |
| 4060 | <h5>Arguments:</h5> |
| 4061 | <p>The '<tt>fpext</tt>' instruction takes a |
| 4062 | <a href="#t_floating">floating point</a> <tt>value</tt> to cast, |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4063 | and a <a href="#t_floating">floating point</a> type to cast it to. The source |
| 4064 | type must be smaller than the destination type.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4065 | |
| 4066 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4067 | <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] | 4068 | <a href="#t_floating">floating point</a> type to a larger |
| 4069 | <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] | 4070 | 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] | 4071 | <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] | 4072 | |
| 4073 | <h5>Example:</h5> |
| 4074 | <pre> |
| 4075 | %X = fpext float 3.1415 to double <i>; yields double:3.1415</i> |
| 4076 | %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i> |
| 4077 | </pre> |
| 4078 | </div> |
| 4079 | |
| 4080 | <!-- _______________________________________________________________________ --> |
| 4081 | <div class="doc_subsubsection"> |
Reid Spencer | 24d6da5 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 4082 | <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4083 | </div> |
| 4084 | <div class="doc_text"> |
| 4085 | |
| 4086 | <h5>Syntax:</h5> |
| 4087 | <pre> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 4088 | <result> = fptoui <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4089 | </pre> |
| 4090 | |
| 4091 | <h5>Overview:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 4092 | <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] | 4093 | unsigned integer equivalent of type <tt>ty2</tt>. |
| 4094 | </p> |
| 4095 | |
| 4096 | <h5>Arguments:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 4097 | <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] | 4098 | scalar or vector <a href="#t_floating">floating point</a> value, and a type |
| 4099 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> |
| 4100 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a |
| 4101 | 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] | 4102 | |
| 4103 | <h5>Semantics:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 4104 | <p> The '<tt>fptoui</tt>' instruction converts its |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4105 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 4106 | towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>, |
| 4107 | the results are undefined.</p> |
| 4108 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4109 | <h5>Example:</h5> |
| 4110 | <pre> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 4111 | %X = fptoui double 123.0 to i32 <i>; yields i32:123</i> |
Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 4112 | %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] | 4113 | %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] | 4114 | </pre> |
| 4115 | </div> |
| 4116 | |
| 4117 | <!-- _______________________________________________________________________ --> |
| 4118 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4119 | <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4120 | </div> |
| 4121 | <div class="doc_text"> |
| 4122 | |
| 4123 | <h5>Syntax:</h5> |
| 4124 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4125 | <result> = fptosi <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4126 | </pre> |
| 4127 | |
| 4128 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4129 | <p>The '<tt>fptosi</tt>' instruction converts |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4130 | <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] | 4131 | </p> |
| 4132 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4133 | <h5>Arguments:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4134 | <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] | 4135 | scalar or vector <a href="#t_floating">floating point</a> value, and a type |
| 4136 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> |
| 4137 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a |
| 4138 | 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] | 4139 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4140 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4141 | <p>The '<tt>fptosi</tt>' instruction converts its |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4142 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 4143 | towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>, |
| 4144 | the results are undefined.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4145 | |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 4146 | <h5>Example:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4147 | <pre> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 4148 | %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i> |
Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 4149 | %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] | 4150 | %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] | 4151 | </pre> |
| 4152 | </div> |
| 4153 | |
| 4154 | <!-- _______________________________________________________________________ --> |
| 4155 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4156 | <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4157 | </div> |
| 4158 | <div class="doc_text"> |
| 4159 | |
| 4160 | <h5>Syntax:</h5> |
| 4161 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4162 | <result> = uitofp <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4163 | </pre> |
| 4164 | |
| 4165 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4166 | <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] | 4167 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 4168 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4169 | <h5>Arguments:</h5> |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 4170 | <p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a |
| 4171 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it |
| 4172 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a> |
| 4173 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector |
| 4174 | 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] | 4175 | |
| 4176 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4177 | <p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4178 | integer quantity and converts it to the corresponding floating point value. If |
Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 4179 | 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] | 4180 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4181 | <h5>Example:</h5> |
| 4182 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4183 | %X = uitofp i32 257 to float <i>; yields float:257.0</i> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4184 | %Y = uitofp i8 -1 to double <i>; yields double:255.0</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4185 | </pre> |
| 4186 | </div> |
| 4187 | |
| 4188 | <!-- _______________________________________________________________________ --> |
| 4189 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4190 | <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4191 | </div> |
| 4192 | <div class="doc_text"> |
| 4193 | |
| 4194 | <h5>Syntax:</h5> |
| 4195 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4196 | <result> = sitofp <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4197 | </pre> |
| 4198 | |
| 4199 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4200 | <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] | 4201 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 4202 | |
| 4203 | <h5>Arguments:</h5> |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 4204 | <p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a |
| 4205 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it |
| 4206 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a> |
| 4207 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector |
| 4208 | 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] | 4209 | |
| 4210 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 4211 | <p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4212 | integer quantity and converts it to the corresponding floating point value. If |
Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 4213 | 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] | 4214 | |
| 4215 | <h5>Example:</h5> |
| 4216 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4217 | %X = sitofp i32 257 to float <i>; yields float:257.0</i> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4218 | %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4219 | </pre> |
| 4220 | </div> |
| 4221 | |
| 4222 | <!-- _______________________________________________________________________ --> |
| 4223 | <div class="doc_subsubsection"> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 4224 | <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a> |
| 4225 | </div> |
| 4226 | <div class="doc_text"> |
| 4227 | |
| 4228 | <h5>Syntax:</h5> |
| 4229 | <pre> |
| 4230 | <result> = ptrtoint <ty> <value> to <ty2> <i>; yields ty2</i> |
| 4231 | </pre> |
| 4232 | |
| 4233 | <h5>Overview:</h5> |
| 4234 | <p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to |
| 4235 | the integer type <tt>ty2</tt>.</p> |
| 4236 | |
| 4237 | <h5>Arguments:</h5> |
| 4238 | <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] | 4239 | must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4240 | <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type.</p> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 4241 | |
| 4242 | <h5>Semantics:</h5> |
| 4243 | <p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type |
| 4244 | <tt>ty2</tt> by interpreting the pointer value as an integer and either |
| 4245 | truncating or zero extending that value to the size of the integer type. If |
| 4246 | <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If |
| 4247 | <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] | 4248 | are the same size, then nothing is done (<i>no-op cast</i>) other than a type |
| 4249 | change.</p> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 4250 | |
| 4251 | <h5>Example:</h5> |
| 4252 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4253 | %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i> |
| 4254 | %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] | 4255 | </pre> |
| 4256 | </div> |
| 4257 | |
| 4258 | <!-- _______________________________________________________________________ --> |
| 4259 | <div class="doc_subsubsection"> |
| 4260 | <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a> |
| 4261 | </div> |
| 4262 | <div class="doc_text"> |
| 4263 | |
| 4264 | <h5>Syntax:</h5> |
| 4265 | <pre> |
| 4266 | <result> = inttoptr <ty> <value> to <ty2> <i>; yields ty2</i> |
| 4267 | </pre> |
| 4268 | |
| 4269 | <h5>Overview:</h5> |
| 4270 | <p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to |
| 4271 | a pointer type, <tt>ty2</tt>.</p> |
| 4272 | |
| 4273 | <h5>Arguments:</h5> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 4274 | <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] | 4275 | value to cast, and a type to cast it to, which must be a |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4276 | <a href="#t_pointer">pointer</a> type.</p> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 4277 | |
| 4278 | <h5>Semantics:</h5> |
| 4279 | <p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type |
| 4280 | <tt>ty2</tt> by applying either a zero extension or a truncation depending on |
| 4281 | the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the |
| 4282 | size of a pointer then a truncation is done. If <tt>value</tt> is smaller than |
| 4283 | the size of a pointer then a zero extension is done. If they are the same size, |
| 4284 | nothing is done (<i>no-op cast</i>).</p> |
| 4285 | |
| 4286 | <h5>Example:</h5> |
| 4287 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4288 | %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i> |
| 4289 | %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i> |
| 4290 | %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] | 4291 | </pre> |
| 4292 | </div> |
| 4293 | |
| 4294 | <!-- _______________________________________________________________________ --> |
| 4295 | <div class="doc_subsubsection"> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 4296 | <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4297 | </div> |
| 4298 | <div class="doc_text"> |
| 4299 | |
| 4300 | <h5>Syntax:</h5> |
| 4301 | <pre> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 4302 | <result> = bitcast <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4303 | </pre> |
| 4304 | |
| 4305 | <h5>Overview:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4306 | |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 4307 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4308 | <tt>ty2</tt> without changing any bits.</p> |
| 4309 | |
| 4310 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4311 | |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 4312 | <p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be |
Dan Gohman | 500233a | 2008-09-08 16:45:59 +0000 | [diff] [blame] | 4313 | a non-aggregate first class value, and a type to cast it to, which must also be |
| 4314 | a non-aggregate <a href="#t_firstclass">first class</a> type. The bit sizes of |
| 4315 | <tt>value</tt> |
Reid Spencer | 19b569f | 2007-01-09 20:08:58 +0000 | [diff] [blame] | 4316 | 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] | 4317 | type is a pointer, the destination type must also be a pointer. This |
| 4318 | instruction supports bitwise conversion of vectors to integers and to vectors |
| 4319 | of other types (as long as they have the same size).</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4320 | |
| 4321 | <h5>Semantics:</h5> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 4322 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 4323 | <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with |
| 4324 | this conversion. The conversion is done as if the <tt>value</tt> had been |
| 4325 | stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be |
| 4326 | converted to other pointer types with this instruction. To convert pointers to |
| 4327 | other types, use the <a href="#i_inttoptr">inttoptr</a> or |
| 4328 | <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 4329 | |
| 4330 | <h5>Example:</h5> |
| 4331 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4332 | %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4333 | %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4334 | %Z = bitcast <2 x int> %V to i64; <i>; yields i64: %V</i> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 4335 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4336 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4337 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4338 | <!-- ======================================================================= --> |
| 4339 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> |
| 4340 | <div class="doc_text"> |
| 4341 | <p>The instructions in this category are the "miscellaneous" |
| 4342 | instructions, which defy better classification.</p> |
| 4343 | </div> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4344 | |
| 4345 | <!-- _______________________________________________________________________ --> |
| 4346 | <div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a> |
| 4347 | </div> |
| 4348 | <div class="doc_text"> |
| 4349 | <h5>Syntax:</h5> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4350 | <pre> <result> = icmp <cond> <ty> <op1>, <op2> <i>; yields {i1} or {<N x i1>}:result</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4351 | </pre> |
| 4352 | <h5>Overview:</h5> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4353 | <p>The '<tt>icmp</tt>' instruction returns a boolean value or |
| 4354 | a vector of boolean values based on comparison |
| 4355 | of its two integer, integer vector, or pointer operands.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4356 | <h5>Arguments:</h5> |
| 4357 | <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] | 4358 | the condition code indicating the kind of comparison to perform. It is not |
| 4359 | a value, just a keyword. The possible condition code are: |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4360 | </p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4361 | <ol> |
| 4362 | <li><tt>eq</tt>: equal</li> |
| 4363 | <li><tt>ne</tt>: not equal </li> |
| 4364 | <li><tt>ugt</tt>: unsigned greater than</li> |
| 4365 | <li><tt>uge</tt>: unsigned greater or equal</li> |
| 4366 | <li><tt>ult</tt>: unsigned less than</li> |
| 4367 | <li><tt>ule</tt>: unsigned less or equal</li> |
| 4368 | <li><tt>sgt</tt>: signed greater than</li> |
| 4369 | <li><tt>sge</tt>: signed greater or equal</li> |
| 4370 | <li><tt>slt</tt>: signed less than</li> |
| 4371 | <li><tt>sle</tt>: signed less or equal</li> |
| 4372 | </ol> |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 4373 | <p>The remaining two arguments must be <a href="#t_integer">integer</a> or |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4374 | <a href="#t_pointer">pointer</a> |
| 4375 | or integer <a href="#t_vector">vector</a> typed. |
| 4376 | They must also be identical types.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4377 | <h5>Semantics:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4378 | <p>The '<tt>icmp</tt>' compares <tt>op1</tt> and <tt>op2</tt> according to |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4379 | the condition code given as <tt>cond</tt>. The comparison performed always |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4380 | yields either an <a href="#t_primitive"><tt>i1</tt></a> or vector of <tt>i1</tt> result, as follows: |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4381 | </p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4382 | <ol> |
| 4383 | <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal, |
| 4384 | <tt>false</tt> otherwise. No sign interpretation is necessary or performed. |
| 4385 | </li> |
| 4386 | <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal, |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4387 | <tt>false</tt> otherwise. No sign interpretation is necessary or performed.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4388 | <li><tt>ugt</tt>: interprets the operands as unsigned values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4389 | <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4390 | <li><tt>uge</tt>: interprets the operands as unsigned values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4391 | <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4392 | <li><tt>ult</tt>: interprets the operands as unsigned values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4393 | <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4394 | <li><tt>ule</tt>: interprets the operands as unsigned values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4395 | <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4396 | <li><tt>sgt</tt>: interprets the operands as signed values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4397 | <tt>true</tt> if <tt>op1</tt> is greater than <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4398 | <li><tt>sge</tt>: interprets the operands as signed values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4399 | <tt>true</tt> if <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4400 | <li><tt>slt</tt>: interprets the operands as signed values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4401 | <tt>true</tt> if <tt>op1</tt> is less than <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4402 | <li><tt>sle</tt>: interprets the operands as signed values and yields |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4403 | <tt>true</tt> if <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4404 | </ol> |
| 4405 | <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] | 4406 | values are compared as if they were integers.</p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4407 | <p>If the operands are integer vectors, then they are compared |
| 4408 | element by element. The result is an <tt>i1</tt> vector with |
| 4409 | the same number of elements as the values being compared. |
| 4410 | Otherwise, the result is an <tt>i1</tt>. |
| 4411 | </p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4412 | |
| 4413 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4414 | <pre> <result> = icmp eq i32 4, 5 <i>; yields: result=false</i> |
| 4415 | <result> = icmp ne float* %X, %X <i>; yields: result=false</i> |
| 4416 | <result> = icmp ult i16 4, 5 <i>; yields: result=true</i> |
| 4417 | <result> = icmp sgt i16 4, 5 <i>; yields: result=false</i> |
| 4418 | <result> = icmp ule i16 -4, 5 <i>; yields: result=false</i> |
| 4419 | <result> = icmp sge i16 4, 5 <i>; yields: result=false</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4420 | </pre> |
Dan Gohman | c766f72 | 2009-01-22 01:39:38 +0000 | [diff] [blame] | 4421 | |
| 4422 | <p>Note that the code generator does not yet support vector types with |
| 4423 | the <tt>icmp</tt> instruction.</p> |
| 4424 | |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4425 | </div> |
| 4426 | |
| 4427 | <!-- _______________________________________________________________________ --> |
| 4428 | <div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a> |
| 4429 | </div> |
| 4430 | <div class="doc_text"> |
| 4431 | <h5>Syntax:</h5> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4432 | <pre> <result> = fcmp <cond> <ty> <op1>, <op2> <i>; yields {i1} or {<N x i1>}:result</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4433 | </pre> |
| 4434 | <h5>Overview:</h5> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4435 | <p>The '<tt>fcmp</tt>' instruction returns a boolean value |
| 4436 | or vector of boolean values based on comparison |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4437 | of its operands.</p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4438 | <p> |
| 4439 | If the operands are floating point scalars, then the result |
| 4440 | type is a boolean (<a href="#t_primitive"><tt>i1</tt></a>). |
| 4441 | </p> |
| 4442 | <p>If the operands are floating point vectors, then the result type |
| 4443 | is a vector of boolean with the same number of elements as the |
| 4444 | operands being compared.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4445 | <h5>Arguments:</h5> |
| 4446 | <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] | 4447 | the condition code indicating the kind of comparison to perform. It is not |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4448 | a value, just a keyword. The possible condition code are:</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4449 | <ol> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4450 | <li><tt>false</tt>: no comparison, always returns false</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4451 | <li><tt>oeq</tt>: ordered and equal</li> |
| 4452 | <li><tt>ogt</tt>: ordered and greater than </li> |
| 4453 | <li><tt>oge</tt>: ordered and greater than or equal</li> |
| 4454 | <li><tt>olt</tt>: ordered and less than </li> |
| 4455 | <li><tt>ole</tt>: ordered and less than or equal</li> |
| 4456 | <li><tt>one</tt>: ordered and not equal</li> |
| 4457 | <li><tt>ord</tt>: ordered (no nans)</li> |
| 4458 | <li><tt>ueq</tt>: unordered or equal</li> |
| 4459 | <li><tt>ugt</tt>: unordered or greater than </li> |
| 4460 | <li><tt>uge</tt>: unordered or greater than or equal</li> |
| 4461 | <li><tt>ult</tt>: unordered or less than </li> |
| 4462 | <li><tt>ule</tt>: unordered or less than or equal</li> |
| 4463 | <li><tt>une</tt>: unordered or not equal</li> |
| 4464 | <li><tt>uno</tt>: unordered (either nans)</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4465 | <li><tt>true</tt>: no comparison, always returns true</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4466 | </ol> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4467 | <p><i>Ordered</i> means that neither operand is a QNAN while |
Reid Spencer | 93a4985 | 2006-12-06 07:08:07 +0000 | [diff] [blame] | 4468 | <i>unordered</i> means that either operand may be a QNAN.</p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4469 | <p>Each of <tt>val1</tt> and <tt>val2</tt> arguments must be |
| 4470 | either a <a href="#t_floating">floating point</a> type |
| 4471 | or a <a href="#t_vector">vector</a> of floating point type. |
| 4472 | They must have identical types.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4473 | <h5>Semantics:</h5> |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4474 | <p>The '<tt>fcmp</tt>' instruction compares <tt>op1</tt> and <tt>op2</tt> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4475 | according to the condition code given as <tt>cond</tt>. |
| 4476 | If the operands are vectors, then the vectors are compared |
| 4477 | element by element. |
| 4478 | Each comparison performed |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4479 | always yields an <a href="#t_primitive">i1</a> result, as follows:</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4480 | <ol> |
| 4481 | <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] | 4482 | <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4483 | <tt>op1</tt> is equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4484 | <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4485 | <tt>op1</tt> is greather than <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4486 | <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4487 | <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4488 | <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4489 | <tt>op1</tt> is less than <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4490 | <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4491 | <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4492 | <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4493 | <tt>op1</tt> is not equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4494 | <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li> |
| 4495 | <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4496 | <tt>op1</tt> is equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4497 | <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4498 | <tt>op1</tt> is greater than <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4499 | <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4500 | <tt>op1</tt> is greater than or equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4501 | <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4502 | <tt>op1</tt> is less than <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4503 | <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4504 | <tt>op1</tt> is less than or equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4505 | <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Gabor Greif | fb224a2 | 2008-08-07 21:46:00 +0000 | [diff] [blame] | 4506 | <tt>op1</tt> is not equal to <tt>op2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 4507 | <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] | 4508 | <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li> |
| 4509 | </ol> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4510 | |
| 4511 | <h5>Example:</h5> |
| 4512 | <pre> <result> = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4513 | <result> = fcmp one float 4.0, 5.0 <i>; yields: result=true</i> |
| 4514 | <result> = fcmp olt float 4.0, 5.0 <i>; yields: result=true</i> |
| 4515 | <result> = fcmp ueq double 1.0, 2.0 <i>; yields: result=false</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4516 | </pre> |
Dan Gohman | c766f72 | 2009-01-22 01:39:38 +0000 | [diff] [blame] | 4517 | |
| 4518 | <p>Note that the code generator does not yet support vector types with |
| 4519 | the <tt>fcmp</tt> instruction.</p> |
| 4520 | |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 4521 | </div> |
| 4522 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4523 | <!-- _______________________________________________________________________ --> |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 4524 | <div class="doc_subsubsection"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4525 | <a name="i_phi">'<tt>phi</tt>' Instruction</a> |
| 4526 | </div> |
| 4527 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4528 | <div class="doc_text"> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4529 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4530 | <h5>Syntax:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4531 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4532 | <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> |
| 4533 | <h5>Overview:</h5> |
| 4534 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in |
| 4535 | the SSA graph representing the function.</p> |
| 4536 | <h5>Arguments:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4537 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4538 | <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] | 4539 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs |
| 4540 | as arguments, with one pair for each predecessor basic block of the |
| 4541 | current block. Only values of <a href="#t_firstclass">first class</a> |
| 4542 | type may be used as the value arguments to the PHI node. Only labels |
| 4543 | may be used as the label arguments.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4544 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4545 | <p>There must be no non-phi instructions between the start of a basic |
| 4546 | block and the PHI instructions: i.e. PHI instructions must be first in |
| 4547 | a basic block.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4548 | |
Jay Foad | d244909 | 2009-06-03 10:20:10 +0000 | [diff] [blame] | 4549 | <p>For the purposes of the SSA form, the use of each incoming value is |
| 4550 | deemed to occur on the edge from the corresponding predecessor block |
| 4551 | to the current block (but after any definition of an '<tt>invoke</tt>' |
| 4552 | instruction's return value on the same edge).</p> |
| 4553 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4554 | <h5>Semantics:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4555 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4556 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value |
| 4557 | specified by the pair corresponding to the predecessor basic block that executed |
| 4558 | just prior to the current block.</p> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4559 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4560 | <h5>Example:</h5> |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4561 | <pre> |
| 4562 | Loop: ; Infinite loop that counts from 0 on up... |
| 4563 | %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ] |
| 4564 | %nextindvar = add i32 %indvar, 1 |
| 4565 | br label %Loop |
| 4566 | </pre> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 4567 | </div> |
| 4568 | |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4569 | <!-- _______________________________________________________________________ --> |
| 4570 | <div class="doc_subsubsection"> |
| 4571 | <a name="i_select">'<tt>select</tt>' Instruction</a> |
| 4572 | </div> |
| 4573 | |
| 4574 | <div class="doc_text"> |
| 4575 | |
| 4576 | <h5>Syntax:</h5> |
| 4577 | |
| 4578 | <pre> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4579 | <result> = select <i>selty</i> <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i> |
| 4580 | |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4581 | <i>selty</i> is either i1 or {<N x i1>} |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4582 | </pre> |
| 4583 | |
| 4584 | <h5>Overview:</h5> |
| 4585 | |
| 4586 | <p> |
| 4587 | The '<tt>select</tt>' instruction is used to choose one value based on a |
| 4588 | condition, without branching. |
| 4589 | </p> |
| 4590 | |
| 4591 | |
| 4592 | <h5>Arguments:</h5> |
| 4593 | |
| 4594 | <p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4595 | The '<tt>select</tt>' instruction requires an 'i1' value or |
| 4596 | a vector of 'i1' values indicating the |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4597 | condition, and two values of the same <a href="#t_firstclass">first class</a> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4598 | type. If the val1/val2 are vectors and |
| 4599 | the condition is a scalar, then entire vectors are selected, not |
Chris Lattner | 5568e94 | 2008-05-20 20:48:21 +0000 | [diff] [blame] | 4600 | individual elements. |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4601 | </p> |
| 4602 | |
| 4603 | <h5>Semantics:</h5> |
| 4604 | |
| 4605 | <p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4606 | If the condition is an i1 and it evaluates to 1, the instruction returns the first |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4607 | value argument; otherwise, it returns the second value argument. |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4608 | </p> |
Dan Gohman | f72fb67 | 2008-09-09 01:02:47 +0000 | [diff] [blame] | 4609 | <p> |
| 4610 | If the condition is a vector of i1, then the value arguments must |
| 4611 | be vectors of the same size, and the selection is done element |
| 4612 | by element. |
| 4613 | </p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4614 | |
| 4615 | <h5>Example:</h5> |
| 4616 | |
| 4617 | <pre> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 4618 | %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] | 4619 | </pre> |
Dan Gohman | c766f72 | 2009-01-22 01:39:38 +0000 | [diff] [blame] | 4620 | |
| 4621 | <p>Note that the code generator does not yet support conditions |
| 4622 | with vector type.</p> |
| 4623 | |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 4624 | </div> |
| 4625 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 4626 | |
| 4627 | <!-- _______________________________________________________________________ --> |
| 4628 | <div class="doc_subsubsection"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4629 | <a name="i_call">'<tt>call</tt>' Instruction</a> |
| 4630 | </div> |
| 4631 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4632 | <div class="doc_text"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4633 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4634 | <h5>Syntax:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4635 | <pre> |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 4636 | <result> = [tail] call [<a href="#callingconv">cconv</a>] [<a href="#paramattrs">ret attrs</a>] <ty> [<fnty>*] <fnptrval>(<function args>) [<a href="#fnattrs">fn attrs</a>] |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4637 | </pre> |
| 4638 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4639 | <h5>Overview:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4640 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4641 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4642 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4643 | <h5>Arguments:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4644 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4645 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4646 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4647 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4648 | <li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4649 | <p>The optional "tail" marker indicates whether the callee function accesses |
| 4650 | 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] | 4651 | function call is eligible for tail call optimization. Note that calls may |
| 4652 | be marked "tail" even if they do not occur before a <a |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4653 | href="#i_ret"><tt>ret</tt></a> instruction.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4654 | </li> |
| 4655 | <li> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 4656 | <p>The optional "cconv" marker indicates which <a href="#callingconv">calling |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4657 | convention</a> the call should use. If none is specified, the call defaults |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4658 | to using C calling conventions.</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4659 | </li> |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 4660 | |
| 4661 | <li> |
| 4662 | <p>The optional <a href="#paramattrs">Parameter Attributes</a> list for |
| 4663 | return values. Only '<tt>zeroext</tt>', '<tt>signext</tt>', |
| 4664 | and '<tt>inreg</tt>' attributes are valid here.</p> |
| 4665 | </li> |
| 4666 | |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 4667 | <li> |
Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 4668 | <p>'<tt>ty</tt>': the type of the call instruction itself which is also |
| 4669 | the type of the return value. Functions that return no value are marked |
| 4670 | <tt><a href="#t_void">void</a></tt>.</p> |
| 4671 | </li> |
| 4672 | <li> |
| 4673 | <p>'<tt>fnty</tt>': shall be the signature of the pointer to function |
| 4674 | value being invoked. The argument types must match the types implied by |
| 4675 | this signature. This type can be omitted if the function is not varargs |
| 4676 | 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] | 4677 | </li> |
| 4678 | <li> |
| 4679 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to |
| 4680 | be invoked. In most cases, this is a direct function invocation, but |
| 4681 | 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] | 4682 | to function value.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4683 | </li> |
| 4684 | <li> |
| 4685 | <p>'<tt>function args</tt>': argument list whose types match the |
Reid Spencer | a7e302a | 2005-05-01 22:22:57 +0000 | [diff] [blame] | 4686 | function signature argument types. All arguments must be of |
| 4687 | <a href="#t_firstclass">first class</a> type. If the function signature |
| 4688 | indicates the function accepts a variable number of arguments, the extra |
| 4689 | arguments can be specified.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4690 | </li> |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 4691 | <li> |
Devang Patel | 307e8ab | 2008-10-07 17:48:33 +0000 | [diff] [blame] | 4692 | <p>The optional <a href="#fnattrs">function attributes</a> list. Only |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 4693 | '<tt>noreturn</tt>', '<tt>nounwind</tt>', '<tt>readonly</tt>' and |
| 4694 | '<tt>readnone</tt>' attributes are valid here.</p> |
| 4695 | </li> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 4696 | </ol> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4697 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4698 | <h5>Semantics:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4699 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4700 | <p>The '<tt>call</tt>' instruction is used to cause control flow to |
| 4701 | transfer to a specified function, with its incoming arguments bound to |
| 4702 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' |
| 4703 | instruction in the called function, control flow continues with the |
| 4704 | instruction after the function call, and the return value of the |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4705 | function is bound to the result argument.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4706 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4707 | <h5>Example:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4708 | |
| 4709 | <pre> |
Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 4710 | %retval = call i32 @test(i32 %argc) |
Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 4711 | call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i> |
| 4712 | %X = tail call i32 @foo() <i>; yields i32</i> |
| 4713 | %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i> |
| 4714 | call void %foo(i8 97 signext) |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4715 | |
| 4716 | %struct.A = type { i32, i8 } |
Devang Patel | f642f47 | 2008-10-06 18:50:38 +0000 | [diff] [blame] | 4717 | %r = call %struct.A @foo() <i>; yields { 32, i8 }</i> |
Dan Gohman | b1e6b96 | 2008-10-04 19:00:07 +0000 | [diff] [blame] | 4718 | %gr = extractvalue %struct.A %r, 0 <i>; yields i32</i> |
| 4719 | %gr1 = extractvalue %struct.A %r, 1 <i>; yields i8</i> |
Chris Lattner | 85a350f | 2008-10-08 06:26:11 +0000 | [diff] [blame] | 4720 | %Z = call void @foo() noreturn <i>; indicates that %foo never returns normally</i> |
Matthijs Kooijman | cb73d19 | 2008-10-07 10:03:45 +0000 | [diff] [blame] | 4721 | %ZZ = call zeroext i32 @bar() <i>; Return value is %zero extended</i> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 4722 | </pre> |
| 4723 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4724 | </div> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4725 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4726 | <!-- _______________________________________________________________________ --> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4727 | <div class="doc_subsubsection"> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 4728 | <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4729 | </div> |
| 4730 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4731 | <div class="doc_text"> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4732 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4733 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4734 | |
| 4735 | <pre> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4736 | <resultval> = va_arg <va_list*> <arglist>, <argty> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4737 | </pre> |
| 4738 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4739 | <h5>Overview:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4740 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4741 | <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] | 4742 | the "variable argument" area of a function call. It is used to implement the |
| 4743 | <tt>va_arg</tt> macro in C.</p> |
| 4744 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4745 | <h5>Arguments:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4746 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4747 | <p>This instruction takes a <tt>va_list*</tt> value and the type of |
| 4748 | the argument. It returns a value of the specified argument type and |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4749 | 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] | 4750 | actual type of <tt>va_list</tt> is target specific.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4751 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4752 | <h5>Semantics:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4753 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4754 | <p>The '<tt>va_arg</tt>' instruction loads an argument of the specified |
| 4755 | type from the specified <tt>va_list</tt> and causes the |
| 4756 | <tt>va_list</tt> to point to the next argument. For more information, |
| 4757 | see the variable argument handling <a href="#int_varargs">Intrinsic |
| 4758 | Functions</a>.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4759 | |
| 4760 | <p>It is legal for this instruction to be called in a function which does not |
| 4761 | take a variable number of arguments, for example, the <tt>vfprintf</tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4762 | function.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4763 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4764 | <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] | 4765 | href="#intrinsics">intrinsic function</a> because it takes a type as an |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4766 | argument.</p> |
| 4767 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4768 | <h5>Example:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4769 | |
| 4770 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> |
| 4771 | |
Dan Gohman | f3e60bd | 2009-01-12 23:12:39 +0000 | [diff] [blame] | 4772 | <p>Note that the code generator does not yet fully support va_arg |
| 4773 | on many targets. Also, it does not currently support va_arg with |
| 4774 | aggregate types on any target.</p> |
| 4775 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4776 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4777 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4778 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4779 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> |
| 4780 | <!-- *********************************************************************** --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4781 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4782 | <div class="doc_text"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4783 | |
| 4784 | <p>LLVM supports the notion of an "intrinsic function". These functions have |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4785 | well known names and semantics and are required to follow certain restrictions. |
| 4786 | Overall, these intrinsics represent an extension mechanism for the LLVM |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4787 | 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] | 4788 | 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] | 4789 | |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4790 | <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] | 4791 | prefix is reserved in LLVM for intrinsic names; thus, function names may not |
| 4792 | begin with this prefix. Intrinsic functions must always be external functions: |
| 4793 | you cannot define the body of intrinsic functions. Intrinsic functions may |
| 4794 | only be used in call or invoke instructions: it is illegal to take the address |
| 4795 | of an intrinsic function. Additionally, because intrinsic functions are part |
| 4796 | of the LLVM language, it is required if any are added that they be documented |
| 4797 | here.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4798 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4799 | <p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents |
| 4800 | a family of functions that perform the same operation but on different data |
| 4801 | types. Because LLVM can represent over 8 million different integer types, |
| 4802 | overloading is used commonly to allow an intrinsic function to operate on any |
| 4803 | integer type. One or more of the argument types or the result type can be |
| 4804 | overloaded to accept any integer type. Argument types may also be defined as |
| 4805 | exactly matching a previous argument's type or the result type. This allows an |
| 4806 | intrinsic function which accepts multiple arguments, but needs all of them to |
| 4807 | be of the same type, to only be overloaded with respect to a single argument or |
| 4808 | the result.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4809 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4810 | <p>Overloaded intrinsics will have the names of its overloaded argument types |
| 4811 | encoded into its function name, each preceded by a period. Only those types |
| 4812 | which are overloaded result in a name suffix. Arguments whose type is matched |
| 4813 | against another type do not. For example, the <tt>llvm.ctpop</tt> function can |
| 4814 | take an integer of any width and returns an integer of exactly the same integer |
| 4815 | width. This leads to a family of functions such as |
| 4816 | <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>. |
| 4817 | Only one type, the return type, is overloaded, and only one type suffix is |
| 4818 | required. Because the argument's type is matched against the return type, it |
| 4819 | does not require its own name suffix.</p> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4820 | |
| 4821 | <p>To learn how to add an intrinsic function, please see the |
| 4822 | <a href="ExtendingLLVM.html">Extending LLVM Guide</a>. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4823 | </p> |
| 4824 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4825 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4826 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4827 | <!-- ======================================================================= --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4828 | <div class="doc_subsection"> |
| 4829 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> |
| 4830 | </div> |
| 4831 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4832 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4833 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4834 | <p>Variable argument support is defined in LLVM with the <a |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 4835 | 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] | 4836 | intrinsic functions. These functions are related to the similarly |
| 4837 | named macros defined in the <tt><stdarg.h></tt> header file.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4838 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4839 | <p>All of these functions operate on arguments that use a |
| 4840 | target-specific value type "<tt>va_list</tt>". The LLVM assembly |
| 4841 | language reference manual does not define what this type is, so all |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4842 | transformations should be prepared to handle these functions regardless of |
| 4843 | the type used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4844 | |
Chris Lattner | 374ab30 | 2006-05-15 17:26:46 +0000 | [diff] [blame] | 4845 | <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] | 4846 | instruction and the variable argument handling intrinsic functions are |
| 4847 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4848 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4849 | <div class="doc_code"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4850 | <pre> |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4851 | define i32 @test(i32 %X, ...) { |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4852 | ; Initialize variable argument processing |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4853 | %ap = alloca i8* |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4854 | %ap2 = bitcast i8** %ap to i8* |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4855 | call void @llvm.va_start(i8* %ap2) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4856 | |
| 4857 | ; Read a single integer argument |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4858 | %tmp = va_arg i8** %ap, i32 |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4859 | |
| 4860 | ; Demonstrate usage of llvm.va_copy and llvm.va_end |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4861 | %aq = alloca i8* |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4862 | %aq2 = bitcast i8** %aq to i8* |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4863 | call void @llvm.va_copy(i8* %aq2, i8* %ap2) |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4864 | call void @llvm.va_end(i8* %aq2) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4865 | |
| 4866 | ; Stop processing of arguments. |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4867 | call void @llvm.va_end(i8* %ap2) |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4868 | ret i32 %tmp |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4869 | } |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4870 | |
| 4871 | declare void @llvm.va_start(i8*) |
| 4872 | declare void @llvm.va_copy(i8*, i8*) |
| 4873 | declare void @llvm.va_end(i8*) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4874 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4875 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4876 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4877 | </div> |
| 4878 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4879 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4880 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4881 | <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4882 | </div> |
| 4883 | |
| 4884 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4885 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4886 | <h5>Syntax:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4887 | <pre> declare void %llvm.va_start(i8* <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4888 | <h5>Overview:</h5> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4889 | <p>The '<tt>llvm.va_start</tt>' intrinsic initializes |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4890 | <tt>*<arglist></tt> for subsequent use by <tt><a |
| 4891 | href="#i_va_arg">va_arg</a></tt>.</p> |
| 4892 | |
| 4893 | <h5>Arguments:</h5> |
| 4894 | |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4895 | <p>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4896 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4897 | <h5>Semantics:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4898 | |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 4899 | <p>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4900 | macro available in C. In a target-dependent way, it initializes the |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4901 | <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] | 4902 | <tt>va_arg</tt> will produce the first variable argument passed to the function. |
| 4903 | 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] | 4904 | 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] | 4905 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4906 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4907 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4908 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4909 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4910 | <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4911 | </div> |
| 4912 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4913 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4914 | <h5>Syntax:</h5> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4915 | <pre> declare void @llvm.va_end(i8* <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4916 | <h5>Overview:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4917 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4918 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*<arglist></tt>, |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4919 | 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] | 4920 | 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] | 4921 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4922 | <h5>Arguments:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4923 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4924 | <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] | 4925 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4926 | <h5>Semantics:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4927 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4928 | <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] | 4929 | macro available in C. In a target-dependent way, it destroys the |
| 4930 | <tt>va_list</tt> element to which the argument points. Calls to <a |
| 4931 | href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy"> |
| 4932 | <tt>llvm.va_copy</tt></a> must be matched exactly with calls to |
| 4933 | <tt>llvm.va_end</tt>.</p> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4934 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4935 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4936 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4937 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4938 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4939 | <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4940 | </div> |
| 4941 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4942 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4943 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4944 | <h5>Syntax:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4945 | |
| 4946 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4947 | declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4948 | </pre> |
| 4949 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4950 | <h5>Overview:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4951 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4952 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position |
| 4953 | from the source argument list to the destination argument list.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4954 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4955 | <h5>Arguments:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4956 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4957 | <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] | 4958 | 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] | 4959 | |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4960 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4961 | <h5>Semantics:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4962 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4963 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> |
| 4964 | macro available in C. In a target-dependent way, it copies the source |
| 4965 | <tt>va_list</tt> element into the destination <tt>va_list</tt> element. This |
| 4966 | intrinsic is necessary because the <tt><a href="#int_va_start"> |
| 4967 | llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for |
| 4968 | example, memory allocation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4969 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4970 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4971 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4972 | <!-- ======================================================================= --> |
| 4973 | <div class="doc_subsection"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4974 | <a name="int_gc">Accurate Garbage Collection Intrinsics</a> |
| 4975 | </div> |
| 4976 | |
| 4977 | <div class="doc_text"> |
| 4978 | |
| 4979 | <p> |
| 4980 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 4981 | Collection</a> (GC) requires the implementation and generation of these |
| 4982 | intrinsics. |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4983 | 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] | 4984 | stack</a>, as well as garbage collector implementations that require <a |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4985 | 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] | 4986 | Front-ends for type-safe garbage collected languages should generate these |
| 4987 | intrinsics to make use of the LLVM garbage collectors. For more details, see <a |
| 4988 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. |
| 4989 | </p> |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 4990 | |
| 4991 | <p>The garbage collection intrinsics only operate on objects in the generic |
| 4992 | address space (address space zero).</p> |
| 4993 | |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4994 | </div> |
| 4995 | |
| 4996 | <!-- _______________________________________________________________________ --> |
| 4997 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4998 | <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4999 | </div> |
| 5000 | |
| 5001 | <div class="doc_text"> |
| 5002 | |
| 5003 | <h5>Syntax:</h5> |
| 5004 | |
| 5005 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5006 | declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5007 | </pre> |
| 5008 | |
| 5009 | <h5>Overview:</h5> |
| 5010 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 5011 | <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] | 5012 | the code generator, and allows some metadata to be associated with it.</p> |
| 5013 | |
| 5014 | <h5>Arguments:</h5> |
| 5015 | |
| 5016 | <p>The first argument specifies the address of a stack object that contains the |
| 5017 | root pointer. The second pointer (which must be either a constant or a global |
| 5018 | value address) contains the meta-data to be associated with the root.</p> |
| 5019 | |
| 5020 | <h5>Semantics:</h5> |
| 5021 | |
Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 5022 | <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] | 5023 | location. At compile-time, the code generator generates information to allow |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 5024 | the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>' |
| 5025 | intrinsic may only be used in a function which <a href="#gc">specifies a GC |
| 5026 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5027 | |
| 5028 | </div> |
| 5029 | |
| 5030 | |
| 5031 | <!-- _______________________________________________________________________ --> |
| 5032 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5033 | <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5034 | </div> |
| 5035 | |
| 5036 | <div class="doc_text"> |
| 5037 | |
| 5038 | <h5>Syntax:</h5> |
| 5039 | |
| 5040 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5041 | declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5042 | </pre> |
| 5043 | |
| 5044 | <h5>Overview:</h5> |
| 5045 | |
| 5046 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap |
| 5047 | locations, allowing garbage collector implementations that require read |
| 5048 | barriers.</p> |
| 5049 | |
| 5050 | <h5>Arguments:</h5> |
| 5051 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 5052 | <p>The second argument is the address to read from, which should be an address |
| 5053 | allocated from the garbage collector. The first object is a pointer to the |
| 5054 | start of the referenced object, if needed by the language runtime (otherwise |
| 5055 | null).</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5056 | |
| 5057 | <h5>Semantics:</h5> |
| 5058 | |
| 5059 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load |
| 5060 | instruction, but may be replaced with substantially more complex code by the |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 5061 | garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic |
| 5062 | may only be used in a function which <a href="#gc">specifies a GC |
| 5063 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5064 | |
| 5065 | </div> |
| 5066 | |
| 5067 | |
| 5068 | <!-- _______________________________________________________________________ --> |
| 5069 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5070 | <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5071 | </div> |
| 5072 | |
| 5073 | <div class="doc_text"> |
| 5074 | |
| 5075 | <h5>Syntax:</h5> |
| 5076 | |
| 5077 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5078 | declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5079 | </pre> |
| 5080 | |
| 5081 | <h5>Overview:</h5> |
| 5082 | |
| 5083 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap |
| 5084 | locations, allowing garbage collector implementations that require write |
| 5085 | barriers (such as generational or reference counting collectors).</p> |
| 5086 | |
| 5087 | <h5>Arguments:</h5> |
| 5088 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 5089 | <p>The first argument is the reference to store, the second is the start of the |
| 5090 | object to store it to, and the third is the address of the field of Obj to |
| 5091 | store to. If the runtime does not require a pointer to the object, Obj may be |
| 5092 | null.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5093 | |
| 5094 | <h5>Semantics:</h5> |
| 5095 | |
| 5096 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store |
| 5097 | instruction, but may be replaced with substantially more complex code by the |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 5098 | garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic |
| 5099 | may only be used in a function which <a href="#gc">specifies a GC |
| 5100 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 5101 | |
| 5102 | </div> |
| 5103 | |
| 5104 | |
| 5105 | |
| 5106 | <!-- ======================================================================= --> |
| 5107 | <div class="doc_subsection"> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5108 | <a name="int_codegen">Code Generator Intrinsics</a> |
| 5109 | </div> |
| 5110 | |
| 5111 | <div class="doc_text"> |
| 5112 | <p> |
| 5113 | These intrinsics are provided by LLVM to expose special features that may only |
| 5114 | be implemented with code generator support. |
| 5115 | </p> |
| 5116 | |
| 5117 | </div> |
| 5118 | |
| 5119 | <!-- _______________________________________________________________________ --> |
| 5120 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5121 | <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5122 | </div> |
| 5123 | |
| 5124 | <div class="doc_text"> |
| 5125 | |
| 5126 | <h5>Syntax:</h5> |
| 5127 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5128 | declare i8 *@llvm.returnaddress(i32 <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5129 | </pre> |
| 5130 | |
| 5131 | <h5>Overview:</h5> |
| 5132 | |
| 5133 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 5134 | The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a |
| 5135 | target-specific value indicating the return address of the current function |
| 5136 | or one of its callers. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5137 | </p> |
| 5138 | |
| 5139 | <h5>Arguments:</h5> |
| 5140 | |
| 5141 | <p> |
| 5142 | The argument to this intrinsic indicates which function to return the address |
| 5143 | for. Zero indicates the calling function, one indicates its caller, etc. The |
| 5144 | argument is <b>required</b> to be a constant integer value. |
| 5145 | </p> |
| 5146 | |
| 5147 | <h5>Semantics:</h5> |
| 5148 | |
| 5149 | <p> |
| 5150 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating |
| 5151 | the return address of the specified call frame, or zero if it cannot be |
| 5152 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 5153 | for arguments other than zero, so it should only be used for debugging purposes. |
| 5154 | </p> |
| 5155 | |
| 5156 | <p> |
| 5157 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 5158 | 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] | 5159 | source-language caller. |
| 5160 | </p> |
| 5161 | </div> |
| 5162 | |
| 5163 | |
| 5164 | <!-- _______________________________________________________________________ --> |
| 5165 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5166 | <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5167 | </div> |
| 5168 | |
| 5169 | <div class="doc_text"> |
| 5170 | |
| 5171 | <h5>Syntax:</h5> |
| 5172 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5173 | declare i8 *@llvm.frameaddress(i32 <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5174 | </pre> |
| 5175 | |
| 5176 | <h5>Overview:</h5> |
| 5177 | |
| 5178 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 5179 | The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the |
| 5180 | target-specific frame pointer value for the specified stack frame. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5181 | </p> |
| 5182 | |
| 5183 | <h5>Arguments:</h5> |
| 5184 | |
| 5185 | <p> |
| 5186 | The argument to this intrinsic indicates which function to return the frame |
| 5187 | pointer for. Zero indicates the calling function, one indicates its caller, |
| 5188 | etc. The argument is <b>required</b> to be a constant integer value. |
| 5189 | </p> |
| 5190 | |
| 5191 | <h5>Semantics:</h5> |
| 5192 | |
| 5193 | <p> |
| 5194 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating |
| 5195 | the frame address of the specified call frame, or zero if it cannot be |
| 5196 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 5197 | for arguments other than zero, so it should only be used for debugging purposes. |
| 5198 | </p> |
| 5199 | |
| 5200 | <p> |
| 5201 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 5202 | 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] | 5203 | source-language caller. |
| 5204 | </p> |
| 5205 | </div> |
| 5206 | |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 5207 | <!-- _______________________________________________________________________ --> |
| 5208 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5209 | <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5210 | </div> |
| 5211 | |
| 5212 | <div class="doc_text"> |
| 5213 | |
| 5214 | <h5>Syntax:</h5> |
| 5215 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5216 | declare i8 *@llvm.stacksave() |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5217 | </pre> |
| 5218 | |
| 5219 | <h5>Overview:</h5> |
| 5220 | |
| 5221 | <p> |
| 5222 | 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] | 5223 | the function stack, for use with <a href="#int_stackrestore"> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5224 | <tt>llvm.stackrestore</tt></a>. This is useful for implementing language |
| 5225 | features like scoped automatic variable sized arrays in C99. |
| 5226 | </p> |
| 5227 | |
| 5228 | <h5>Semantics:</h5> |
| 5229 | |
| 5230 | <p> |
| 5231 | 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] | 5232 | href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5233 | <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from |
| 5234 | <tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the |
| 5235 | state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In |
| 5236 | practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack |
| 5237 | that were allocated after the <tt>llvm.stacksave</tt> was executed. |
| 5238 | </p> |
| 5239 | |
| 5240 | </div> |
| 5241 | |
| 5242 | <!-- _______________________________________________________________________ --> |
| 5243 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5244 | <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5245 | </div> |
| 5246 | |
| 5247 | <div class="doc_text"> |
| 5248 | |
| 5249 | <h5>Syntax:</h5> |
| 5250 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5251 | declare void @llvm.stackrestore(i8 * %ptr) |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5252 | </pre> |
| 5253 | |
| 5254 | <h5>Overview:</h5> |
| 5255 | |
| 5256 | <p> |
| 5257 | The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of |
| 5258 | 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] | 5259 | href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 5260 | useful for implementing language features like scoped automatic variable sized |
| 5261 | arrays in C99. |
| 5262 | </p> |
| 5263 | |
| 5264 | <h5>Semantics:</h5> |
| 5265 | |
| 5266 | <p> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5267 | 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] | 5268 | </p> |
| 5269 | |
| 5270 | </div> |
| 5271 | |
| 5272 | |
| 5273 | <!-- _______________________________________________________________________ --> |
| 5274 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5275 | <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a> |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 5276 | </div> |
| 5277 | |
| 5278 | <div class="doc_text"> |
| 5279 | |
| 5280 | <h5>Syntax:</h5> |
| 5281 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5282 | declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>) |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 5283 | </pre> |
| 5284 | |
| 5285 | <h5>Overview:</h5> |
| 5286 | |
| 5287 | |
| 5288 | <p> |
| 5289 | 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] | 5290 | a prefetch instruction if supported; otherwise, it is a noop. Prefetches have |
| 5291 | no |
| 5292 | effect on the behavior of the program but can change its performance |
Chris Lattner | 2a61536 | 2005-02-28 19:47:14 +0000 | [diff] [blame] | 5293 | characteristics. |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 5294 | </p> |
| 5295 | |
| 5296 | <h5>Arguments:</h5> |
| 5297 | |
| 5298 | <p> |
| 5299 | <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier |
| 5300 | determining if the fetch should be for a read (0) or write (1), and |
| 5301 | <tt>locality</tt> is a temporal locality specifier ranging from (0) - no |
Chris Lattner | aeffb4a | 2005-03-07 20:31:38 +0000 | [diff] [blame] | 5302 | 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] | 5303 | <tt>locality</tt> arguments must be constant integers. |
| 5304 | </p> |
| 5305 | |
| 5306 | <h5>Semantics:</h5> |
| 5307 | |
| 5308 | <p> |
| 5309 | This intrinsic does not modify the behavior of the program. In particular, |
| 5310 | prefetches cannot trap and do not produce a value. On targets that support this |
| 5311 | intrinsic, the prefetch can provide hints to the processor cache for better |
| 5312 | performance. |
| 5313 | </p> |
| 5314 | |
| 5315 | </div> |
| 5316 | |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 5317 | <!-- _______________________________________________________________________ --> |
| 5318 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5319 | <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a> |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 5320 | </div> |
| 5321 | |
| 5322 | <div class="doc_text"> |
| 5323 | |
| 5324 | <h5>Syntax:</h5> |
| 5325 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 5326 | declare void @llvm.pcmarker(i32 <id>) |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 5327 | </pre> |
| 5328 | |
| 5329 | <h5>Overview:</h5> |
| 5330 | |
| 5331 | |
| 5332 | <p> |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 5333 | The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 5334 | (PC) in a region of |
| 5335 | code to simulators and other tools. The method is target specific, but it is |
| 5336 | expected that the marker will use exported symbols to transmit the PC of the |
| 5337 | marker. |
| 5338 | The marker makes no guarantees that it will remain with any specific instruction |
| 5339 | 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] | 5340 | optimizations. The intended use is to be inserted after optimizations to allow |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 5341 | correlations of simulation runs. |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 5342 | </p> |
| 5343 | |
| 5344 | <h5>Arguments:</h5> |
| 5345 | |
| 5346 | <p> |
| 5347 | <tt>id</tt> is a numerical id identifying the marker. |
| 5348 | </p> |
| 5349 | |
| 5350 | <h5>Semantics:</h5> |
| 5351 | |
| 5352 | <p> |
| 5353 | This intrinsic does not modify the behavior of the program. Backends that do not |
| 5354 | support this intrinisic may ignore it. |
| 5355 | </p> |
| 5356 | |
| 5357 | </div> |
| 5358 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 5359 | <!-- _______________________________________________________________________ --> |
| 5360 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5361 | <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a> |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 5362 | </div> |
| 5363 | |
| 5364 | <div class="doc_text"> |
| 5365 | |
| 5366 | <h5>Syntax:</h5> |
| 5367 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5368 | declare i64 @llvm.readcyclecounter( ) |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 5369 | </pre> |
| 5370 | |
| 5371 | <h5>Overview:</h5> |
| 5372 | |
| 5373 | |
| 5374 | <p> |
| 5375 | The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle |
| 5376 | counter register (or similar low latency, high accuracy clocks) on those targets |
| 5377 | that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC. |
| 5378 | As the backing counters overflow quickly (on the order of 9 seconds on alpha), this |
| 5379 | should only be used for small timings. |
| 5380 | </p> |
| 5381 | |
| 5382 | <h5>Semantics:</h5> |
| 5383 | |
| 5384 | <p> |
| 5385 | When directly supported, reading the cycle counter should not modify any memory. |
| 5386 | Implementations are allowed to either return a application specific value or a |
| 5387 | system wide value. On backends without support, this is lowered to a constant 0. |
| 5388 | </p> |
| 5389 | |
| 5390 | </div> |
| 5391 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5392 | <!-- ======================================================================= --> |
| 5393 | <div class="doc_subsection"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5394 | <a name="int_libc">Standard C Library Intrinsics</a> |
| 5395 | </div> |
| 5396 | |
| 5397 | <div class="doc_text"> |
| 5398 | <p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5399 | LLVM provides intrinsics for a few important standard C library functions. |
| 5400 | These intrinsics allow source-language front-ends to pass information about the |
| 5401 | alignment of the pointer arguments to the code generator, providing opportunity |
| 5402 | for more efficient code generation. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5403 | </p> |
| 5404 | |
| 5405 | </div> |
| 5406 | |
| 5407 | <!-- _______________________________________________________________________ --> |
| 5408 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5409 | <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5410 | </div> |
| 5411 | |
| 5412 | <div class="doc_text"> |
| 5413 | |
| 5414 | <h5>Syntax:</h5> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5415 | <p>This is an overloaded intrinsic. You can use llvm.memcpy on any integer bit |
| 5416 | width. Not all targets support all bit widths however.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5417 | <pre> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5418 | declare void @llvm.memcpy.i8(i8 * <dest>, i8 * <src>, |
| 5419 | i8 <len>, i32 <align>) |
| 5420 | declare void @llvm.memcpy.i16(i8 * <dest>, i8 * <src>, |
| 5421 | i16 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5422 | declare void @llvm.memcpy.i32(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5423 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5424 | declare void @llvm.memcpy.i64(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5425 | i64 <len>, i32 <align>) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5426 | </pre> |
| 5427 | |
| 5428 | <h5>Overview:</h5> |
| 5429 | |
| 5430 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5431 | 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] | 5432 | location to the destination location. |
| 5433 | </p> |
| 5434 | |
| 5435 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5436 | Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt> |
| 5437 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5438 | </p> |
| 5439 | |
| 5440 | <h5>Arguments:</h5> |
| 5441 | |
| 5442 | <p> |
| 5443 | 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] | 5444 | the source. The third argument is an integer argument |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5445 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 5446 | of the source and destination locations. |
| 5447 | </p> |
| 5448 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5449 | <p> |
| 5450 | 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] | 5451 | the caller guarantees that both the source and destination pointers are aligned |
| 5452 | to that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5453 | </p> |
| 5454 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 5455 | <h5>Semantics:</h5> |
| 5456 | |
| 5457 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5458 | 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] | 5459 | location to the destination location, which are not allowed to overlap. It |
| 5460 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 5461 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 5462 | be set to 0 or 1. |
| 5463 | </p> |
| 5464 | </div> |
| 5465 | |
| 5466 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5467 | <!-- _______________________________________________________________________ --> |
| 5468 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5469 | <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5470 | </div> |
| 5471 | |
| 5472 | <div class="doc_text"> |
| 5473 | |
| 5474 | <h5>Syntax:</h5> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5475 | <p>This is an overloaded intrinsic. You can use llvm.memmove on any integer bit |
| 5476 | width. Not all targets support all bit widths however.</p> |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5477 | <pre> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5478 | declare void @llvm.memmove.i8(i8 * <dest>, i8 * <src>, |
| 5479 | i8 <len>, i32 <align>) |
| 5480 | declare void @llvm.memmove.i16(i8 * <dest>, i8 * <src>, |
| 5481 | i16 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5482 | declare void @llvm.memmove.i32(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5483 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5484 | declare void @llvm.memmove.i64(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5485 | i64 <len>, i32 <align>) |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5486 | </pre> |
| 5487 | |
| 5488 | <h5>Overview:</h5> |
| 5489 | |
| 5490 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5491 | The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source |
| 5492 | location to the destination location. It is similar to the |
Chris Lattner | 4b2cbcf | 2008-01-06 19:51:52 +0000 | [diff] [blame] | 5493 | '<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] | 5494 | </p> |
| 5495 | |
| 5496 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5497 | Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt> |
| 5498 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5499 | </p> |
| 5500 | |
| 5501 | <h5>Arguments:</h5> |
| 5502 | |
| 5503 | <p> |
| 5504 | 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] | 5505 | the source. The third argument is an integer argument |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5506 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 5507 | of the source and destination locations. |
| 5508 | </p> |
| 5509 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5510 | <p> |
| 5511 | 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] | 5512 | the caller guarantees that the source and destination pointers are aligned to |
| 5513 | that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 5514 | </p> |
| 5515 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 5516 | <h5>Semantics:</h5> |
| 5517 | |
| 5518 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5519 | 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] | 5520 | location to the destination location, which may overlap. It |
| 5521 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 5522 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 5523 | be set to 0 or 1. |
| 5524 | </p> |
| 5525 | </div> |
| 5526 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 5527 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5528 | <!-- _______________________________________________________________________ --> |
| 5529 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5530 | <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5531 | </div> |
| 5532 | |
| 5533 | <div class="doc_text"> |
| 5534 | |
| 5535 | <h5>Syntax:</h5> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5536 | <p>This is an overloaded intrinsic. You can use llvm.memset on any integer bit |
| 5537 | width. Not all targets support all bit widths however.</p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5538 | <pre> |
Chris Lattner | 824b958 | 2008-11-21 16:42:48 +0000 | [diff] [blame] | 5539 | declare void @llvm.memset.i8(i8 * <dest>, i8 <val>, |
| 5540 | i8 <len>, i32 <align>) |
| 5541 | declare void @llvm.memset.i16(i8 * <dest>, i8 <val>, |
| 5542 | i16 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5543 | declare void @llvm.memset.i32(i8 * <dest>, i8 <val>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5544 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5545 | declare void @llvm.memset.i64(i8 * <dest>, i8 <val>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 5546 | i64 <len>, i32 <align>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5547 | </pre> |
| 5548 | |
| 5549 | <h5>Overview:</h5> |
| 5550 | |
| 5551 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5552 | 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] | 5553 | byte value. |
| 5554 | </p> |
| 5555 | |
| 5556 | <p> |
| 5557 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic |
| 5558 | does not return a value, and takes an extra alignment argument. |
| 5559 | </p> |
| 5560 | |
| 5561 | <h5>Arguments:</h5> |
| 5562 | |
| 5563 | <p> |
| 5564 | 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] | 5565 | byte value to fill it with, the third argument is an integer |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5566 | argument specifying the number of bytes to fill, and the fourth argument is the |
| 5567 | known alignment of destination location. |
| 5568 | </p> |
| 5569 | |
| 5570 | <p> |
| 5571 | 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] | 5572 | the caller guarantees that the destination pointer is aligned to that boundary. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5573 | </p> |
| 5574 | |
| 5575 | <h5>Semantics:</h5> |
| 5576 | |
| 5577 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 5578 | The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at |
| 5579 | the |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 5580 | destination location. If the argument is known to be aligned to some boundary, |
| 5581 | this can be specified as the fourth argument, otherwise it should be set to 0 or |
| 5582 | 1. |
| 5583 | </p> |
| 5584 | </div> |
| 5585 | |
| 5586 | |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 5587 | <!-- _______________________________________________________________________ --> |
| 5588 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5589 | <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a> |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5590 | </div> |
| 5591 | |
| 5592 | <div class="doc_text"> |
| 5593 | |
| 5594 | <h5>Syntax:</h5> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5595 | <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] | 5596 | floating point or vector of floating point type. Not all targets support all |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5597 | types however.</p> |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5598 | <pre> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5599 | declare float @llvm.sqrt.f32(float %Val) |
| 5600 | declare double @llvm.sqrt.f64(double %Val) |
| 5601 | declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) |
| 5602 | declare fp128 @llvm.sqrt.f128(fp128 %Val) |
| 5603 | declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5604 | </pre> |
| 5605 | |
| 5606 | <h5>Overview:</h5> |
| 5607 | |
| 5608 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5609 | 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] | 5610 | 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] | 5611 | <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] | 5612 | negative numbers other than -0.0 (which allows for better optimization, because |
| 5613 | there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is |
| 5614 | defined to return -0.0 like IEEE sqrt. |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 5615 | </p> |
| 5616 | |
| 5617 | <h5>Arguments:</h5> |
| 5618 | |
| 5619 | <p> |
| 5620 | The argument and return value are floating point numbers of the same type. |
| 5621 | </p> |
| 5622 | |
| 5623 | <h5>Semantics:</h5> |
| 5624 | |
| 5625 | <p> |
Dan Gohman | d6257fe | 2007-07-16 14:37:41 +0000 | [diff] [blame] | 5626 | 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] | 5627 | floating point number. |
| 5628 | </p> |
| 5629 | </div> |
| 5630 | |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5631 | <!-- _______________________________________________________________________ --> |
| 5632 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5633 | <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a> |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5634 | </div> |
| 5635 | |
| 5636 | <div class="doc_text"> |
| 5637 | |
| 5638 | <h5>Syntax:</h5> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5639 | <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] | 5640 | floating point or vector of floating point type. Not all targets support all |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5641 | types however.</p> |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5642 | <pre> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 5643 | declare float @llvm.powi.f32(float %Val, i32 %power) |
| 5644 | declare double @llvm.powi.f64(double %Val, i32 %power) |
| 5645 | declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power) |
| 5646 | declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power) |
| 5647 | declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power) |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5648 | </pre> |
| 5649 | |
| 5650 | <h5>Overview:</h5> |
| 5651 | |
| 5652 | <p> |
| 5653 | The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the |
| 5654 | specified (positive or negative) power. The order of evaluation of |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5655 | multiplications is not defined. When a vector of floating point type is |
| 5656 | used, the second argument remains a scalar integer value. |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5657 | </p> |
| 5658 | |
| 5659 | <h5>Arguments:</h5> |
| 5660 | |
| 5661 | <p> |
| 5662 | The second argument is an integer power, and the first is a value to raise to |
| 5663 | that power. |
| 5664 | </p> |
| 5665 | |
| 5666 | <h5>Semantics:</h5> |
| 5667 | |
| 5668 | <p> |
| 5669 | This function returns the first value raised to the second power with an |
| 5670 | unspecified sequence of rounding operations.</p> |
| 5671 | </div> |
| 5672 | |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5673 | <!-- _______________________________________________________________________ --> |
| 5674 | <div class="doc_subsubsection"> |
| 5675 | <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a> |
| 5676 | </div> |
| 5677 | |
| 5678 | <div class="doc_text"> |
| 5679 | |
| 5680 | <h5>Syntax:</h5> |
| 5681 | <p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any |
| 5682 | floating point or vector of floating point type. Not all targets support all |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5683 | types however.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5684 | <pre> |
| 5685 | declare float @llvm.sin.f32(float %Val) |
| 5686 | declare double @llvm.sin.f64(double %Val) |
| 5687 | declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) |
| 5688 | declare fp128 @llvm.sin.f128(fp128 %Val) |
| 5689 | declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) |
| 5690 | </pre> |
| 5691 | |
| 5692 | <h5>Overview:</h5> |
| 5693 | |
| 5694 | <p> |
| 5695 | The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand. |
| 5696 | </p> |
| 5697 | |
| 5698 | <h5>Arguments:</h5> |
| 5699 | |
| 5700 | <p> |
| 5701 | The argument and return value are floating point numbers of the same type. |
| 5702 | </p> |
| 5703 | |
| 5704 | <h5>Semantics:</h5> |
| 5705 | |
| 5706 | <p> |
| 5707 | This function returns the sine of the specified operand, returning the |
| 5708 | 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] | 5709 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5710 | </div> |
| 5711 | |
| 5712 | <!-- _______________________________________________________________________ --> |
| 5713 | <div class="doc_subsubsection"> |
| 5714 | <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a> |
| 5715 | </div> |
| 5716 | |
| 5717 | <div class="doc_text"> |
| 5718 | |
| 5719 | <h5>Syntax:</h5> |
| 5720 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any |
| 5721 | floating point or vector of floating point type. Not all targets support all |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5722 | types however.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5723 | <pre> |
| 5724 | declare float @llvm.cos.f32(float %Val) |
| 5725 | declare double @llvm.cos.f64(double %Val) |
| 5726 | declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) |
| 5727 | declare fp128 @llvm.cos.f128(fp128 %Val) |
| 5728 | declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) |
| 5729 | </pre> |
| 5730 | |
| 5731 | <h5>Overview:</h5> |
| 5732 | |
| 5733 | <p> |
| 5734 | The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand. |
| 5735 | </p> |
| 5736 | |
| 5737 | <h5>Arguments:</h5> |
| 5738 | |
| 5739 | <p> |
| 5740 | The argument and return value are floating point numbers of the same type. |
| 5741 | </p> |
| 5742 | |
| 5743 | <h5>Semantics:</h5> |
| 5744 | |
| 5745 | <p> |
| 5746 | This function returns the cosine of the specified operand, returning the |
| 5747 | 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] | 5748 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5749 | </div> |
| 5750 | |
| 5751 | <!-- _______________________________________________________________________ --> |
| 5752 | <div class="doc_subsubsection"> |
| 5753 | <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a> |
| 5754 | </div> |
| 5755 | |
| 5756 | <div class="doc_text"> |
| 5757 | |
| 5758 | <h5>Syntax:</h5> |
| 5759 | <p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any |
| 5760 | floating point or vector of floating point type. Not all targets support all |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5761 | types however.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5762 | <pre> |
| 5763 | declare float @llvm.pow.f32(float %Val, float %Power) |
| 5764 | declare double @llvm.pow.f64(double %Val, double %Power) |
| 5765 | declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) |
| 5766 | declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) |
| 5767 | declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) |
| 5768 | </pre> |
| 5769 | |
| 5770 | <h5>Overview:</h5> |
| 5771 | |
| 5772 | <p> |
| 5773 | The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the |
| 5774 | specified (positive or negative) power. |
| 5775 | </p> |
| 5776 | |
| 5777 | <h5>Arguments:</h5> |
| 5778 | |
| 5779 | <p> |
| 5780 | The second argument is a floating point power, and the first is a value to |
| 5781 | raise to that power. |
| 5782 | </p> |
| 5783 | |
| 5784 | <h5>Semantics:</h5> |
| 5785 | |
| 5786 | <p> |
| 5787 | This function returns the first value raised to the second power, |
| 5788 | returning the |
| 5789 | 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] | 5790 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5791 | </div> |
| 5792 | |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5793 | |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5794 | <!-- ======================================================================= --> |
| 5795 | <div class="doc_subsection"> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5796 | <a name="int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5797 | </div> |
| 5798 | |
| 5799 | <div class="doc_text"> |
| 5800 | <p> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5801 | LLVM provides intrinsics for a few important bit manipulation operations. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5802 | These allow efficient code generation for some algorithms. |
| 5803 | </p> |
| 5804 | |
| 5805 | </div> |
| 5806 | |
| 5807 | <!-- _______________________________________________________________________ --> |
| 5808 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5809 | <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5810 | </div> |
| 5811 | |
| 5812 | <div class="doc_text"> |
| 5813 | |
| 5814 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5815 | <p>This is an overloaded intrinsic function. You can use bswap on any integer |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5816 | type that is an even number of bytes (i.e. BitWidth % 16 == 0).</p> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5817 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5818 | declare i16 @llvm.bswap.i16(i16 <id>) |
| 5819 | declare i32 @llvm.bswap.i32(i32 <id>) |
| 5820 | declare i64 @llvm.bswap.i64(i64 <id>) |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5821 | </pre> |
| 5822 | |
| 5823 | <h5>Overview:</h5> |
| 5824 | |
| 5825 | <p> |
Reid Spencer | 338ea09 | 2007-04-02 02:25:19 +0000 | [diff] [blame] | 5826 | 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] | 5827 | values with an even number of bytes (positive multiple of 16 bits). These are |
| 5828 | useful for performing operations on data that is not in the target's native |
| 5829 | byte order. |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5830 | </p> |
| 5831 | |
| 5832 | <h5>Semantics:</h5> |
| 5833 | |
| 5834 | <p> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5835 | 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] | 5836 | and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt> |
| 5837 | intrinsic returns an i32 value that has the four bytes of the input i32 |
| 5838 | 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] | 5839 | i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>, |
| 5840 | <tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5841 | additional even-byte lengths (6 bytes, 8 bytes and more, respectively). |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5842 | </p> |
| 5843 | |
| 5844 | </div> |
| 5845 | |
| 5846 | <!-- _______________________________________________________________________ --> |
| 5847 | <div class="doc_subsubsection"> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5848 | <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5849 | </div> |
| 5850 | |
| 5851 | <div class="doc_text"> |
| 5852 | |
| 5853 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5854 | <p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5855 | width. Not all targets support all bit widths however.</p> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5856 | <pre> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 5857 | declare i8 @llvm.ctpop.i8(i8 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5858 | declare i16 @llvm.ctpop.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5859 | declare i32 @llvm.ctpop.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5860 | declare i64 @llvm.ctpop.i64(i64 <src>) |
| 5861 | declare i256 @llvm.ctpop.i256(i256 <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5862 | </pre> |
| 5863 | |
| 5864 | <h5>Overview:</h5> |
| 5865 | |
| 5866 | <p> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 5867 | The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a |
| 5868 | value. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5869 | </p> |
| 5870 | |
| 5871 | <h5>Arguments:</h5> |
| 5872 | |
| 5873 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5874 | 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] | 5875 | integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5876 | </p> |
| 5877 | |
| 5878 | <h5>Semantics:</h5> |
| 5879 | |
| 5880 | <p> |
| 5881 | The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable. |
| 5882 | </p> |
| 5883 | </div> |
| 5884 | |
| 5885 | <!-- _______________________________________________________________________ --> |
| 5886 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5887 | <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5888 | </div> |
| 5889 | |
| 5890 | <div class="doc_text"> |
| 5891 | |
| 5892 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5893 | <p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5894 | integer bit width. Not all targets support all bit widths however.</p> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5895 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5896 | declare i8 @llvm.ctlz.i8 (i8 <src>) |
| 5897 | declare i16 @llvm.ctlz.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5898 | declare i32 @llvm.ctlz.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5899 | declare i64 @llvm.ctlz.i64(i64 <src>) |
| 5900 | declare i256 @llvm.ctlz.i256(i256 <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5901 | </pre> |
| 5902 | |
| 5903 | <h5>Overview:</h5> |
| 5904 | |
| 5905 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5906 | The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of |
| 5907 | leading zeros in a variable. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5908 | </p> |
| 5909 | |
| 5910 | <h5>Arguments:</h5> |
| 5911 | |
| 5912 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5913 | 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] | 5914 | integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5915 | </p> |
| 5916 | |
| 5917 | <h5>Semantics:</h5> |
| 5918 | |
| 5919 | <p> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5920 | The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros |
| 5921 | 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] | 5922 | of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5923 | </p> |
| 5924 | </div> |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 5925 | |
| 5926 | |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5927 | |
| 5928 | <!-- _______________________________________________________________________ --> |
| 5929 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5930 | <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5931 | </div> |
| 5932 | |
| 5933 | <div class="doc_text"> |
| 5934 | |
| 5935 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5936 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 5937 | integer bit width. Not all targets support all bit widths however.</p> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5938 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5939 | declare i8 @llvm.cttz.i8 (i8 <src>) |
| 5940 | declare i16 @llvm.cttz.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5941 | declare i32 @llvm.cttz.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5942 | declare i64 @llvm.cttz.i64(i64 <src>) |
| 5943 | declare i256 @llvm.cttz.i256(i256 <src>) |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5944 | </pre> |
| 5945 | |
| 5946 | <h5>Overview:</h5> |
| 5947 | |
| 5948 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5949 | The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of |
| 5950 | trailing zeros. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5951 | </p> |
| 5952 | |
| 5953 | <h5>Arguments:</h5> |
| 5954 | |
| 5955 | <p> |
| 5956 | 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] | 5957 | integer type. The return type must match the argument type. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5958 | </p> |
| 5959 | |
| 5960 | <h5>Semantics:</h5> |
| 5961 | |
| 5962 | <p> |
| 5963 | The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros |
| 5964 | in a variable. If the src == 0 then the result is the size in bits of the type |
| 5965 | of src. For example, <tt>llvm.cttz(2) = 1</tt>. |
| 5966 | </p> |
| 5967 | </div> |
| 5968 | |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 5969 | |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 5970 | <!-- ======================================================================= --> |
| 5971 | <div class="doc_subsection"> |
| 5972 | <a name="int_overflow">Arithmetic with Overflow Intrinsics</a> |
| 5973 | </div> |
| 5974 | |
| 5975 | <div class="doc_text"> |
| 5976 | <p> |
| 5977 | LLVM provides intrinsics for some arithmetic with overflow operations. |
| 5978 | </p> |
| 5979 | |
| 5980 | </div> |
| 5981 | |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 5982 | <!-- _______________________________________________________________________ --> |
| 5983 | <div class="doc_subsubsection"> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 5984 | <a name="int_sadd_overflow">'<tt>llvm.sadd.with.overflow.*</tt>' Intrinsics</a> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 5985 | </div> |
| 5986 | |
| 5987 | <div class="doc_text"> |
| 5988 | |
| 5989 | <h5>Syntax:</h5> |
| 5990 | |
| 5991 | <p>This is an overloaded intrinsic. You can use <tt>llvm.sadd.with.overflow</tt> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 5992 | on any integer bit width.</p> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 5993 | |
| 5994 | <pre> |
| 5995 | declare {i16, i1} @llvm.sadd.with.overflow.i16(i16 %a, i16 %b) |
| 5996 | declare {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) |
| 5997 | declare {i64, i1} @llvm.sadd.with.overflow.i64(i64 %a, i64 %b) |
| 5998 | </pre> |
| 5999 | |
| 6000 | <h5>Overview:</h5> |
| 6001 | |
| 6002 | <p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform |
| 6003 | a signed addition of the two arguments, and indicate whether an overflow |
| 6004 | occurred during the signed summation.</p> |
| 6005 | |
| 6006 | <h5>Arguments:</h5> |
| 6007 | |
| 6008 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6009 | be of integer types of any bit width, but they must have the same bit width. The |
| 6010 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6011 | and <tt>%b</tt> are the two values that will undergo signed addition.</p> |
| 6012 | |
| 6013 | <h5>Semantics:</h5> |
| 6014 | |
| 6015 | <p>The '<tt>llvm.sadd.with.overflow</tt>' family of intrinsic functions perform |
| 6016 | a signed addition of the two variables. They return a structure — the |
| 6017 | first element of which is the signed summation, and the second element of which |
| 6018 | is a bit specifying if the signed summation resulted in an overflow.</p> |
| 6019 | |
| 6020 | <h5>Examples:</h5> |
| 6021 | <pre> |
| 6022 | %res = call {i32, i1} @llvm.sadd.with.overflow.i32(i32 %a, i32 %b) |
| 6023 | %sum = extractvalue {i32, i1} %res, 0 |
| 6024 | %obit = extractvalue {i32, i1} %res, 1 |
| 6025 | br i1 %obit, label %overflow, label %normal |
| 6026 | </pre> |
| 6027 | |
| 6028 | </div> |
| 6029 | |
| 6030 | <!-- _______________________________________________________________________ --> |
| 6031 | <div class="doc_subsubsection"> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6032 | <a name="int_uadd_overflow">'<tt>llvm.uadd.with.overflow.*</tt>' Intrinsics</a> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6033 | </div> |
| 6034 | |
| 6035 | <div class="doc_text"> |
| 6036 | |
| 6037 | <h5>Syntax:</h5> |
| 6038 | |
| 6039 | <p>This is an overloaded intrinsic. You can use <tt>llvm.uadd.with.overflow</tt> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6040 | on any integer bit width.</p> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6041 | |
| 6042 | <pre> |
| 6043 | declare {i16, i1} @llvm.uadd.with.overflow.i16(i16 %a, i16 %b) |
| 6044 | declare {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) |
| 6045 | declare {i64, i1} @llvm.uadd.with.overflow.i64(i64 %a, i64 %b) |
| 6046 | </pre> |
| 6047 | |
| 6048 | <h5>Overview:</h5> |
| 6049 | |
| 6050 | <p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform |
| 6051 | an unsigned addition of the two arguments, and indicate whether a carry occurred |
| 6052 | during the unsigned summation.</p> |
| 6053 | |
| 6054 | <h5>Arguments:</h5> |
| 6055 | |
| 6056 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6057 | be of integer types of any bit width, but they must have the same bit width. The |
| 6058 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6059 | and <tt>%b</tt> are the two values that will undergo unsigned addition.</p> |
| 6060 | |
| 6061 | <h5>Semantics:</h5> |
| 6062 | |
| 6063 | <p>The '<tt>llvm.uadd.with.overflow</tt>' family of intrinsic functions perform |
| 6064 | an unsigned addition of the two arguments. They return a structure — the |
| 6065 | first element of which is the sum, and the second element of which is a bit |
| 6066 | specifying if the unsigned summation resulted in a carry.</p> |
| 6067 | |
| 6068 | <h5>Examples:</h5> |
| 6069 | <pre> |
| 6070 | %res = call {i32, i1} @llvm.uadd.with.overflow.i32(i32 %a, i32 %b) |
| 6071 | %sum = extractvalue {i32, i1} %res, 0 |
| 6072 | %obit = extractvalue {i32, i1} %res, 1 |
| 6073 | br i1 %obit, label %carry, label %normal |
| 6074 | </pre> |
| 6075 | |
| 6076 | </div> |
| 6077 | |
| 6078 | <!-- _______________________________________________________________________ --> |
| 6079 | <div class="doc_subsubsection"> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6080 | <a name="int_ssub_overflow">'<tt>llvm.ssub.with.overflow.*</tt>' Intrinsics</a> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6081 | </div> |
| 6082 | |
| 6083 | <div class="doc_text"> |
| 6084 | |
| 6085 | <h5>Syntax:</h5> |
| 6086 | |
| 6087 | <p>This is an overloaded intrinsic. You can use <tt>llvm.ssub.with.overflow</tt> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6088 | on any integer bit width.</p> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6089 | |
| 6090 | <pre> |
| 6091 | declare {i16, i1} @llvm.ssub.with.overflow.i16(i16 %a, i16 %b) |
| 6092 | declare {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) |
| 6093 | declare {i64, i1} @llvm.ssub.with.overflow.i64(i64 %a, i64 %b) |
| 6094 | </pre> |
| 6095 | |
| 6096 | <h5>Overview:</h5> |
| 6097 | |
| 6098 | <p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform |
| 6099 | a signed subtraction of the two arguments, and indicate whether an overflow |
| 6100 | occurred during the signed subtraction.</p> |
| 6101 | |
| 6102 | <h5>Arguments:</h5> |
| 6103 | |
| 6104 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6105 | be of integer types of any bit width, but they must have the same bit width. The |
| 6106 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6107 | and <tt>%b</tt> are the two values that will undergo signed subtraction.</p> |
| 6108 | |
| 6109 | <h5>Semantics:</h5> |
| 6110 | |
| 6111 | <p>The '<tt>llvm.ssub.with.overflow</tt>' family of intrinsic functions perform |
| 6112 | a signed subtraction of the two arguments. They return a structure — the |
| 6113 | first element of which is the subtraction, and the second element of which is a bit |
| 6114 | specifying if the signed subtraction resulted in an overflow.</p> |
| 6115 | |
| 6116 | <h5>Examples:</h5> |
| 6117 | <pre> |
| 6118 | %res = call {i32, i1} @llvm.ssub.with.overflow.i32(i32 %a, i32 %b) |
| 6119 | %sum = extractvalue {i32, i1} %res, 0 |
| 6120 | %obit = extractvalue {i32, i1} %res, 1 |
| 6121 | br i1 %obit, label %overflow, label %normal |
| 6122 | </pre> |
| 6123 | |
| 6124 | </div> |
| 6125 | |
| 6126 | <!-- _______________________________________________________________________ --> |
| 6127 | <div class="doc_subsubsection"> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6128 | <a name="int_usub_overflow">'<tt>llvm.usub.with.overflow.*</tt>' Intrinsics</a> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6129 | </div> |
| 6130 | |
| 6131 | <div class="doc_text"> |
| 6132 | |
| 6133 | <h5>Syntax:</h5> |
| 6134 | |
| 6135 | <p>This is an overloaded intrinsic. You can use <tt>llvm.usub.with.overflow</tt> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6136 | on any integer bit width.</p> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6137 | |
| 6138 | <pre> |
| 6139 | declare {i16, i1} @llvm.usub.with.overflow.i16(i16 %a, i16 %b) |
| 6140 | declare {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) |
| 6141 | declare {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b) |
| 6142 | </pre> |
| 6143 | |
| 6144 | <h5>Overview:</h5> |
| 6145 | |
| 6146 | <p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform |
| 6147 | an unsigned subtraction of the two arguments, and indicate whether an overflow |
| 6148 | occurred during the unsigned subtraction.</p> |
| 6149 | |
| 6150 | <h5>Arguments:</h5> |
| 6151 | |
| 6152 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6153 | be of integer types of any bit width, but they must have the same bit width. The |
| 6154 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6155 | and <tt>%b</tt> are the two values that will undergo unsigned subtraction.</p> |
| 6156 | |
| 6157 | <h5>Semantics:</h5> |
| 6158 | |
| 6159 | <p>The '<tt>llvm.usub.with.overflow</tt>' family of intrinsic functions perform |
| 6160 | an unsigned subtraction of the two arguments. They return a structure — the |
| 6161 | first element of which is the subtraction, and the second element of which is a bit |
| 6162 | specifying if the unsigned subtraction resulted in an overflow.</p> |
| 6163 | |
| 6164 | <h5>Examples:</h5> |
| 6165 | <pre> |
| 6166 | %res = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b) |
| 6167 | %sum = extractvalue {i32, i1} %res, 0 |
| 6168 | %obit = extractvalue {i32, i1} %res, 1 |
| 6169 | br i1 %obit, label %overflow, label %normal |
| 6170 | </pre> |
| 6171 | |
| 6172 | </div> |
| 6173 | |
| 6174 | <!-- _______________________________________________________________________ --> |
| 6175 | <div class="doc_subsubsection"> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6176 | <a name="int_smul_overflow">'<tt>llvm.smul.with.overflow.*</tt>' Intrinsics</a> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6177 | </div> |
| 6178 | |
| 6179 | <div class="doc_text"> |
| 6180 | |
| 6181 | <h5>Syntax:</h5> |
| 6182 | |
| 6183 | <p>This is an overloaded intrinsic. You can use <tt>llvm.smul.with.overflow</tt> |
Bill Wendling | da01af7 | 2009-02-08 04:04:40 +0000 | [diff] [blame] | 6184 | on any integer bit width.</p> |
Bill Wendling | ac1df8e | 2009-02-08 01:40:31 +0000 | [diff] [blame] | 6185 | |
| 6186 | <pre> |
| 6187 | declare {i16, i1} @llvm.smul.with.overflow.i16(i16 %a, i16 %b) |
| 6188 | declare {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) |
| 6189 | declare {i64, i1} @llvm.smul.with.overflow.i64(i64 %a, i64 %b) |
| 6190 | </pre> |
| 6191 | |
| 6192 | <h5>Overview:</h5> |
| 6193 | |
| 6194 | <p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform |
| 6195 | a signed multiplication of the two arguments, and indicate whether an overflow |
| 6196 | occurred during the signed multiplication.</p> |
| 6197 | |
| 6198 | <h5>Arguments:</h5> |
| 6199 | |
| 6200 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6201 | be of integer types of any bit width, but they must have the same bit width. The |
| 6202 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6203 | and <tt>%b</tt> are the two values that will undergo signed multiplication.</p> |
| 6204 | |
| 6205 | <h5>Semantics:</h5> |
| 6206 | |
| 6207 | <p>The '<tt>llvm.smul.with.overflow</tt>' family of intrinsic functions perform |
| 6208 | a signed multiplication of the two arguments. They return a structure — |
| 6209 | the first element of which is the multiplication, and the second element of |
| 6210 | which is a bit specifying if the signed multiplication resulted in an |
| 6211 | overflow.</p> |
| 6212 | |
| 6213 | <h5>Examples:</h5> |
| 6214 | <pre> |
| 6215 | %res = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a, i32 %b) |
| 6216 | %sum = extractvalue {i32, i1} %res, 0 |
| 6217 | %obit = extractvalue {i32, i1} %res, 1 |
| 6218 | br i1 %obit, label %overflow, label %normal |
| 6219 | </pre> |
| 6220 | |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 6221 | </div> |
| 6222 | |
Bill Wendling | 41b485c | 2009-02-08 23:00:09 +0000 | [diff] [blame] | 6223 | <!-- _______________________________________________________________________ --> |
| 6224 | <div class="doc_subsubsection"> |
| 6225 | <a name="int_umul_overflow">'<tt>llvm.umul.with.overflow.*</tt>' Intrinsics</a> |
| 6226 | </div> |
| 6227 | |
| 6228 | <div class="doc_text"> |
| 6229 | |
| 6230 | <h5>Syntax:</h5> |
| 6231 | |
| 6232 | <p>This is an overloaded intrinsic. You can use <tt>llvm.umul.with.overflow</tt> |
| 6233 | on any integer bit width.</p> |
| 6234 | |
| 6235 | <pre> |
| 6236 | declare {i16, i1} @llvm.umul.with.overflow.i16(i16 %a, i16 %b) |
| 6237 | declare {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) |
| 6238 | declare {i64, i1} @llvm.umul.with.overflow.i64(i64 %a, i64 %b) |
| 6239 | </pre> |
| 6240 | |
| 6241 | <h5>Overview:</h5> |
| 6242 | |
Bill Wendling | 41b485c | 2009-02-08 23:00:09 +0000 | [diff] [blame] | 6243 | <p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform |
| 6244 | a unsigned multiplication of the two arguments, and indicate whether an overflow |
| 6245 | occurred during the unsigned multiplication.</p> |
| 6246 | |
| 6247 | <h5>Arguments:</h5> |
| 6248 | |
| 6249 | <p>The arguments (%a and %b) and the first element of the result structure may |
| 6250 | be of integer types of any bit width, but they must have the same bit width. The |
| 6251 | second element of the result structure must be of type <tt>i1</tt>. <tt>%a</tt> |
| 6252 | and <tt>%b</tt> are the two values that will undergo unsigned |
| 6253 | multiplication.</p> |
| 6254 | |
| 6255 | <h5>Semantics:</h5> |
| 6256 | |
| 6257 | <p>The '<tt>llvm.umul.with.overflow</tt>' family of intrinsic functions perform |
| 6258 | an unsigned multiplication of the two arguments. They return a structure — |
| 6259 | the first element of which is the multiplication, and the second element of |
| 6260 | which is a bit specifying if the unsigned multiplication resulted in an |
| 6261 | overflow.</p> |
| 6262 | |
| 6263 | <h5>Examples:</h5> |
| 6264 | <pre> |
| 6265 | %res = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a, i32 %b) |
| 6266 | %sum = extractvalue {i32, i1} %res, 0 |
| 6267 | %obit = extractvalue {i32, i1} %res, 1 |
| 6268 | br i1 %obit, label %overflow, label %normal |
| 6269 | </pre> |
| 6270 | |
| 6271 | </div> |
| 6272 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 6273 | <!-- ======================================================================= --> |
| 6274 | <div class="doc_subsection"> |
| 6275 | <a name="int_debugger">Debugger Intrinsics</a> |
| 6276 | </div> |
| 6277 | |
| 6278 | <div class="doc_text"> |
| 6279 | <p> |
| 6280 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), |
| 6281 | are described in the <a |
| 6282 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level |
| 6283 | Debugging</a> document. |
| 6284 | </p> |
| 6285 | </div> |
| 6286 | |
| 6287 | |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 6288 | <!-- ======================================================================= --> |
| 6289 | <div class="doc_subsection"> |
| 6290 | <a name="int_eh">Exception Handling Intrinsics</a> |
| 6291 | </div> |
| 6292 | |
| 6293 | <div class="doc_text"> |
| 6294 | <p> The LLVM exception handling intrinsics (which all start with |
| 6295 | <tt>llvm.eh.</tt> prefix), are described in the <a |
| 6296 | href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception |
| 6297 | Handling</a> document. </p> |
| 6298 | </div> |
| 6299 | |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 6300 | <!-- ======================================================================= --> |
| 6301 | <div class="doc_subsection"> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6302 | <a name="int_trampoline">Trampoline Intrinsic</a> |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6303 | </div> |
| 6304 | |
| 6305 | <div class="doc_text"> |
| 6306 | <p> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6307 | This intrinsic makes it possible to excise one parameter, marked with |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6308 | the <tt>nest</tt> attribute, from a function. The result is a callable |
| 6309 | function pointer lacking the nest parameter - the caller does not need |
| 6310 | to provide a value for it. Instead, the value to use is stored in |
| 6311 | advance in a "trampoline", a block of memory usually allocated |
| 6312 | on the stack, which also contains code to splice the nest value into the |
| 6313 | argument list. This is used to implement the GCC nested function address |
| 6314 | extension. |
| 6315 | </p> |
| 6316 | <p> |
| 6317 | For example, if the function is |
| 6318 | <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] | 6319 | 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] | 6320 | <pre> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6321 | %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 |
| 6322 | %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0 |
| 6323 | %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval ) |
| 6324 | %fp = bitcast i8* %p to i32 (i32, i32)* |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6325 | </pre> |
Bill Wendling | 03295ca | 2007-09-22 09:23:55 +0000 | [diff] [blame] | 6326 | <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent |
| 6327 | 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] | 6328 | </div> |
| 6329 | |
| 6330 | <!-- _______________________________________________________________________ --> |
| 6331 | <div class="doc_subsubsection"> |
| 6332 | <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a> |
| 6333 | </div> |
| 6334 | <div class="doc_text"> |
| 6335 | <h5>Syntax:</h5> |
| 6336 | <pre> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6337 | declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6338 | </pre> |
| 6339 | <h5>Overview:</h5> |
| 6340 | <p> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6341 | This fills the memory pointed to by <tt>tramp</tt> with code |
| 6342 | and returns a function pointer suitable for executing it. |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6343 | </p> |
| 6344 | <h5>Arguments:</h5> |
| 6345 | <p> |
| 6346 | The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all |
| 6347 | pointers. The <tt>tramp</tt> argument must point to a sufficiently large |
| 6348 | 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] | 6349 | intrinsic. Note that the size and the alignment are target-specific - LLVM |
| 6350 | currently provides no portable way of determining them, so a front-end that |
| 6351 | generates this intrinsic needs to have some target-specific knowledge. |
| 6352 | 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] | 6353 | </p> |
| 6354 | <h5>Semantics:</h5> |
| 6355 | <p> |
| 6356 | 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] | 6357 | dependent code, turning it into a function. A pointer to this function is |
| 6358 | returned, but needs to be bitcast to an |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6359 | <a href="#int_trampoline">appropriate function pointer type</a> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 6360 | before being called. The new function's signature is the same as that of |
| 6361 | <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute |
| 6362 | removed. At most one such <tt>nest</tt> argument is allowed, and it must be |
| 6363 | of pointer type. Calling the new function is equivalent to calling |
| 6364 | <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the |
| 6365 | missing <tt>nest</tt> argument. If, after calling |
| 6366 | <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is |
| 6367 | modified, then the effect of any later call to the returned function pointer is |
| 6368 | undefined. |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 6369 | </p> |
| 6370 | </div> |
| 6371 | |
| 6372 | <!-- ======================================================================= --> |
| 6373 | <div class="doc_subsection"> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 6374 | <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a> |
| 6375 | </div> |
| 6376 | |
| 6377 | <div class="doc_text"> |
| 6378 | <p> |
| 6379 | These intrinsic functions expand the "universal IR" of LLVM to represent |
| 6380 | hardware constructs for atomic operations and memory synchronization. This |
| 6381 | provides an interface to the hardware, not an interface to the programmer. It |
Chris Lattner | d3eda89 | 2008-08-05 18:29:16 +0000 | [diff] [blame] | 6382 | is aimed at a low enough level to allow any programming models or APIs |
| 6383 | (Application Programming Interfaces) which |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 6384 | need atomic behaviors to map cleanly onto it. It is also modeled primarily on |
| 6385 | hardware behavior. Just as hardware provides a "universal IR" for source |
| 6386 | languages, it also provides a starting point for developing a "universal" |
| 6387 | atomic operation and synchronization IR. |
| 6388 | </p> |
| 6389 | <p> |
| 6390 | These do <em>not</em> form an API such as high-level threading libraries, |
| 6391 | software transaction memory systems, atomic primitives, and intrinsic |
| 6392 | functions as found in BSD, GNU libc, atomic_ops, APR, and other system and |
| 6393 | application libraries. The hardware interface provided by LLVM should allow |
| 6394 | a clean implementation of all of these APIs and parallel programming models. |
| 6395 | No one model or paradigm should be selected above others unless the hardware |
| 6396 | itself ubiquitously does so. |
| 6397 | |
| 6398 | </p> |
| 6399 | </div> |
| 6400 | |
| 6401 | <!-- _______________________________________________________________________ --> |
| 6402 | <div class="doc_subsubsection"> |
| 6403 | <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a> |
| 6404 | </div> |
| 6405 | <div class="doc_text"> |
| 6406 | <h5>Syntax:</h5> |
| 6407 | <pre> |
| 6408 | declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>, i1 <ss>, |
| 6409 | i1 <device> ) |
| 6410 | |
| 6411 | </pre> |
| 6412 | <h5>Overview:</h5> |
| 6413 | <p> |
| 6414 | The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between |
| 6415 | specific pairs of memory access types. |
| 6416 | </p> |
| 6417 | <h5>Arguments:</h5> |
| 6418 | <p> |
| 6419 | The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments. |
| 6420 | The first four arguments enables a specific barrier as listed below. The fith |
| 6421 | argument specifies that the barrier applies to io or device or uncached memory. |
| 6422 | |
| 6423 | </p> |
| 6424 | <ul> |
| 6425 | <li><tt>ll</tt>: load-load barrier</li> |
| 6426 | <li><tt>ls</tt>: load-store barrier</li> |
| 6427 | <li><tt>sl</tt>: store-load barrier</li> |
| 6428 | <li><tt>ss</tt>: store-store barrier</li> |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 6429 | <li><tt>device</tt>: barrier applies to device and uncached memory also.</li> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 6430 | </ul> |
| 6431 | <h5>Semantics:</h5> |
| 6432 | <p> |
| 6433 | This intrinsic causes the system to enforce some ordering constraints upon |
| 6434 | the loads and stores of the program. This barrier does not indicate |
| 6435 | <em>when</em> any events will occur, it only enforces an <em>order</em> in |
| 6436 | which they occur. For any of the specified pairs of load and store operations |
| 6437 | (f.ex. load-load, or store-load), all of the first operations preceding the |
| 6438 | barrier will complete before any of the second operations succeeding the |
| 6439 | barrier begin. Specifically the semantics for each pairing is as follows: |
| 6440 | </p> |
| 6441 | <ul> |
| 6442 | <li><tt>ll</tt>: All loads before the barrier must complete before any load |
| 6443 | after the barrier begins.</li> |
| 6444 | |
| 6445 | <li><tt>ls</tt>: All loads before the barrier must complete before any |
| 6446 | store after the barrier begins.</li> |
| 6447 | <li><tt>ss</tt>: All stores before the barrier must complete before any |
| 6448 | store after the barrier begins.</li> |
| 6449 | <li><tt>sl</tt>: All stores before the barrier must complete before any |
| 6450 | load after the barrier begins.</li> |
| 6451 | </ul> |
| 6452 | <p> |
| 6453 | These semantics are applied with a logical "and" behavior when more than one |
| 6454 | is enabled in a single memory barrier intrinsic. |
| 6455 | </p> |
| 6456 | <p> |
| 6457 | Backends may implement stronger barriers than those requested when they do not |
| 6458 | support as fine grained a barrier as requested. Some architectures do not |
| 6459 | need all types of barriers and on such architectures, these become noops. |
| 6460 | </p> |
| 6461 | <h5>Example:</h5> |
| 6462 | <pre> |
| 6463 | %ptr = malloc i32 |
| 6464 | store i32 4, %ptr |
| 6465 | |
| 6466 | %result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i> |
| 6467 | call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false ) |
| 6468 | <i>; guarantee the above finishes</i> |
| 6469 | store i32 8, %ptr <i>; before this begins</i> |
| 6470 | </pre> |
| 6471 | </div> |
| 6472 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6473 | <!-- _______________________________________________________________________ --> |
| 6474 | <div class="doc_subsubsection"> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6475 | <a name="int_atomic_cmp_swap">'<tt>llvm.atomic.cmp.swap.*</tt>' Intrinsic</a> |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6476 | </div> |
| 6477 | <div class="doc_text"> |
| 6478 | <h5>Syntax:</h5> |
| 6479 | <p> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6480 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.cmp.swap</tt> on |
| 6481 | any integer bit width and for different address spaces. Not all targets |
| 6482 | support all bit widths however.</p> |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6483 | |
| 6484 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6485 | declare i8 @llvm.atomic.cmp.swap.i8.p0i8( i8* <ptr>, i8 <cmp>, i8 <val> ) |
| 6486 | declare i16 @llvm.atomic.cmp.swap.i16.p0i16( i16* <ptr>, i16 <cmp>, i16 <val> ) |
| 6487 | declare i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* <ptr>, i32 <cmp>, i32 <val> ) |
| 6488 | declare i64 @llvm.atomic.cmp.swap.i64.p0i64( i64* <ptr>, i64 <cmp>, i64 <val> ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6489 | |
| 6490 | </pre> |
| 6491 | <h5>Overview:</h5> |
| 6492 | <p> |
| 6493 | This loads a value in memory and compares it to a given value. If they are |
| 6494 | equal, it stores a new value into the memory. |
| 6495 | </p> |
| 6496 | <h5>Arguments:</h5> |
| 6497 | <p> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6498 | The <tt>llvm.atomic.cmp.swap</tt> intrinsic takes three arguments. The result as |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6499 | well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the |
| 6500 | same bit width. The <tt>ptr</tt> argument must be a pointer to a value of |
| 6501 | this integer type. While any bit width integer may be used, targets may only |
| 6502 | lower representations they support in hardware. |
| 6503 | |
| 6504 | </p> |
| 6505 | <h5>Semantics:</h5> |
| 6506 | <p> |
| 6507 | This entire intrinsic must be executed atomically. It first loads the value |
| 6508 | in memory pointed to by <tt>ptr</tt> and compares it with the value |
| 6509 | <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The |
| 6510 | loaded value is yielded in all cases. This provides the equivalent of an |
| 6511 | atomic compare-and-swap operation within the SSA framework. |
| 6512 | </p> |
| 6513 | <h5>Examples:</h5> |
| 6514 | |
| 6515 | <pre> |
| 6516 | %ptr = malloc i32 |
| 6517 | store i32 4, %ptr |
| 6518 | |
| 6519 | %val1 = add i32 4, 4 |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6520 | %result1 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 4, %val1 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6521 | <i>; yields {i32}:result1 = 4</i> |
| 6522 | %stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i> |
| 6523 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i> |
| 6524 | |
| 6525 | %val2 = add i32 1, 1 |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6526 | %result2 = call i32 @llvm.atomic.cmp.swap.i32.p0i32( i32* %ptr, i32 5, %val2 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6527 | <i>; yields {i32}:result2 = 8</i> |
| 6528 | %stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i> |
| 6529 | |
| 6530 | %memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i> |
| 6531 | </pre> |
| 6532 | </div> |
| 6533 | |
| 6534 | <!-- _______________________________________________________________________ --> |
| 6535 | <div class="doc_subsubsection"> |
| 6536 | <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a> |
| 6537 | </div> |
| 6538 | <div class="doc_text"> |
| 6539 | <h5>Syntax:</h5> |
| 6540 | |
| 6541 | <p> |
| 6542 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any |
| 6543 | integer bit width. Not all targets support all bit widths however.</p> |
| 6544 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6545 | declare i8 @llvm.atomic.swap.i8.p0i8( i8* <ptr>, i8 <val> ) |
| 6546 | declare i16 @llvm.atomic.swap.i16.p0i16( i16* <ptr>, i16 <val> ) |
| 6547 | declare i32 @llvm.atomic.swap.i32.p0i32( i32* <ptr>, i32 <val> ) |
| 6548 | declare i64 @llvm.atomic.swap.i64.p0i64( i64* <ptr>, i64 <val> ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6549 | |
| 6550 | </pre> |
| 6551 | <h5>Overview:</h5> |
| 6552 | <p> |
| 6553 | This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields |
| 6554 | the value from memory. It then stores the value in <tt>val</tt> in the memory |
| 6555 | at <tt>ptr</tt>. |
| 6556 | </p> |
| 6557 | <h5>Arguments:</h5> |
| 6558 | |
| 6559 | <p> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6560 | The <tt>llvm.atomic.swap</tt> intrinsic takes two arguments. Both the |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6561 | <tt>val</tt> argument and the result must be integers of the same bit width. |
| 6562 | The first argument, <tt>ptr</tt>, must be a pointer to a value of this |
| 6563 | integer type. The targets may only lower integer representations they |
| 6564 | support. |
| 6565 | </p> |
| 6566 | <h5>Semantics:</h5> |
| 6567 | <p> |
| 6568 | This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and |
| 6569 | stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the |
| 6570 | equivalent of an atomic swap operation within the SSA framework. |
| 6571 | |
| 6572 | </p> |
| 6573 | <h5>Examples:</h5> |
| 6574 | <pre> |
| 6575 | %ptr = malloc i32 |
| 6576 | store i32 4, %ptr |
| 6577 | |
| 6578 | %val1 = add i32 4, 4 |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6579 | %result1 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val1 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6580 | <i>; yields {i32}:result1 = 4</i> |
| 6581 | %stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i> |
| 6582 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i> |
| 6583 | |
| 6584 | %val2 = add i32 1, 1 |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6585 | %result2 = call i32 @llvm.atomic.swap.i32.p0i32( i32* %ptr, i32 %val2 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6586 | <i>; yields {i32}:result2 = 8</i> |
| 6587 | |
| 6588 | %stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i> |
| 6589 | %memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i> |
| 6590 | </pre> |
| 6591 | </div> |
| 6592 | |
| 6593 | <!-- _______________________________________________________________________ --> |
| 6594 | <div class="doc_subsubsection"> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6595 | <a name="int_atomic_load_add">'<tt>llvm.atomic.load.add.*</tt>' Intrinsic</a> |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6596 | |
| 6597 | </div> |
| 6598 | <div class="doc_text"> |
| 6599 | <h5>Syntax:</h5> |
| 6600 | <p> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6601 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.add</tt> on any |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6602 | integer bit width. Not all targets support all bit widths however.</p> |
| 6603 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6604 | declare i8 @llvm.atomic.load.add.i8..p0i8( i8* <ptr>, i8 <delta> ) |
| 6605 | declare i16 @llvm.atomic.load.add.i16..p0i16( i16* <ptr>, i16 <delta> ) |
| 6606 | declare i32 @llvm.atomic.load.add.i32..p0i32( i32* <ptr>, i32 <delta> ) |
| 6607 | declare i64 @llvm.atomic.load.add.i64..p0i64( i64* <ptr>, i64 <delta> ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6608 | |
| 6609 | </pre> |
| 6610 | <h5>Overview:</h5> |
| 6611 | <p> |
| 6612 | This intrinsic adds <tt>delta</tt> to the value stored in memory at |
| 6613 | <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>. |
| 6614 | </p> |
| 6615 | <h5>Arguments:</h5> |
| 6616 | <p> |
| 6617 | |
| 6618 | The intrinsic takes two arguments, the first a pointer to an integer value |
| 6619 | and the second an integer value. The result is also an integer value. These |
| 6620 | integer types can have any bit width, but they must all have the same bit |
| 6621 | width. The targets may only lower integer representations they support. |
| 6622 | </p> |
| 6623 | <h5>Semantics:</h5> |
| 6624 | <p> |
| 6625 | This intrinsic does a series of operations atomically. It first loads the |
| 6626 | value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result |
| 6627 | to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>. |
| 6628 | </p> |
| 6629 | |
| 6630 | <h5>Examples:</h5> |
| 6631 | <pre> |
| 6632 | %ptr = malloc i32 |
| 6633 | store i32 4, %ptr |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6634 | %result1 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 4 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6635 | <i>; yields {i32}:result1 = 4</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6636 | %result2 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 2 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6637 | <i>; yields {i32}:result2 = 8</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6638 | %result3 = call i32 @llvm.atomic.load.add.i32.p0i32( i32* %ptr, i32 5 ) |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6639 | <i>; yields {i32}:result3 = 10</i> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6640 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 15</i> |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 6641 | </pre> |
| 6642 | </div> |
| 6643 | |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6644 | <!-- _______________________________________________________________________ --> |
| 6645 | <div class="doc_subsubsection"> |
| 6646 | <a name="int_atomic_load_sub">'<tt>llvm.atomic.load.sub.*</tt>' Intrinsic</a> |
| 6647 | |
| 6648 | </div> |
| 6649 | <div class="doc_text"> |
| 6650 | <h5>Syntax:</h5> |
| 6651 | <p> |
| 6652 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.load.sub</tt> on |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6653 | any integer bit width and for different address spaces. Not all targets |
| 6654 | support all bit widths however.</p> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6655 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6656 | declare i8 @llvm.atomic.load.sub.i8.p0i32( i8* <ptr>, i8 <delta> ) |
| 6657 | declare i16 @llvm.atomic.load.sub.i16.p0i32( i16* <ptr>, i16 <delta> ) |
| 6658 | declare i32 @llvm.atomic.load.sub.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6659 | declare i64 @llvm.atomic.load.sub.i64.p0i32( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6660 | |
| 6661 | </pre> |
| 6662 | <h5>Overview:</h5> |
| 6663 | <p> |
| 6664 | This intrinsic subtracts <tt>delta</tt> to the value stored in memory at |
| 6665 | <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>. |
| 6666 | </p> |
| 6667 | <h5>Arguments:</h5> |
| 6668 | <p> |
| 6669 | |
| 6670 | The intrinsic takes two arguments, the first a pointer to an integer value |
| 6671 | and the second an integer value. The result is also an integer value. These |
| 6672 | integer types can have any bit width, but they must all have the same bit |
| 6673 | width. The targets may only lower integer representations they support. |
| 6674 | </p> |
| 6675 | <h5>Semantics:</h5> |
| 6676 | <p> |
| 6677 | This intrinsic does a series of operations atomically. It first loads the |
| 6678 | value stored at <tt>ptr</tt>. It then subtracts <tt>delta</tt>, stores the |
| 6679 | result to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>. |
| 6680 | </p> |
| 6681 | |
| 6682 | <h5>Examples:</h5> |
| 6683 | <pre> |
| 6684 | %ptr = malloc i32 |
| 6685 | store i32 8, %ptr |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6686 | %result1 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 4 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6687 | <i>; yields {i32}:result1 = 8</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6688 | %result2 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 2 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6689 | <i>; yields {i32}:result2 = 4</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6690 | %result3 = call i32 @llvm.atomic.load.sub.i32.p0i32( i32* %ptr, i32 5 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6691 | <i>; yields {i32}:result3 = 2</i> |
| 6692 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = -3</i> |
| 6693 | </pre> |
| 6694 | </div> |
| 6695 | |
| 6696 | <!-- _______________________________________________________________________ --> |
| 6697 | <div class="doc_subsubsection"> |
| 6698 | <a name="int_atomic_load_and">'<tt>llvm.atomic.load.and.*</tt>' Intrinsic</a><br> |
| 6699 | <a name="int_atomic_load_nand">'<tt>llvm.atomic.load.nand.*</tt>' Intrinsic</a><br> |
| 6700 | <a name="int_atomic_load_or">'<tt>llvm.atomic.load.or.*</tt>' Intrinsic</a><br> |
| 6701 | <a name="int_atomic_load_xor">'<tt>llvm.atomic.load.xor.*</tt>' Intrinsic</a><br> |
| 6702 | |
| 6703 | </div> |
| 6704 | <div class="doc_text"> |
| 6705 | <h5>Syntax:</h5> |
| 6706 | <p> |
| 6707 | These are overloaded intrinsics. You can use <tt>llvm.atomic.load_and</tt>, |
| 6708 | <tt>llvm.atomic.load_nand</tt>, <tt>llvm.atomic.load_or</tt>, and |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6709 | <tt>llvm.atomic.load_xor</tt> on any integer bit width and for different |
| 6710 | address spaces. Not all targets support all bit widths however.</p> |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6711 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6712 | declare i8 @llvm.atomic.load.and.i8.p0i8( i8* <ptr>, i8 <delta> ) |
| 6713 | declare i16 @llvm.atomic.load.and.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6714 | declare i32 @llvm.atomic.load.and.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6715 | declare i64 @llvm.atomic.load.and.i64.p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6716 | |
| 6717 | </pre> |
| 6718 | |
| 6719 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6720 | declare i8 @llvm.atomic.load.or.i8.p0i8( i8* <ptr>, i8 <delta> ) |
| 6721 | declare i16 @llvm.atomic.load.or.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6722 | declare i32 @llvm.atomic.load.or.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6723 | declare i64 @llvm.atomic.load.or.i64.p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6724 | |
| 6725 | </pre> |
| 6726 | |
| 6727 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6728 | declare i8 @llvm.atomic.load.nand.i8.p0i32( i8* <ptr>, i8 <delta> ) |
| 6729 | declare i16 @llvm.atomic.load.nand.i16.p0i32( i16* <ptr>, i16 <delta> ) |
| 6730 | declare i32 @llvm.atomic.load.nand.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6731 | declare i64 @llvm.atomic.load.nand.i64.p0i32( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6732 | |
| 6733 | </pre> |
| 6734 | |
| 6735 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6736 | declare i8 @llvm.atomic.load.xor.i8.p0i32( i8* <ptr>, i8 <delta> ) |
| 6737 | declare i16 @llvm.atomic.load.xor.i16.p0i32( i16* <ptr>, i16 <delta> ) |
| 6738 | declare i32 @llvm.atomic.load.xor.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6739 | declare i64 @llvm.atomic.load.xor.i64.p0i32( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6740 | |
| 6741 | </pre> |
| 6742 | <h5>Overview:</h5> |
| 6743 | <p> |
| 6744 | These intrinsics bitwise the operation (and, nand, or, xor) <tt>delta</tt> to |
| 6745 | the value stored in memory at <tt>ptr</tt>. It yields the original value |
| 6746 | at <tt>ptr</tt>. |
| 6747 | </p> |
| 6748 | <h5>Arguments:</h5> |
| 6749 | <p> |
| 6750 | |
| 6751 | These intrinsics take two arguments, the first a pointer to an integer value |
| 6752 | and the second an integer value. The result is also an integer value. These |
| 6753 | integer types can have any bit width, but they must all have the same bit |
| 6754 | width. The targets may only lower integer representations they support. |
| 6755 | </p> |
| 6756 | <h5>Semantics:</h5> |
| 6757 | <p> |
| 6758 | These intrinsics does a series of operations atomically. They first load the |
| 6759 | value stored at <tt>ptr</tt>. They then do the bitwise operation |
| 6760 | <tt>delta</tt>, store the result to <tt>ptr</tt>. They yield the original |
| 6761 | value stored at <tt>ptr</tt>. |
| 6762 | </p> |
| 6763 | |
| 6764 | <h5>Examples:</h5> |
| 6765 | <pre> |
| 6766 | %ptr = malloc i32 |
| 6767 | store i32 0x0F0F, %ptr |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6768 | %result0 = call i32 @llvm.atomic.load.nand.i32.p0i32( i32* %ptr, i32 0xFF ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6769 | <i>; yields {i32}:result0 = 0x0F0F</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6770 | %result1 = call i32 @llvm.atomic.load.and.i32.p0i32( i32* %ptr, i32 0xFF ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6771 | <i>; yields {i32}:result1 = 0xFFFFFFF0</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6772 | %result2 = call i32 @llvm.atomic.load.or.i32.p0i32( i32* %ptr, i32 0F ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6773 | <i>; yields {i32}:result2 = 0xF0</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6774 | %result3 = call i32 @llvm.atomic.load.xor.i32.p0i32( i32* %ptr, i32 0F ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6775 | <i>; yields {i32}:result3 = FF</i> |
| 6776 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = F0</i> |
| 6777 | </pre> |
| 6778 | </div> |
| 6779 | |
| 6780 | |
| 6781 | <!-- _______________________________________________________________________ --> |
| 6782 | <div class="doc_subsubsection"> |
| 6783 | <a name="int_atomic_load_max">'<tt>llvm.atomic.load.max.*</tt>' Intrinsic</a><br> |
| 6784 | <a name="int_atomic_load_min">'<tt>llvm.atomic.load.min.*</tt>' Intrinsic</a><br> |
| 6785 | <a name="int_atomic_load_umax">'<tt>llvm.atomic.load.umax.*</tt>' Intrinsic</a><br> |
| 6786 | <a name="int_atomic_load_umin">'<tt>llvm.atomic.load.umin.*</tt>' Intrinsic</a><br> |
| 6787 | |
| 6788 | </div> |
| 6789 | <div class="doc_text"> |
| 6790 | <h5>Syntax:</h5> |
| 6791 | <p> |
| 6792 | These are overloaded intrinsics. You can use <tt>llvm.atomic.load_max</tt>, |
| 6793 | <tt>llvm.atomic.load_min</tt>, <tt>llvm.atomic.load_umax</tt>, and |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6794 | <tt>llvm.atomic.load_umin</tt> on any integer bit width and for different |
| 6795 | address spaces. Not all targets |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6796 | support all bit widths however.</p> |
| 6797 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6798 | declare i8 @llvm.atomic.load.max.i8.p0i8( i8* <ptr>, i8 <delta> ) |
| 6799 | declare i16 @llvm.atomic.load.max.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6800 | declare i32 @llvm.atomic.load.max.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6801 | declare i64 @llvm.atomic.load.max.i64.p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6802 | |
| 6803 | </pre> |
| 6804 | |
| 6805 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6806 | declare i8 @llvm.atomic.load.min.i8.p0i8( i8* <ptr>, i8 <delta> ) |
| 6807 | declare i16 @llvm.atomic.load.min.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6808 | declare i32 @llvm.atomic.load.min.i32..p0i32( i32* <ptr>, i32 <delta> ) |
| 6809 | declare i64 @llvm.atomic.load.min.i64..p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6810 | |
| 6811 | </pre> |
| 6812 | |
| 6813 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6814 | declare i8 @llvm.atomic.load.umax.i8.p0i8( i8* <ptr>, i8 <delta> ) |
| 6815 | declare i16 @llvm.atomic.load.umax.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6816 | declare i32 @llvm.atomic.load.umax.i32.p0i32( i32* <ptr>, i32 <delta> ) |
| 6817 | declare i64 @llvm.atomic.load.umax.i64.p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6818 | |
| 6819 | </pre> |
| 6820 | |
| 6821 | <pre> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6822 | declare i8 @llvm.atomic.load.umin.i8..p0i8( i8* <ptr>, i8 <delta> ) |
| 6823 | declare i16 @llvm.atomic.load.umin.i16.p0i16( i16* <ptr>, i16 <delta> ) |
| 6824 | declare i32 @llvm.atomic.load.umin.i32..p0i32( i32* <ptr>, i32 <delta> ) |
| 6825 | declare i64 @llvm.atomic.load.umin.i64..p0i64( i64* <ptr>, i64 <delta> ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6826 | |
| 6827 | </pre> |
| 6828 | <h5>Overview:</h5> |
| 6829 | <p> |
| 6830 | These intrinsics takes the signed or unsigned minimum or maximum of |
| 6831 | <tt>delta</tt> and the value stored in memory at <tt>ptr</tt>. It yields the |
| 6832 | original value at <tt>ptr</tt>. |
| 6833 | </p> |
| 6834 | <h5>Arguments:</h5> |
| 6835 | <p> |
| 6836 | |
| 6837 | These intrinsics take two arguments, the first a pointer to an integer value |
| 6838 | and the second an integer value. The result is also an integer value. These |
| 6839 | integer types can have any bit width, but they must all have the same bit |
| 6840 | width. The targets may only lower integer representations they support. |
| 6841 | </p> |
| 6842 | <h5>Semantics:</h5> |
| 6843 | <p> |
| 6844 | These intrinsics does a series of operations atomically. They first load the |
| 6845 | value stored at <tt>ptr</tt>. They then do the signed or unsigned min or max |
| 6846 | <tt>delta</tt> and the value, store the result to <tt>ptr</tt>. They yield |
| 6847 | the original value stored at <tt>ptr</tt>. |
| 6848 | </p> |
| 6849 | |
| 6850 | <h5>Examples:</h5> |
| 6851 | <pre> |
| 6852 | %ptr = malloc i32 |
| 6853 | store i32 7, %ptr |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6854 | %result0 = call i32 @llvm.atomic.load.min.i32.p0i32( i32* %ptr, i32 -2 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6855 | <i>; yields {i32}:result0 = 7</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6856 | %result1 = call i32 @llvm.atomic.load.max.i32.p0i32( i32* %ptr, i32 8 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6857 | <i>; yields {i32}:result1 = -2</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6858 | %result2 = call i32 @llvm.atomic.load.umin.i32.p0i32( i32* %ptr, i32 10 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6859 | <i>; yields {i32}:result2 = 8</i> |
Mon P Wang | e3b3a72 | 2008-07-30 04:36:53 +0000 | [diff] [blame] | 6860 | %result3 = call i32 @llvm.atomic.load.umax.i32.p0i32( i32* %ptr, i32 30 ) |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 6861 | <i>; yields {i32}:result3 = 8</i> |
| 6862 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 30</i> |
| 6863 | </pre> |
| 6864 | </div> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 6865 | |
| 6866 | <!-- ======================================================================= --> |
| 6867 | <div class="doc_subsection"> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 6868 | <a name="int_general">General Intrinsics</a> |
| 6869 | </div> |
| 6870 | |
| 6871 | <div class="doc_text"> |
| 6872 | <p> This class of intrinsics is designed to be generic and has |
| 6873 | no specific purpose. </p> |
| 6874 | </div> |
| 6875 | |
| 6876 | <!-- _______________________________________________________________________ --> |
| 6877 | <div class="doc_subsubsection"> |
| 6878 | <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a> |
| 6879 | </div> |
| 6880 | |
| 6881 | <div class="doc_text"> |
| 6882 | |
| 6883 | <h5>Syntax:</h5> |
| 6884 | <pre> |
Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 6885 | 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] | 6886 | </pre> |
| 6887 | |
| 6888 | <h5>Overview:</h5> |
| 6889 | |
| 6890 | <p> |
| 6891 | The '<tt>llvm.var.annotation</tt>' intrinsic |
| 6892 | </p> |
| 6893 | |
| 6894 | <h5>Arguments:</h5> |
| 6895 | |
| 6896 | <p> |
Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 6897 | The first argument is a pointer to a value, the second is a pointer to a |
| 6898 | global string, the third is a pointer to a global string which is the source |
| 6899 | file name, and the last argument is the line number. |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 6900 | </p> |
| 6901 | |
| 6902 | <h5>Semantics:</h5> |
| 6903 | |
| 6904 | <p> |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 6905 | This intrinsic allows annotation of local variables with arbitrary strings. |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 6906 | 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] | 6907 | annotations. These have no other defined use, they are ignored by code |
| 6908 | generation and optimization. |
| 6909 | </p> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 6910 | </div> |
| 6911 | |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6912 | <!-- _______________________________________________________________________ --> |
| 6913 | <div class="doc_subsubsection"> |
Tanya Lattner | e1a8da0 | 2007-09-21 23:57:59 +0000 | [diff] [blame] | 6914 | <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6915 | </div> |
| 6916 | |
| 6917 | <div class="doc_text"> |
| 6918 | |
| 6919 | <h5>Syntax:</h5> |
Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 6920 | <p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on |
| 6921 | any integer bit width. |
| 6922 | </p> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6923 | <pre> |
Tanya Lattner | d3989a8 | 2007-09-22 00:03:01 +0000 | [diff] [blame] | 6924 | declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 6925 | declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 6926 | declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 6927 | declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 6928 | 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] | 6929 | </pre> |
| 6930 | |
| 6931 | <h5>Overview:</h5> |
Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 6932 | |
| 6933 | <p> |
| 6934 | The '<tt>llvm.annotation</tt>' intrinsic. |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6935 | </p> |
| 6936 | |
| 6937 | <h5>Arguments:</h5> |
| 6938 | |
| 6939 | <p> |
| 6940 | The first argument is an integer value (result of some expression), |
| 6941 | the second is a pointer to a global string, the third is a pointer to a global |
| 6942 | 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] | 6943 | It returns the value of the first argument. |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6944 | </p> |
| 6945 | |
| 6946 | <h5>Semantics:</h5> |
| 6947 | |
| 6948 | <p> |
| 6949 | This intrinsic allows annotations to be put on arbitrary expressions |
| 6950 | with arbitrary strings. This can be useful for special purpose optimizations |
| 6951 | that want to look for these annotations. These have no other defined use, they |
| 6952 | are ignored by code generation and optimization. |
Dan Gohman | 0e451ce | 2008-10-14 16:51:45 +0000 | [diff] [blame] | 6953 | </p> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 6954 | </div> |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 6955 | |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 6956 | <!-- _______________________________________________________________________ --> |
| 6957 | <div class="doc_subsubsection"> |
| 6958 | <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a> |
| 6959 | </div> |
| 6960 | |
| 6961 | <div class="doc_text"> |
| 6962 | |
| 6963 | <h5>Syntax:</h5> |
| 6964 | <pre> |
| 6965 | declare void @llvm.trap() |
| 6966 | </pre> |
| 6967 | |
| 6968 | <h5>Overview:</h5> |
| 6969 | |
| 6970 | <p> |
| 6971 | The '<tt>llvm.trap</tt>' intrinsic |
| 6972 | </p> |
| 6973 | |
| 6974 | <h5>Arguments:</h5> |
| 6975 | |
| 6976 | <p> |
| 6977 | None |
| 6978 | </p> |
| 6979 | |
| 6980 | <h5>Semantics:</h5> |
| 6981 | |
| 6982 | <p> |
| 6983 | This intrinsics is lowered to the target dependent trap instruction. If the |
| 6984 | target does not have a trap instruction, this intrinsic will be lowered to the |
| 6985 | call of the abort() function. |
| 6986 | </p> |
| 6987 | </div> |
| 6988 | |
Bill Wendling | 69e4adb | 2008-11-19 05:56:17 +0000 | [diff] [blame] | 6989 | <!-- _______________________________________________________________________ --> |
| 6990 | <div class="doc_subsubsection"> |
Misha Brukman | dccb025 | 2008-11-22 23:55:29 +0000 | [diff] [blame] | 6991 | <a name="int_stackprotector">'<tt>llvm.stackprotector</tt>' Intrinsic</a> |
Bill Wendling | 69e4adb | 2008-11-19 05:56:17 +0000 | [diff] [blame] | 6992 | </div> |
| 6993 | <div class="doc_text"> |
| 6994 | <h5>Syntax:</h5> |
| 6995 | <pre> |
| 6996 | declare void @llvm.stackprotector( i8* <guard>, i8** <slot> ) |
| 6997 | |
| 6998 | </pre> |
| 6999 | <h5>Overview:</h5> |
| 7000 | <p> |
| 7001 | The <tt>llvm.stackprotector</tt> intrinsic takes the <tt>guard</tt> and stores |
| 7002 | it onto the stack at <tt>slot</tt>. The stack slot is adjusted to ensure that |
| 7003 | it is placed on the stack before local variables. |
| 7004 | </p> |
| 7005 | <h5>Arguments:</h5> |
| 7006 | <p> |
| 7007 | The <tt>llvm.stackprotector</tt> intrinsic requires two pointer arguments. The |
| 7008 | first argument is the value loaded from the stack guard |
| 7009 | <tt>@__stack_chk_guard</tt>. The second variable is an <tt>alloca</tt> that |
| 7010 | has enough space to hold the value of the guard. |
| 7011 | </p> |
| 7012 | <h5>Semantics:</h5> |
| 7013 | <p> |
| 7014 | This intrinsic causes the prologue/epilogue inserter to force the position of |
| 7015 | the <tt>AllocaInst</tt> stack slot to be before local variables on the |
| 7016 | stack. This is to ensure that if a local variable on the stack is overwritten, |
| 7017 | it will destroy the value of the guard. When the function exits, the guard on |
| 7018 | the stack is checked against the original guard. If they're different, then |
| 7019 | the program aborts by calling the <tt>__stack_chk_fail()</tt> function. |
| 7020 | </p> |
| 7021 | </div> |
| 7022 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 7023 | <!-- *********************************************************************** --> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 7024 | <hr> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 7025 | <address> |
| 7026 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 7027 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 7028 | <a href="http://validator.w3.org/check/referer"><img |
Misha Brukman | 4440870 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 7029 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 7030 | |
| 7031 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 7032 | <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 7033 | Last modified: $Date$ |
| 7034 | </address> |
Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 7035 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 7036 | </body> |
| 7037 | </html> |