Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3 | <html> |
| 4 | <head> |
| 5 | <title>LLVM Assembly Language Reference Manual</title> |
Reid Spencer | 3921c74 | 2004-08-26 20:44:00 +0000 | [diff] [blame] | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 7 | <meta name="author" content="Chris Lattner"> |
| 8 | <meta name="description" |
| 9 | content="LLVM Assembly Language Reference Manual."> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 10 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
| 11 | </head> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 12 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 13 | <body> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 14 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 15 | <div class="doc_title"> LLVM Language Reference Manual </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 17 | <li><a href="#abstract">Abstract</a></li> |
| 18 | <li><a href="#introduction">Introduction</a></li> |
| 19 | <li><a href="#identifiers">Identifiers</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 20 | <li><a href="#highlevel">High Level Structure</a> |
| 21 | <ol> |
| 22 | <li><a href="#modulestructure">Module Structure</a></li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 23 | <li><a href="#linkage">Linkage Types</a></li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 24 | <li><a href="#callingconv">Calling Conventions</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 25 | <li><a href="#globalvars">Global Variables</a></li> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 26 | <li><a href="#functionstructure">Functions</a></li> |
Anton Korobeynikov | c6c98af | 2007-04-29 18:02:48 +0000 | [diff] [blame] | 27 | <li><a href="#aliasstructure">Aliases</a> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 28 | <li><a href="#paramattrs">Parameter Attributes</a></li> |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 29 | <li><a href="#gc">Garbage Collector Names</a></li> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 30 | <li><a href="#moduleasm">Module-Level Inline Assembly</a></li> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 31 | <li><a href="#datalayout">Data Layout</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 32 | </ol> |
| 33 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 34 | <li><a href="#typesystem">Type System</a> |
| 35 | <ol> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 36 | <li><a href="#t_classifications">Type Classifications</a></li> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 37 | <li><a href="#t_primitive">Primitive Types</a> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 38 | <ol> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 39 | <li><a href="#t_floating">Floating Point Types</a></li> |
| 40 | <li><a href="#t_void">Void Type</a></li> |
| 41 | <li><a href="#t_label">Label Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 42 | </ol> |
| 43 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 44 | <li><a href="#t_derived">Derived Types</a> |
| 45 | <ol> |
Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 46 | <li><a href="#t_integer">Integer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 47 | <li><a href="#t_array">Array Type</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 48 | <li><a href="#t_function">Function Type</a></li> |
| 49 | <li><a href="#t_pointer">Pointer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 50 | <li><a href="#t_struct">Structure Type</a></li> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 51 | <li><a href="#t_pstruct">Packed Structure Type</a></li> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 52 | <li><a href="#t_vector">Vector Type</a></li> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 53 | <li><a href="#t_opaque">Opaque Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 54 | </ol> |
| 55 | </li> |
| 56 | </ol> |
| 57 | </li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 58 | <li><a href="#constants">Constants</a> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 59 | <ol> |
| 60 | <li><a href="#simpleconstants">Simple Constants</a> |
| 61 | <li><a href="#aggregateconstants">Aggregate Constants</a> |
| 62 | <li><a href="#globalconstants">Global Variable and Function Addresses</a> |
| 63 | <li><a href="#undefvalues">Undefined Values</a> |
| 64 | <li><a href="#constantexprs">Constant Expressions</a> |
| 65 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 66 | </li> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 67 | <li><a href="#othervalues">Other Values</a> |
| 68 | <ol> |
| 69 | <li><a href="#inlineasm">Inline Assembler Expressions</a> |
| 70 | </ol> |
| 71 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 72 | <li><a href="#instref">Instruction Reference</a> |
| 73 | <ol> |
| 74 | <li><a href="#terminators">Terminator Instructions</a> |
| 75 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 76 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> |
| 77 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 78 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> |
| 79 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 80 | <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 81 | <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 82 | </ol> |
| 83 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 84 | <li><a href="#binaryops">Binary Operations</a> |
| 85 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 86 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> |
| 87 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> |
| 88 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 89 | <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li> |
| 90 | <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li> |
| 91 | <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 92 | <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li> |
| 93 | <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li> |
| 94 | <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 95 | </ol> |
| 96 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 97 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> |
| 98 | <ol> |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 99 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> |
| 100 | <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li> |
| 101 | <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 102 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 103 | <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 104 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 105 | </ol> |
| 106 | </li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 107 | <li><a href="#vectorops">Vector Operations</a> |
| 108 | <ol> |
| 109 | <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li> |
| 110 | <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li> |
| 111 | <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 112 | </ol> |
| 113 | </li> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 114 | <li><a href="#memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 115 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 116 | <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li> |
| 117 | <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li> |
| 118 | <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 119 | <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li> |
| 120 | <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li> |
| 121 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 122 | </ol> |
| 123 | </li> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 124 | <li><a href="#convertops">Conversion Operations</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 125 | <ol> |
| 126 | <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li> |
| 127 | <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li> |
| 128 | <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li> |
| 129 | <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li> |
| 130 | <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 131 | <li><a href="#i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a></li> |
| 132 | <li><a href="#i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a></li> |
| 133 | <li><a href="#i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a></li> |
| 134 | <li><a href="#i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a></li> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 135 | <li><a href="#i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a></li> |
| 136 | <li><a href="#i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a></li> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 137 | <li><a href="#i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a></li> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 138 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 139 | <li><a href="#otherops">Other Operations</a> |
| 140 | <ol> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 141 | <li><a href="#i_icmp">'<tt>icmp</tt>' Instruction</a></li> |
| 142 | <li><a href="#i_fcmp">'<tt>fcmp</tt>' Instruction</a></li> |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 143 | <li><a href="#i_vicmp">'<tt>vicmp</tt>' Instruction</a></li> |
| 144 | <li><a href="#i_vfcmp">'<tt>vfcmp</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 145 | <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 146 | <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 147 | <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 148 | <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 149 | <li><a href="#i_getresult">'<tt>getresult</tt>' Instruction</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 150 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 151 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 152 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 153 | </li> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 154 | <li><a href="#intrinsics">Intrinsic Functions</a> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 155 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 156 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> |
| 157 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 158 | <li><a href="#int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> |
| 159 | <li><a href="#int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li> |
| 160 | <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] | 161 | </ol> |
| 162 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 163 | <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> |
| 164 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 165 | <li><a href="#int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> |
| 166 | <li><a href="#int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> |
| 167 | <li><a href="#int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 168 | </ol> |
| 169 | </li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 170 | <li><a href="#int_codegen">Code Generator Intrinsics</a> |
| 171 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 172 | <li><a href="#int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> |
| 173 | <li><a href="#int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li> |
| 174 | <li><a href="#int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li> |
| 175 | <li><a href="#int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li> |
| 176 | <li><a href="#int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li> |
| 177 | <li><a href="#int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li> |
| 178 | <li><a href="#int_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 179 | </ol> |
| 180 | </li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 181 | <li><a href="#int_libc">Standard C Library Intrinsics</a> |
| 182 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 183 | <li><a href="#int_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li> |
| 184 | <li><a href="#int_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li> |
| 185 | <li><a href="#int_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li> |
| 186 | <li><a href="#int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li> |
| 187 | <li><a href="#int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 188 | <li><a href="#int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a></li> |
| 189 | <li><a href="#int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a></li> |
| 190 | <li><a href="#int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a></li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 191 | </ol> |
| 192 | </li> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 193 | <li><a href="#int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 194 | <ol> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 195 | <li><a href="#int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 196 | <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li> |
| 197 | <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li> |
| 198 | <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li> |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 199 | <li><a href="#int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic </a></li> |
| 200 | <li><a href="#int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic </a></li> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 201 | </ol> |
| 202 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 203 | <li><a href="#int_debugger">Debugger intrinsics</a></li> |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 204 | <li><a href="#int_eh">Exception Handling intrinsics</a></li> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 205 | <li><a href="#int_trampoline">Trampoline Intrinsic</a> |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 206 | <ol> |
| 207 | <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] | 208 | </ol> |
| 209 | </li> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 210 | <li><a href="#int_atomics">Atomic intrinsics</a> |
| 211 | <ol> |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 212 | <li><a href="#int_memory_barrier"><tt>llvm.memory_barrier</tt></a></li> |
| 213 | <li><a href="#int_atomic_lcs"><tt>llvm.atomic.lcs</tt></a></li> |
| 214 | <li><a href="#int_atomic_las"><tt>llvm.atomic.las</tt></a></li> |
| 215 | <li><a href="#int_atomic_swap"><tt>llvm.atomic.swap</tt></a></li> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 216 | </ol> |
| 217 | </li> |
Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 218 | <li><a href="#int_general">General intrinsics</a> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 219 | <ol> |
Reid Spencer | 2067764 | 2007-07-20 19:59:11 +0000 | [diff] [blame] | 220 | <li><a href="#int_var_annotation"> |
Tanya Lattner | 91d0b88 | 2007-09-22 00:01:26 +0000 | [diff] [blame] | 221 | <tt>llvm.var.annotation</tt>' Intrinsic</a></li> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 222 | <li><a href="#int_annotation"> |
Tanya Lattner | 91d0b88 | 2007-09-22 00:01:26 +0000 | [diff] [blame] | 223 | <tt>llvm.annotation.*</tt>' Intrinsic</a></li> |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 224 | <li><a href="#int_trap"> |
| 225 | <tt>llvm.trap</tt>' Intrinsic</a></li> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 226 | </ol> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 227 | </li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 228 | </ol> |
| 229 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 230 | </ol> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 231 | |
| 232 | <div class="doc_author"> |
| 233 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
| 234 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 235 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 236 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 237 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 238 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 239 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 240 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 241 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 242 | <p>This document is a reference manual for the LLVM assembly language. |
| 243 | LLVM is an SSA based representation that provides type safety, |
| 244 | low-level operations, flexibility, and the capability of representing |
| 245 | 'all' high-level languages cleanly. It is the common code |
| 246 | representation used throughout all phases of the LLVM compilation |
| 247 | strategy.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 248 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 250 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 251 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> |
| 252 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 253 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 254 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 256 | <p>The LLVM code representation is designed to be used in three |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 257 | 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] | 258 | representation (suitable for fast loading by a Just-In-Time compiler), |
| 259 | and as a human readable assembly language representation. This allows |
| 260 | LLVM to provide a powerful intermediate representation for efficient |
| 261 | compiler transformations and analysis, while providing a natural means |
| 262 | to debug and visualize the transformations. The three different forms |
| 263 | of LLVM are all equivalent. This document describes the human readable |
| 264 | representation and notation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 265 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 266 | <p>The LLVM representation aims to be light-weight and low-level |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 267 | while being expressive, typed, and extensible at the same time. It |
| 268 | aims to be a "universal IR" of sorts, by being at a low enough level |
| 269 | that high-level ideas may be cleanly mapped to it (similar to how |
| 270 | microprocessors are "universal IR's", allowing many source languages to |
| 271 | be mapped to them). By providing type information, LLVM can be used as |
| 272 | the target of optimizations: for example, through pointer analysis, it |
| 273 | can be proven that a C automatic variable is never accessed outside of |
| 274 | the current function... allowing it to be promoted to a simple SSA |
| 275 | value instead of a memory location.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 276 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 277 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 278 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 279 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 280 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 281 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 282 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 284 | <p>It is important to note that this document describes 'well formed' |
| 285 | LLVM assembly language. There is a difference between what the parser |
| 286 | accepts and what is considered 'well formed'. For example, the |
| 287 | following instruction is syntactically okay, but not well formed:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 288 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 289 | <div class="doc_code"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 290 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 291 | %x = <a href="#i_add">add</a> i32 1, %x |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 292 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 293 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 294 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 295 | <p>...because the definition of <tt>%x</tt> does not dominate all of |
| 296 | its uses. The LLVM infrastructure provides a verification pass that may |
| 297 | 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] | 298 | automatically run by the parser after parsing input assembly and by |
Gabor Greif | 04367bf | 2007-07-06 22:07:22 +0000 | [diff] [blame] | 299 | the optimizer before it outputs bitcode. The violations pointed out |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 300 | by the verifier pass indicate bugs in transformation passes or input to |
| 301 | the parser.</p> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 302 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 303 | |
Chris Lattner | cc68939 | 2007-10-03 17:34:29 +0000 | [diff] [blame] | 304 | <!-- Describe the typesetting conventions here. --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 305 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 306 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 307 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 308 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 309 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 310 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 311 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 312 | <p>LLVM identifiers come in two basic types: global and local. Global |
| 313 | identifiers (functions, global variables) begin with the @ character. Local |
| 314 | identifiers (register names, types) begin with the % character. Additionally, |
| 315 | there are three different formats for identifiers, for different purposes: |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 316 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 317 | <ol> |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 318 | <li>Named values are represented as a string of characters with their prefix. |
| 319 | For example, %foo, @DivisionByZero, %a.really.long.identifier. The actual |
| 320 | 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] | 321 | Identifiers which require other characters in their names can be surrounded |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 322 | with quotes. In this way, anything except a <tt>"</tt> character can |
| 323 | be used in a named value.</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 324 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 325 | <li>Unnamed values are represented as an unsigned numeric value with their |
| 326 | prefix. For example, %12, @2, %44.</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 327 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 328 | <li>Constants, which are described in a <a href="#constants">section about |
| 329 | constants</a>, below.</li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 330 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 331 | |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 332 | <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] | 333 | don't need to worry about name clashes with reserved words, and the set of |
| 334 | reserved words may be expanded in the future without penalty. Additionally, |
| 335 | unnamed identifiers allow a compiler to quickly come up with a temporary |
| 336 | variable without having to avoid symbol table conflicts.</p> |
| 337 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 338 | <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] | 339 | languages. There are keywords for different opcodes |
| 340 | ('<tt><a href="#i_add">add</a></tt>', |
| 341 | '<tt><a href="#i_bitcast">bitcast</a></tt>', |
| 342 | '<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] | 343 | 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] | 344 | and others. These reserved words cannot conflict with variable names, because |
Reid Spencer | 2c45228 | 2007-08-07 14:34:28 +0000 | [diff] [blame] | 345 | none of them start with a prefix character ('%' or '@').</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 346 | |
| 347 | <p>Here is an example of LLVM code to multiply the integer variable |
| 348 | '<tt>%X</tt>' by 8:</p> |
| 349 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 350 | <p>The easy way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 351 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 352 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 353 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 354 | %result = <a href="#i_mul">mul</a> i32 %X, 8 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 355 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 356 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 357 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 358 | <p>After strength reduction:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 359 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 360 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 361 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 362 | %result = <a href="#i_shl">shl</a> i32 %X, i8 3 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 363 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 364 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 365 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 366 | <p>And the hard way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 367 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 368 | <div class="doc_code"> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 369 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 370 | <a href="#i_add">add</a> i32 %X, %X <i>; yields {i32}:%0</i> |
| 371 | <a href="#i_add">add</a> i32 %0, %0 <i>; yields {i32}:%1</i> |
| 372 | %result = <a href="#i_add">add</a> i32 %1, %1 |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 373 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 374 | </div> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 375 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 376 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several |
| 377 | important lexical features of LLVM:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 379 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 380 | |
| 381 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end of |
| 382 | line.</li> |
| 383 | |
| 384 | <li>Unnamed temporaries are created when the result of a computation is not |
| 385 | assigned to a named value.</li> |
| 386 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 387 | <li>Unnamed temporaries are numbered sequentially</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 388 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 389 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 390 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 391 | <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] | 392 | demonstrating instructions, we will follow an instruction with a comment that |
| 393 | defines the type and name of value produced. Comments are shown in italic |
| 394 | text.</p> |
| 395 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 396 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 397 | |
| 398 | <!-- *********************************************************************** --> |
| 399 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> |
| 400 | <!-- *********************************************************************** --> |
| 401 | |
| 402 | <!-- ======================================================================= --> |
| 403 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> |
| 404 | </div> |
| 405 | |
| 406 | <div class="doc_text"> |
| 407 | |
| 408 | <p>LLVM programs are composed of "Module"s, each of which is a |
| 409 | translation unit of the input programs. Each module consists of |
| 410 | functions, global variables, and symbol table entries. Modules may be |
| 411 | combined together with the LLVM linker, which merges function (and |
| 412 | global variable) definitions, resolves forward declarations, and merges |
| 413 | symbol table entries. Here is an example of the "hello world" module:</p> |
| 414 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 415 | <div class="doc_code"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 416 | <pre><i>; Declare the string constant as a global constant...</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 417 | <a href="#identifiers">@.LC0</a> = <a href="#linkage_internal">internal</a> <a |
| 418 | 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] | 419 | |
| 420 | <i>; External declaration of the puts function</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 421 | <a href="#functionstructure">declare</a> i32 @puts(i8 *) <i>; i32(i8 *)* </i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 422 | |
| 423 | <i>; Definition of main function</i> |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 424 | define i32 @main() { <i>; i32()* </i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 425 | <i>; Convert [13x i8 ]* to i8 *...</i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 426 | %cast210 = <a |
Chris Lattner | 6c0955b | 2007-06-12 17:01:15 +0000 | [diff] [blame] | 427 | 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] | 428 | |
| 429 | <i>; Call puts function to write out the string to stdout...</i> |
| 430 | <a |
Chris Lattner | a89e5f1 | 2007-06-12 17:00:26 +0000 | [diff] [blame] | 431 | href="#i_call">call</a> i32 @puts(i8 * %cast210) <i>; i32</i> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 432 | <a |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 433 | href="#i_ret">ret</a> i32 0<br>}<br> |
| 434 | </pre> |
| 435 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 436 | |
| 437 | <p>This example is made up of a <a href="#globalvars">global variable</a> |
| 438 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" |
| 439 | function, and a <a href="#functionstructure">function definition</a> |
| 440 | for "<tt>main</tt>".</p> |
| 441 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 442 | <p>In general, a module is made up of a list of global values, |
| 443 | where both functions and global variables are global values. Global values are |
| 444 | represented by a pointer to a memory location (in this case, a pointer to an |
| 445 | array of char, and a pointer to a function), and have one of the following <a |
| 446 | href="#linkage">linkage types</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 447 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 448 | </div> |
| 449 | |
| 450 | <!-- ======================================================================= --> |
| 451 | <div class="doc_subsection"> |
| 452 | <a name="linkage">Linkage Types</a> |
| 453 | </div> |
| 454 | |
| 455 | <div class="doc_text"> |
| 456 | |
| 457 | <p> |
| 458 | All Global Variables and Functions have one of the following types of linkage: |
| 459 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 460 | |
| 461 | <dl> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 462 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 463 | <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 464 | |
| 465 | <dd>Global values with internal linkage are only directly accessible by |
| 466 | objects in the current module. In particular, linking code into a module with |
| 467 | an internal global value may cause the internal to be renamed as necessary to |
| 468 | avoid collisions. Because the symbol is internal to the module, all |
| 469 | references can be updated. This corresponds to the notion of the |
Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 470 | '<tt>static</tt>' keyword in C. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 471 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 472 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 473 | <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 474 | |
Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 475 | <dd>Globals with "<tt>linkonce</tt>" linkage are merged with other globals of |
| 476 | the same name when linkage occurs. This is typically used to implement |
| 477 | inline functions, templates, or other code which must be generated in each |
| 478 | translation unit that uses it. Unreferenced <tt>linkonce</tt> globals are |
| 479 | allowed to be discarded. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 480 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 481 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 482 | <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 483 | |
| 484 | <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage, |
| 485 | except that unreferenced <tt>weak</tt> globals may not be discarded. This is |
Chris Lattner | 4887bd8 | 2007-01-14 06:51:48 +0000 | [diff] [blame] | 486 | used for globals that may be emitted in multiple translation units, but that |
| 487 | are not guaranteed to be emitted into every translation unit that uses them. |
| 488 | One example of this are common globals in C, such as "<tt>int X;</tt>" at |
| 489 | global scope. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 490 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 491 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 492 | <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 493 | |
| 494 | <dd>"<tt>appending</tt>" linkage may only be applied to global variables of |
| 495 | pointer to array type. When two global variables with appending linkage are |
| 496 | linked together, the two global arrays are appended together. This is the |
| 497 | LLVM, typesafe, equivalent of having the system linker append together |
| 498 | "sections" with identical names when .o files are linked. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 499 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 500 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 501 | <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> |
| 502 | <dd>The semantics of this linkage follow the ELF model: the symbol is weak |
| 503 | until linked, if not linked, the symbol becomes null instead of being an |
| 504 | undefined reference. |
| 505 | </dd> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 506 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 507 | <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] | 508 | |
| 509 | <dd>If none of the above identifiers are used, the global is externally |
| 510 | visible, meaning that it participates in linkage and can be used to resolve |
| 511 | external symbol references. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 512 | </dd> |
Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 513 | </dl> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 514 | |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 515 | <p> |
| 516 | The next two types of linkage are targeted for Microsoft Windows platform |
| 517 | only. They are designed to support importing (exporting) symbols from (to) |
| 518 | DLLs. |
| 519 | </p> |
| 520 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 521 | <dl> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 522 | <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt> |
| 523 | |
| 524 | <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function |
| 525 | or variable via a global pointer to a pointer that is set up by the DLL |
| 526 | exporting the symbol. On Microsoft Windows targets, the pointer name is |
| 527 | formed by combining <code>_imp__</code> and the function or variable name. |
| 528 | </dd> |
| 529 | |
| 530 | <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt> |
| 531 | |
| 532 | <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global |
| 533 | pointer to a pointer in a DLL, so that it can be referenced with the |
| 534 | <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer |
| 535 | name is formed by combining <code>_imp__</code> and the function or variable |
| 536 | name. |
| 537 | </dd> |
| 538 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 539 | </dl> |
| 540 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 541 | <p><a name="linkage_external"></a>For example, since the "<tt>.LC0</tt>" |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 542 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" |
| 543 | variable and was linked with this one, one of the two would be renamed, |
| 544 | preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are |
| 545 | external (i.e., lacking any linkage declarations), they are accessible |
Reid Spencer | ac8d276 | 2007-01-05 00:59:10 +0000 | [diff] [blame] | 546 | outside of the current module.</p> |
| 547 | <p>It is illegal for a function <i>declaration</i> |
| 548 | to have any linkage type other than "externally visible", <tt>dllimport</tt>, |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 549 | or <tt>extern_weak</tt>.</p> |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 550 | <p>Aliases can have only <tt>external</tt>, <tt>internal</tt> and <tt>weak</tt> |
| 551 | linkages. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 552 | </div> |
| 553 | |
| 554 | <!-- ======================================================================= --> |
| 555 | <div class="doc_subsection"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 556 | <a name="callingconv">Calling Conventions</a> |
| 557 | </div> |
| 558 | |
| 559 | <div class="doc_text"> |
| 560 | |
| 561 | <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a> |
| 562 | and <a href="#i_invoke">invokes</a> can all have an optional calling convention |
| 563 | specified for the call. The calling convention of any pair of dynamic |
| 564 | caller/callee must match, or the behavior of the program is undefined. The |
| 565 | following calling conventions are supported by LLVM, and more may be added in |
| 566 | the future:</p> |
| 567 | |
| 568 | <dl> |
| 569 | <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt> |
| 570 | |
| 571 | <dd>This calling convention (the default if no other calling convention is |
| 572 | specified) matches the target C calling conventions. This calling convention |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 573 | supports varargs function calls and tolerates some mismatch in the declared |
Reid Spencer | c28d2bc | 2006-12-31 21:30:18 +0000 | [diff] [blame] | 574 | prototype and implemented declaration of the function (as does normal C). |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 575 | </dd> |
| 576 | |
| 577 | <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt> |
| 578 | |
| 579 | <dd>This calling convention attempts to make calls as fast as possible |
| 580 | (e.g. by passing things in registers). This calling convention allows the |
| 581 | target to use whatever tricks it wants to produce fast code for the target, |
Chris Lattner | 8cdc5bc | 2005-05-06 23:08:23 +0000 | [diff] [blame] | 582 | without having to conform to an externally specified ABI. Implementations of |
| 583 | this convention should allow arbitrary tail call optimization to be supported. |
| 584 | This calling convention does not support varargs and requires the prototype of |
| 585 | all callees to exactly match the prototype of the function definition. |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 586 | </dd> |
| 587 | |
| 588 | <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt> |
| 589 | |
| 590 | <dd>This calling convention attempts to make code in the caller as efficient |
| 591 | as possible under the assumption that the call is not commonly executed. As |
| 592 | such, these calls often preserve all registers so that the call does not break |
| 593 | any live ranges in the caller side. This calling convention does not support |
| 594 | varargs and requires the prototype of all callees to exactly match the |
| 595 | prototype of the function definition. |
| 596 | </dd> |
| 597 | |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 598 | <dt><b>"<tt>cc <<em>n</em>></tt>" - Numbered convention</b>:</dt> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 599 | |
| 600 | <dd>Any calling convention may be specified by number, allowing |
| 601 | target-specific calling conventions to be used. Target specific calling |
| 602 | conventions start at 64. |
| 603 | </dd> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 604 | </dl> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 605 | |
| 606 | <p>More calling conventions can be added/defined on an as-needed basis, to |
| 607 | support pascal conventions or any other well-known target-independent |
| 608 | convention.</p> |
| 609 | |
| 610 | </div> |
| 611 | |
| 612 | <!-- ======================================================================= --> |
| 613 | <div class="doc_subsection"> |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 614 | <a name="visibility">Visibility Styles</a> |
| 615 | </div> |
| 616 | |
| 617 | <div class="doc_text"> |
| 618 | |
| 619 | <p> |
| 620 | All Global Variables and Functions have one of the following visibility styles: |
| 621 | </p> |
| 622 | |
| 623 | <dl> |
| 624 | <dt><b>"<tt>default</tt>" - Default style</b>:</dt> |
| 625 | |
| 626 | <dd>On ELF, default visibility means that the declaration is visible to other |
| 627 | modules and, in shared libraries, means that the declared entity may be |
| 628 | overridden. On Darwin, default visibility means that the declaration is |
| 629 | visible to other modules. Default visibility corresponds to "external |
| 630 | linkage" in the language. |
| 631 | </dd> |
| 632 | |
| 633 | <dt><b>"<tt>hidden</tt>" - Hidden style</b>:</dt> |
| 634 | |
| 635 | <dd>Two declarations of an object with hidden visibility refer to the same |
| 636 | object if they are in the same shared object. Usually, hidden visibility |
| 637 | indicates that the symbol will not be placed into the dynamic symbol table, |
| 638 | so no other module (executable or shared library) can reference it |
| 639 | directly. |
| 640 | </dd> |
| 641 | |
Anton Korobeynikov | 6f9896f | 2007-04-29 18:35:00 +0000 | [diff] [blame] | 642 | <dt><b>"<tt>protected</tt>" - Protected style</b>:</dt> |
| 643 | |
| 644 | <dd>On ELF, protected visibility indicates that the symbol will be placed in |
| 645 | the dynamic symbol table, but that references within the defining module will |
| 646 | bind to the local symbol. That is, the symbol cannot be overridden by another |
| 647 | module. |
| 648 | </dd> |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 649 | </dl> |
| 650 | |
| 651 | </div> |
| 652 | |
| 653 | <!-- ======================================================================= --> |
| 654 | <div class="doc_subsection"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 655 | <a name="globalvars">Global Variables</a> |
| 656 | </div> |
| 657 | |
| 658 | <div class="doc_text"> |
| 659 | |
Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 660 | <p>Global variables define regions of memory allocated at compilation time |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 661 | instead of run-time. Global variables may optionally be initialized, may have |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 662 | an explicit section to be placed in, and may have an optional explicit alignment |
| 663 | specified. A variable may be defined as "thread_local", which means that it |
| 664 | will not be shared by threads (each thread will have a separated copy of the |
| 665 | variable). A variable may be defined as a global "constant," which indicates |
| 666 | 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] | 667 | optimization, allowing the global data to be placed in the read-only section of |
| 668 | an executable, etc). Note that variables that need runtime initialization |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 669 | 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] | 670 | |
| 671 | <p> |
| 672 | LLVM explicitly allows <em>declarations</em> of global variables to be marked |
| 673 | constant, even if the final definition of the global is not. This capability |
| 674 | can be used to enable slightly better optimization of the program, but requires |
| 675 | the language definition to guarantee that optimizations based on the |
| 676 | 'constantness' are valid for the translation units that do not include the |
| 677 | definition. |
| 678 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 679 | |
| 680 | <p>As SSA values, global variables define pointer values that are in |
| 681 | scope (i.e. they dominate) all basic blocks in the program. Global |
| 682 | variables always define a pointer to their "content" type because they |
| 683 | describe a region of memory, and all memory objects in LLVM are |
| 684 | accessed through pointers.</p> |
| 685 | |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 686 | <p>A global variable may be declared to reside in a target-specifc numbered |
| 687 | address space. For targets that support them, address spaces may affect how |
| 688 | optimizations are performed and/or what target instructions are used to access |
Christopher Lamb | d49e18d | 2007-12-12 08:44:39 +0000 | [diff] [blame] | 689 | the variable. The default address space is zero. The address space qualifier |
| 690 | must precede any other attributes.</p> |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 691 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 692 | <p>LLVM allows an explicit section to be specified for globals. If the target |
| 693 | supports it, it will emit globals to the section specified.</p> |
| 694 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 695 | <p>An explicit alignment may be specified for a global. If not present, or if |
| 696 | the alignment is set to zero, the alignment of the global is set by the target |
| 697 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 698 | global is forced to have at least that much alignment. All alignments must be |
| 699 | a power of 2.</p> |
| 700 | |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 701 | <p>For example, the following defines a global in a numbered address space with |
| 702 | an initializer, section, and alignment:</p> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 703 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 704 | <div class="doc_code"> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 705 | <pre> |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 706 | @G = constant float 1.0 addrspace(5), section "foo", align 4 |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 707 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 708 | </div> |
Chris Lattner | 68027ea | 2007-01-14 00:27:09 +0000 | [diff] [blame] | 709 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 710 | </div> |
| 711 | |
| 712 | |
| 713 | <!-- ======================================================================= --> |
| 714 | <div class="doc_subsection"> |
| 715 | <a name="functionstructure">Functions</a> |
| 716 | </div> |
| 717 | |
| 718 | <div class="doc_text"> |
| 719 | |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 720 | <p>LLVM function definitions consist of the "<tt>define</tt>" keyord, |
| 721 | an optional <a href="#linkage">linkage type</a>, an optional |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 722 | <a href="#visibility">visibility style</a>, an optional |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 723 | <a href="#callingconv">calling convention</a>, a return type, an optional |
| 724 | <a href="#paramattrs">parameter attribute</a> for the return type, a function |
| 725 | name, a (possibly empty) argument list (each with optional |
Anton Korobeynikov | 8cea37b | 2007-01-23 12:35:46 +0000 | [diff] [blame] | 726 | <a href="#paramattrs">parameter attributes</a>), an optional section, an |
Gordon Henriksen | e754abe | 2007-12-10 03:30:21 +0000 | [diff] [blame] | 727 | optional alignment, an optional <a href="#gc">garbage collector name</a>, an |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 728 | 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] | 729 | |
| 730 | LLVM function declarations consist of the "<tt>declare</tt>" keyword, an |
| 731 | optional <a href="#linkage">linkage type</a>, an optional |
| 732 | <a href="#visibility">visibility style</a>, an optional |
| 733 | <a href="#callingconv">calling convention</a>, a return type, an optional |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 734 | <a href="#paramattrs">parameter attribute</a> for the return type, a function |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 735 | 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] | 736 | <a href="#gc">garbage collector name</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 737 | |
| 738 | <p>A function definition contains a list of basic blocks, forming the CFG for |
| 739 | the function. Each basic block may optionally start with a label (giving the |
| 740 | basic block a symbol table entry), contains a list of instructions, and ends |
| 741 | with a <a href="#terminators">terminator</a> instruction (such as a branch or |
| 742 | function return).</p> |
| 743 | |
Chris Lattner | 4a3c901 | 2007-06-08 16:52:14 +0000 | [diff] [blame] | 744 | <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] | 745 | executed on entrance to the function, and it is not allowed to have predecessor |
| 746 | basic blocks (i.e. there can not be any branches to the entry block of a |
| 747 | function). Because the block can have no predecessors, it also cannot have any |
| 748 | <a href="#i_phi">PHI nodes</a>.</p> |
| 749 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 750 | <p>LLVM allows an explicit section to be specified for functions. If the target |
| 751 | supports it, it will emit functions to the section specified.</p> |
| 752 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 753 | <p>An explicit alignment may be specified for a function. If not present, or if |
| 754 | the alignment is set to zero, the alignment of the function is set by the target |
| 755 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 756 | function is forced to have at least that much alignment. All alignments must be |
| 757 | a power of 2.</p> |
| 758 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 759 | </div> |
| 760 | |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 761 | |
| 762 | <!-- ======================================================================= --> |
| 763 | <div class="doc_subsection"> |
| 764 | <a name="aliasstructure">Aliases</a> |
| 765 | </div> |
| 766 | <div class="doc_text"> |
| 767 | <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] | 768 | function, global variable, another alias or bitcast of global value). Aliases |
| 769 | may have an optional <a href="#linkage">linkage type</a>, and an |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 770 | optional <a href="#visibility">visibility style</a>.</p> |
| 771 | |
| 772 | <h5>Syntax:</h5> |
| 773 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 774 | <div class="doc_code"> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 775 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 776 | @<Name> = [Linkage] [Visibility] alias <AliaseeTy> @<Aliasee> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 777 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 778 | </div> |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 779 | |
| 780 | </div> |
| 781 | |
| 782 | |
| 783 | |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 784 | <!-- ======================================================================= --> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 785 | <div class="doc_subsection"><a name="paramattrs">Parameter Attributes</a></div> |
| 786 | <div class="doc_text"> |
| 787 | <p>The return type and each parameter of a function type may have a set of |
| 788 | <i>parameter attributes</i> associated with them. Parameter attributes are |
| 789 | used to communicate additional information about the result or parameters of |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 790 | a function. Parameter attributes are considered to be part of the function, |
| 791 | not of the function type, so functions with different parameter attributes |
| 792 | can have the same function type.</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 793 | |
Reid Spencer | 950e9f8 | 2007-01-15 18:27:39 +0000 | [diff] [blame] | 794 | <p>Parameter attributes are simple keywords that follow the type specified. If |
| 795 | multiple parameter attributes are needed, they are space separated. For |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 796 | example:</p> |
| 797 | |
| 798 | <div class="doc_code"> |
| 799 | <pre> |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 800 | declare i32 @printf(i8* noalias , ...) nounwind |
| 801 | declare i32 @atoi(i8*) nounwind readonly |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 802 | </pre> |
| 803 | </div> |
| 804 | |
Duncan Sands | dc02467 | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 805 | <p>Note that any attributes for the function result (<tt>nounwind</tt>, |
| 806 | <tt>readonly</tt>) come immediately after the argument list.</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 807 | |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 808 | <p>Currently, only the following parameter attributes are defined:</p> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 809 | <dl> |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 810 | <dt><tt>zeroext</tt></dt> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 811 | <dd>This indicates that the parameter should be zero extended just before |
| 812 | a call to this function.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 813 | |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 814 | <dt><tt>signext</tt></dt> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 815 | <dd>This indicates that the parameter should be sign extended just before |
| 816 | a call to this function.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 817 | |
Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 818 | <dt><tt>inreg</tt></dt> |
| 819 | <dd>This indicates that the parameter should be placed in register (if |
Anton Korobeynikov | 66a8c8c | 2007-01-28 15:27:21 +0000 | [diff] [blame] | 820 | possible) during assembling function call. Support for this attribute is |
| 821 | target-specific</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 822 | |
| 823 | <dt><tt>byval</tt></dt> |
Chris Lattner | 0747baa | 2008-01-15 04:34:22 +0000 | [diff] [blame] | 824 | <dd>This indicates that the pointer parameter should really be passed by |
| 825 | value to the function. The attribute implies that a hidden copy of the |
| 826 | pointee is made between the caller and the callee, so the callee is unable |
| 827 | to modify the value in the callee. This attribute is only valid on llvm |
| 828 | pointer arguments. It is generally used to pass structs and arrays by |
| 829 | value, but is also valid on scalars (even though this is silly).</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 830 | |
Anton Korobeynikov | 34d6dea | 2007-01-28 14:30:45 +0000 | [diff] [blame] | 831 | <dt><tt>sret</tt></dt> |
Duncan Sands | e26dec6 | 2008-02-18 04:19:38 +0000 | [diff] [blame] | 832 | <dd>This indicates that the pointer parameter specifies the address of a |
| 833 | structure that is the return value of the function in the source program. |
Duncan Sands | b7f0c08 | 2008-03-17 12:17:41 +0000 | [diff] [blame] | 834 | Loads and stores to the structure are assumed not to trap. |
Duncan Sands | e26dec6 | 2008-02-18 04:19:38 +0000 | [diff] [blame] | 835 | May only be applied to the first parameter.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 836 | |
Zhou Sheng | febca34 | 2007-06-05 05:28:26 +0000 | [diff] [blame] | 837 | <dt><tt>noalias</tt></dt> |
Owen Anderson | 117bbd3 | 2008-02-18 04:09:01 +0000 | [diff] [blame] | 838 | <dd>This indicates that the parameter does not alias any global or any other |
| 839 | parameter. The caller is responsible for ensuring that this is the case, |
| 840 | usually by placing the value in a stack allocation.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 841 | |
Reid Spencer | 2dc5201 | 2007-03-22 02:18:56 +0000 | [diff] [blame] | 842 | <dt><tt>noreturn</tt></dt> |
| 843 | <dd>This function attribute indicates that the function never returns. This |
| 844 | indicates to LLVM that every call to this function should be treated as if |
| 845 | an <tt>unreachable</tt> instruction immediately followed the call.</dd> |
Chris Lattner | 47507de | 2008-01-11 06:20:47 +0000 | [diff] [blame] | 846 | |
Reid Spencer | 6760612 | 2007-03-22 02:02:11 +0000 | [diff] [blame] | 847 | <dt><tt>nounwind</tt></dt> |
Duncan Sands | b7f0c08 | 2008-03-17 12:17:41 +0000 | [diff] [blame] | 848 | <dd>This function attribute indicates that no exceptions unwind out of the |
| 849 | function. Usually this is because the function makes no use of exceptions, |
| 850 | but it may also be that the function catches any exceptions thrown when |
| 851 | executing it.</dd> |
| 852 | |
Duncan Sands | 50f19f5 | 2007-07-27 19:57:41 +0000 | [diff] [blame] | 853 | <dt><tt>nest</tt></dt> |
| 854 | <dd>This indicates that the parameter can be excised using the |
| 855 | <a href="#int_trampoline">trampoline intrinsics</a>.</dd> |
Duncan Sands | ed4a2f1 | 2007-11-22 20:23:04 +0000 | [diff] [blame] | 856 | <dt><tt>readonly</tt></dt> |
Duncan Sands | f04d584 | 2007-11-14 21:14:02 +0000 | [diff] [blame] | 857 | <dd>This function attribute indicates that the function has no side-effects |
Duncan Sands | ed4a2f1 | 2007-11-22 20:23:04 +0000 | [diff] [blame] | 858 | except for producing a return value or throwing an exception. The value |
| 859 | returned must only depend on the function arguments and/or global variables. |
| 860 | It may use values obtained by dereferencing pointers.</dd> |
| 861 | <dt><tt>readnone</tt></dt> |
| 862 | <dd>A <tt>readnone</tt> function has the same restrictions as a <tt>readonly</tt> |
Duncan Sands | f04d584 | 2007-11-14 21:14:02 +0000 | [diff] [blame] | 863 | function, but in addition it is not allowed to dereference any pointer arguments |
| 864 | or global variables. |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 865 | </dl> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 866 | |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 867 | </div> |
| 868 | |
| 869 | <!-- ======================================================================= --> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 870 | <div class="doc_subsection"> |
Gordon Henriksen | 80a75bf | 2007-12-10 03:18:06 +0000 | [diff] [blame] | 871 | <a name="gc">Garbage Collector Names</a> |
| 872 | </div> |
| 873 | |
| 874 | <div class="doc_text"> |
| 875 | <p>Each function may specify a garbage collector name, which is simply a |
| 876 | string.</p> |
| 877 | |
| 878 | <div class="doc_code"><pre |
| 879 | >define void @f() gc "name" { ...</pre></div> |
| 880 | |
| 881 | <p>The compiler declares the supported values of <i>name</i>. Specifying a |
| 882 | collector which will cause the compiler to alter its output in order to support |
| 883 | the named garbage collection algorithm.</p> |
| 884 | </div> |
| 885 | |
| 886 | <!-- ======================================================================= --> |
| 887 | <div class="doc_subsection"> |
Chris Lattner | 1eeeb0c | 2006-04-08 04:40:53 +0000 | [diff] [blame] | 888 | <a name="moduleasm">Module-Level Inline Assembly</a> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 889 | </div> |
| 890 | |
| 891 | <div class="doc_text"> |
| 892 | <p> |
| 893 | Modules may contain "module-level inline asm" blocks, which corresponds to the |
| 894 | GCC "file scope inline asm" blocks. These blocks are internally concatenated by |
| 895 | LLVM and treated as a single unit, but may be separated in the .ll file if |
| 896 | desired. The syntax is very simple: |
| 897 | </p> |
| 898 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 899 | <div class="doc_code"> |
| 900 | <pre> |
| 901 | module asm "inline asm code goes here" |
| 902 | module asm "more can go here" |
| 903 | </pre> |
| 904 | </div> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 905 | |
| 906 | <p>The strings can contain any character by escaping non-printable characters. |
| 907 | The escape sequence used is simply "\xx" where "xx" is the two digit hex code |
| 908 | for the number. |
| 909 | </p> |
| 910 | |
| 911 | <p> |
| 912 | The inline asm code is simply printed to the machine code .s file when |
| 913 | assembly code is generated. |
| 914 | </p> |
| 915 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 916 | |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 917 | <!-- ======================================================================= --> |
| 918 | <div class="doc_subsection"> |
| 919 | <a name="datalayout">Data Layout</a> |
| 920 | </div> |
| 921 | |
| 922 | <div class="doc_text"> |
| 923 | <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] | 924 | data is to be laid out in memory. The syntax for the data layout is simply:</p> |
| 925 | <pre> target datalayout = "<i>layout specification</i>"</pre> |
| 926 | <p>The <i>layout specification</i> consists of a list of specifications |
| 927 | separated by the minus sign character ('-'). Each specification starts with a |
| 928 | letter and may include other information after the letter to define some |
| 929 | aspect of the data layout. The specifications accepted are as follows: </p> |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 930 | <dl> |
| 931 | <dt><tt>E</tt></dt> |
| 932 | <dd>Specifies that the target lays out data in big-endian form. That is, the |
| 933 | bits with the most significance have the lowest address location.</dd> |
| 934 | <dt><tt>e</tt></dt> |
| 935 | <dd>Specifies that hte target lays out data in little-endian form. That is, |
| 936 | the bits with the least significance have the lowest address location.</dd> |
| 937 | <dt><tt>p:<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 938 | <dd>This specifies the <i>size</i> of a pointer and its <i>abi</i> and |
| 939 | <i>preferred</i> alignments. All sizes are in bits. Specifying the <i>pref</i> |
| 940 | alignment is optional. If omitted, the preceding <tt>:</tt> should be omitted |
| 941 | too.</dd> |
| 942 | <dt><tt>i<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 943 | <dd>This specifies the alignment for an integer type of a given bit |
| 944 | <i>size</i>. The value of <i>size</i> must be in the range [1,2^23).</dd> |
| 945 | <dt><tt>v<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 946 | <dd>This specifies the alignment for a vector type of a given bit |
| 947 | <i>size</i>.</dd> |
| 948 | <dt><tt>f<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 949 | <dd>This specifies the alignment for a floating point type of a given bit |
| 950 | <i>size</i>. The value of <i>size</i> must be either 32 (float) or 64 |
| 951 | (double).</dd> |
| 952 | <dt><tt>a<i>size</i>:<i>abi</i>:<i>pref</i></tt></dt> |
| 953 | <dd>This specifies the alignment for an aggregate type of a given bit |
| 954 | <i>size</i>.</dd> |
| 955 | </dl> |
| 956 | <p>When constructing the data layout for a given target, LLVM starts with a |
| 957 | default set of specifications which are then (possibly) overriden by the |
| 958 | specifications in the <tt>datalayout</tt> keyword. The default specifications |
| 959 | are given in this list:</p> |
| 960 | <ul> |
| 961 | <li><tt>E</tt> - big endian</li> |
| 962 | <li><tt>p:32:64:64</tt> - 32-bit pointers with 64-bit alignment</li> |
| 963 | <li><tt>i1:8:8</tt> - i1 is 8-bit (byte) aligned</li> |
| 964 | <li><tt>i8:8:8</tt> - i8 is 8-bit (byte) aligned</li> |
| 965 | <li><tt>i16:16:16</tt> - i16 is 16-bit aligned</li> |
| 966 | <li><tt>i32:32:32</tt> - i32 is 32-bit aligned</li> |
| 967 | <li><tt>i64:32:64</tt> - i64 has abi alignment of 32-bits but preferred |
| 968 | alignment of 64-bits</li> |
| 969 | <li><tt>f32:32:32</tt> - float is 32-bit aligned</li> |
| 970 | <li><tt>f64:64:64</tt> - double is 64-bit aligned</li> |
| 971 | <li><tt>v64:64:64</tt> - 64-bit vector is 64-bit aligned</li> |
| 972 | <li><tt>v128:128:128</tt> - 128-bit vector is 128-bit aligned</li> |
| 973 | <li><tt>a0:0:1</tt> - aggregates are 8-bit aligned</li> |
| 974 | </ul> |
| 975 | <p>When llvm is determining the alignment for a given type, it uses the |
| 976 | following rules: |
| 977 | <ol> |
| 978 | <li>If the type sought is an exact match for one of the specifications, that |
| 979 | specification is used.</li> |
| 980 | <li>If no match is found, and the type sought is an integer type, then the |
| 981 | smallest integer type that is larger than the bitwidth of the sought type is |
| 982 | used. If none of the specifications are larger than the bitwidth then the the |
| 983 | largest integer type is used. For example, given the default specifications |
| 984 | above, the i7 type will use the alignment of i8 (next largest) while both |
| 985 | i65 and i256 will use the alignment of i64 (largest specified).</li> |
| 986 | <li>If no match is found, and the type sought is a vector type, then the |
| 987 | largest vector type that is smaller than the sought vector type will be used |
| 988 | as a fall back. This happens because <128 x double> can be implemented in |
| 989 | terms of 64 <2 x double>, for example.</li> |
| 990 | </ol> |
| 991 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 992 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 993 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 994 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> |
| 995 | <!-- *********************************************************************** --> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 996 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 997 | <div class="doc_text"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 998 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 999 | <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] | 1000 | intermediate representation. Being typed enables a number of |
| 1001 | optimizations to be performed on the IR directly, without having to do |
| 1002 | extra analyses on the side before the transformation. A strong type |
| 1003 | system makes it easier to read the generated code and enables novel |
| 1004 | analyses and transformations that are not feasible to perform on normal |
| 1005 | three address code representations.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 1006 | |
| 1007 | </div> |
| 1008 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1009 | <!-- ======================================================================= --> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1010 | <div class="doc_subsection"> <a name="t_classifications">Type |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1011 | Classifications</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1012 | <div class="doc_text"> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1013 | <p>The types fall into a few useful |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1014 | classifications:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1015 | |
| 1016 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1017 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1018 | <tr><th>Classification</th><th>Types</th></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1019 | <tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1020 | <td><a href="#t_integer">integer</a></td> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1021 | <td><tt>i1, i2, i3, ... i8, ... i16, ... i32, ... i64, ... </tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1022 | </tr> |
| 1023 | <tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1024 | <td><a href="#t_floating">floating point</a></td> |
| 1025 | <td><tt>float, double, x86_fp80, fp128, ppc_fp128</tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1026 | </tr> |
| 1027 | <tr> |
| 1028 | <td><a name="t_firstclass">first class</a></td> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1029 | <td><a href="#t_integer">integer</a>, |
| 1030 | <a href="#t_floating">floating point</a>, |
| 1031 | <a href="#t_pointer">pointer</a>, |
| 1032 | <a href="#t_vector">vector</a> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1033 | </td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1034 | </tr> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1035 | <tr> |
| 1036 | <td><a href="#t_primitive">primitive</a></td> |
| 1037 | <td><a href="#t_label">label</a>, |
| 1038 | <a href="#t_void">void</a>, |
| 1039 | <a href="#t_integer">integer</a>, |
| 1040 | <a href="#t_floating">floating point</a>.</td> |
| 1041 | </tr> |
| 1042 | <tr> |
| 1043 | <td><a href="#t_derived">derived</a></td> |
| 1044 | <td><a href="#t_integer">integer</a>, |
| 1045 | <a href="#t_array">array</a>, |
| 1046 | <a href="#t_function">function</a>, |
| 1047 | <a href="#t_pointer">pointer</a>, |
| 1048 | <a href="#t_struct">structure</a>, |
| 1049 | <a href="#t_pstruct">packed structure</a>, |
| 1050 | <a href="#t_vector">vector</a>, |
| 1051 | <a href="#t_opaque">opaque</a>. |
| 1052 | </tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1053 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1054 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1055 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1056 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the |
| 1057 | most important. Values of these types are the only ones which can be |
| 1058 | produced by instructions, passed as arguments, or used as operands to |
| 1059 | instructions. This means that all structures and arrays must be |
| 1060 | manipulated either by pointer or by component.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1061 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1062 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1063 | <!-- ======================================================================= --> |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1064 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> |
Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1065 | |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1066 | <div class="doc_text"> |
| 1067 | <p>The primitive types are the fundamental building blocks of the LLVM |
| 1068 | system.</p> |
| 1069 | |
Chris Lattner | 8f8c7b7 | 2008-01-04 04:34:14 +0000 | [diff] [blame] | 1070 | </div> |
| 1071 | |
Chris Lattner | 4f69f46 | 2008-01-04 04:32:38 +0000 | [diff] [blame] | 1072 | <!-- _______________________________________________________________________ --> |
| 1073 | <div class="doc_subsubsection"> <a name="t_floating">Floating Point Types</a> </div> |
| 1074 | |
| 1075 | <div class="doc_text"> |
| 1076 | <table> |
| 1077 | <tbody> |
| 1078 | <tr><th>Type</th><th>Description</th></tr> |
| 1079 | <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr> |
| 1080 | <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr> |
| 1081 | <tr><td><tt>fp128</tt></td><td>128-bit floating point value (112-bit mantissa)</td></tr> |
| 1082 | <tr><td><tt>x86_fp80</tt></td><td>80-bit floating point value (X87)</td></tr> |
| 1083 | <tr><td><tt>ppc_fp128</tt></td><td>128-bit floating point value (two 64-bits)</td></tr> |
| 1084 | </tbody> |
| 1085 | </table> |
| 1086 | </div> |
| 1087 | |
| 1088 | <!-- _______________________________________________________________________ --> |
| 1089 | <div class="doc_subsubsection"> <a name="t_void">Void Type</a> </div> |
| 1090 | |
| 1091 | <div class="doc_text"> |
| 1092 | <h5>Overview:</h5> |
| 1093 | <p>The void type does not represent any value and has no size.</p> |
| 1094 | |
| 1095 | <h5>Syntax:</h5> |
| 1096 | |
| 1097 | <pre> |
| 1098 | void |
| 1099 | </pre> |
| 1100 | </div> |
| 1101 | |
| 1102 | <!-- _______________________________________________________________________ --> |
| 1103 | <div class="doc_subsubsection"> <a name="t_label">Label Type</a> </div> |
| 1104 | |
| 1105 | <div class="doc_text"> |
| 1106 | <h5>Overview:</h5> |
| 1107 | <p>The label type represents code labels.</p> |
| 1108 | |
| 1109 | <h5>Syntax:</h5> |
| 1110 | |
| 1111 | <pre> |
| 1112 | label |
| 1113 | </pre> |
| 1114 | </div> |
| 1115 | |
| 1116 | |
| 1117 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1118 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1119 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1120 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1121 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1122 | <p>The real power in LLVM comes from the derived types in the system. |
| 1123 | This is what allows a programmer to represent arrays, functions, |
| 1124 | pointers, and other useful types. Note that these derived types may be |
| 1125 | 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] | 1126 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1127 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1128 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1129 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1130 | <div class="doc_subsubsection"> <a name="t_integer">Integer Type</a> </div> |
| 1131 | |
| 1132 | <div class="doc_text"> |
| 1133 | |
| 1134 | <h5>Overview:</h5> |
| 1135 | <p>The integer type is a very simple derived type that simply specifies an |
| 1136 | arbitrary bit width for the integer type desired. Any bit width from 1 bit to |
| 1137 | 2^23-1 (about 8 million) can be specified.</p> |
| 1138 | |
| 1139 | <h5>Syntax:</h5> |
| 1140 | |
| 1141 | <pre> |
| 1142 | iN |
| 1143 | </pre> |
| 1144 | |
| 1145 | <p>The number of bits the integer will occupy is specified by the <tt>N</tt> |
| 1146 | value.</p> |
| 1147 | |
| 1148 | <h5>Examples:</h5> |
| 1149 | <table class="layout"> |
Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 1150 | <tbody> |
| 1151 | <tr> |
| 1152 | <td><tt>i1</tt></td> |
| 1153 | <td>a single-bit integer.</td> |
| 1154 | </tr><tr> |
| 1155 | <td><tt>i32</tt></td> |
| 1156 | <td>a 32-bit integer.</td> |
| 1157 | </tr><tr> |
| 1158 | <td><tt>i1942652</tt></td> |
| 1159 | <td>a really big integer of over 1 million bits.</td> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1160 | </tr> |
Chris Lattner | b9488a6 | 2007-12-18 06:18:21 +0000 | [diff] [blame] | 1161 | </tbody> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1162 | </table> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1163 | </div> |
Reid Spencer | 2b91631 | 2007-05-16 18:44:01 +0000 | [diff] [blame] | 1164 | |
| 1165 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1166 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1167 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1168 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1169 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1170 | <h5>Overview:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1171 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1172 | <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] | 1173 | sequentially in memory. The array type requires a size (number of |
| 1174 | elements) and an underlying data type.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1175 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1176 | <h5>Syntax:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1177 | |
| 1178 | <pre> |
| 1179 | [<# elements> x <elementtype>] |
| 1180 | </pre> |
| 1181 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1182 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1183 | be any type with a size.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1184 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1185 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1186 | <table class="layout"> |
| 1187 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1188 | <td class="left"><tt>[40 x i32]</tt></td> |
| 1189 | <td class="left">Array of 40 32-bit integer values.</td> |
| 1190 | </tr> |
| 1191 | <tr class="layout"> |
| 1192 | <td class="left"><tt>[41 x i32]</tt></td> |
| 1193 | <td class="left">Array of 41 32-bit integer values.</td> |
| 1194 | </tr> |
| 1195 | <tr class="layout"> |
| 1196 | <td class="left"><tt>[4 x i8]</tt></td> |
| 1197 | <td class="left">Array of 4 8-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1198 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1199 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1200 | <p>Here are some examples of multidimensional arrays:</p> |
| 1201 | <table class="layout"> |
| 1202 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1203 | <td class="left"><tt>[3 x [4 x i32]]</tt></td> |
| 1204 | <td class="left">3x4 array of 32-bit integer values.</td> |
| 1205 | </tr> |
| 1206 | <tr class="layout"> |
| 1207 | <td class="left"><tt>[12 x [10 x float]]</tt></td> |
| 1208 | <td class="left">12x10 array of single precision floating point values.</td> |
| 1209 | </tr> |
| 1210 | <tr class="layout"> |
| 1211 | <td class="left"><tt>[2 x [3 x [4 x i16]]]</tt></td> |
| 1212 | <td class="left">2x3x4 array of 16-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1213 | </tr> |
| 1214 | </table> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1215 | |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1216 | <p>Note that 'variable sized arrays' can be implemented in LLVM with a zero |
| 1217 | 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] | 1218 | LLVM (e.g. it is illegal to access the 5th element of a 3 element array). |
| 1219 | As a special case, however, zero length arrays are recognized to be variable |
| 1220 | length. This allows implementation of 'pascal style arrays' with the LLVM |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1221 | type "{ i32, [0 x float]}", for example.</p> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 1222 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1223 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1224 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1225 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1226 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1227 | <div class="doc_text"> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1228 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1229 | <h5>Overview:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1230 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1231 | <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] | 1232 | 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] | 1233 | 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] | 1234 | 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] | 1235 | class types, and the struct must have at least one element.</p> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1236 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1237 | <h5>Syntax:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1238 | |
| 1239 | <pre> |
| 1240 | <returntype list> (<parameter list>) |
| 1241 | </pre> |
| 1242 | |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1243 | <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] | 1244 | specifiers. Optionally, the parameter list may include a type <tt>...</tt>, |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1245 | which indicates that the function takes a variable number of arguments. |
| 1246 | Variable argument functions can access their arguments with the <a |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1247 | href="#int_varargs">variable argument handling intrinsic</a> functions. |
| 1248 | '<tt><returntype list></tt>' is a comma-separated list of |
| 1249 | <a href="#t_firstclass">first class</a> type specifiers.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1250 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1251 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1252 | <table class="layout"> |
| 1253 | <tr class="layout"> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1254 | <td class="left"><tt>i32 (i32)</tt></td> |
| 1255 | <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] | 1256 | </td> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1257 | </tr><tr class="layout"> |
Reid Spencer | 9445e9a | 2007-07-19 23:13:04 +0000 | [diff] [blame] | 1258 | <td class="left"><tt>float (i16 signext, i32 *) * |
Reid Spencer | f17a0b7 | 2006-12-31 07:20:23 +0000 | [diff] [blame] | 1259 | </tt></td> |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1260 | <td class="left"><a href="#t_pointer">Pointer</a> to a function that takes |
| 1261 | an <tt>i16</tt> that should be sign extended and a |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1262 | <a href="#t_pointer">pointer</a> to <tt>i32</tt>, returning |
Reid Spencer | 92f8230 | 2006-12-31 07:18:34 +0000 | [diff] [blame] | 1263 | <tt>float</tt>. |
| 1264 | </td> |
| 1265 | </tr><tr class="layout"> |
| 1266 | <td class="left"><tt>i32 (i8*, ...)</tt></td> |
| 1267 | <td class="left">A vararg function that takes at least one |
Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1268 | <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] | 1269 | which returns an integer. This is the signature for <tt>printf</tt> in |
| 1270 | LLVM. |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1271 | </td> |
Devang Patel | a582f40 | 2008-03-24 05:35:41 +0000 | [diff] [blame] | 1272 | </tr><tr class="layout"> |
| 1273 | <td class="left"><tt>{i32, i32} (i32)</tt></td> |
Devang Patel | 3a5bff8 | 2008-03-24 18:10:52 +0000 | [diff] [blame] | 1274 | <td class="left">A function taking an <tt>i32></tt>, returning two |
| 1275 | <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] | 1276 | </td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1277 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1278 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1279 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1280 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1281 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1282 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1283 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1284 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1285 | <p>The structure type is used to represent a collection of data members |
| 1286 | together in memory. The packing of the field types is defined to match |
| 1287 | the ABI of the underlying processor. The elements of a structure may |
| 1288 | be any type that has a size.</p> |
| 1289 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 1290 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 1291 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 1292 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1293 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1294 | <pre> { <type list> }<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1295 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1296 | <table class="layout"> |
| 1297 | <tr class="layout"> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1298 | <td class="left"><tt>{ i32, i32, i32 }</tt></td> |
| 1299 | <td class="left">A triple of three <tt>i32</tt> values</td> |
| 1300 | </tr><tr class="layout"> |
| 1301 | <td class="left"><tt>{ float, i32 (i32) * }</tt></td> |
| 1302 | <td class="left">A pair, where the first element is a <tt>float</tt> and the |
| 1303 | second element is a <a href="#t_pointer">pointer</a> to a |
| 1304 | <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning |
| 1305 | an <tt>i32</tt>.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1306 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1307 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1308 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1309 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1310 | <!-- _______________________________________________________________________ --> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1311 | <div class="doc_subsubsection"> <a name="t_pstruct">Packed Structure Type</a> |
| 1312 | </div> |
| 1313 | <div class="doc_text"> |
| 1314 | <h5>Overview:</h5> |
| 1315 | <p>The packed structure type is used to represent a collection of data members |
| 1316 | together in memory. There is no padding between fields. Further, the alignment |
| 1317 | of a packed structure is 1 byte. The elements of a packed structure may |
| 1318 | be any type that has a size.</p> |
| 1319 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 1320 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 1321 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 1322 | instruction.</p> |
| 1323 | <h5>Syntax:</h5> |
| 1324 | <pre> < { <type list> } > <br></pre> |
| 1325 | <h5>Examples:</h5> |
| 1326 | <table class="layout"> |
| 1327 | <tr class="layout"> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1328 | <td class="left"><tt>< { i32, i32, i32 } ></tt></td> |
| 1329 | <td class="left">A triple of three <tt>i32</tt> values</td> |
| 1330 | </tr><tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1331 | <td class="left"><tt>< { float, i32 (i32)* } ></tt></td> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1332 | <td class="left">A pair, where the first element is a <tt>float</tt> and the |
| 1333 | second element is a <a href="#t_pointer">pointer</a> to a |
| 1334 | <a href="#t_function">function</a> that takes an <tt>i32</tt>, returning |
| 1335 | an <tt>i32</tt>.</td> |
Andrew Lenharth | 75e1068 | 2006-12-08 17:13:00 +0000 | [diff] [blame] | 1336 | </tr> |
| 1337 | </table> |
| 1338 | </div> |
| 1339 | |
| 1340 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1341 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1342 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1343 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1344 | <p>As in many languages, the pointer type represents a pointer or |
Christopher Lamb | 284d992 | 2007-12-11 09:31:00 +0000 | [diff] [blame] | 1345 | reference to another object, which must live in memory. Pointer types may have |
| 1346 | an optional address space attribute defining the target-specific numbered |
| 1347 | address space where the pointed-to object resides. The default address space is |
| 1348 | zero.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1349 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1350 | <pre> <type> *<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1351 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1352 | <table class="layout"> |
| 1353 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1354 | <td class="left"><tt>[4x i32]*</tt></td> |
| 1355 | <td class="left">A <a href="#t_pointer">pointer</a> to <a |
| 1356 | href="#t_array">array</a> of four <tt>i32</tt> values.</td> |
| 1357 | </tr> |
| 1358 | <tr class="layout"> |
| 1359 | <td class="left"><tt>i32 (i32 *) *</tt></td> |
| 1360 | <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] | 1361 | 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] | 1362 | <tt>i32</tt>.</td> |
| 1363 | </tr> |
| 1364 | <tr class="layout"> |
| 1365 | <td class="left"><tt>i32 addrspace(5)*</tt></td> |
| 1366 | <td class="left">A <a href="#t_pointer">pointer</a> to an <tt>i32</tt> value |
| 1367 | that resides in address space #5.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1368 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1369 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1370 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1371 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1372 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1373 | <div class="doc_subsubsection"> <a name="t_vector">Vector Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1374 | <div class="doc_text"> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1375 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1376 | <h5>Overview:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1377 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1378 | <p>A vector type is a simple derived type that represents a vector |
| 1379 | of elements. Vector types are used when multiple primitive data |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1380 | are operated in parallel using a single instruction (SIMD). |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1381 | A vector type requires a size (number of |
Chris Lattner | b8d172f | 2005-11-10 01:44:22 +0000 | [diff] [blame] | 1382 | elements) and an underlying primitive data type. Vectors must have a power |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1383 | of two length (1, 2, 4, 8, 16 ...). Vector types are |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1384 | considered <a href="#t_firstclass">first class</a>.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1385 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1386 | <h5>Syntax:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1387 | |
| 1388 | <pre> |
| 1389 | < <# elements> x <elementtype> > |
| 1390 | </pre> |
| 1391 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1392 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 1393 | be any integer or floating point type.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1394 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1395 | <h5>Examples:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1396 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1397 | <table class="layout"> |
| 1398 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1399 | <td class="left"><tt><4 x i32></tt></td> |
| 1400 | <td class="left">Vector of 4 32-bit integer values.</td> |
| 1401 | </tr> |
| 1402 | <tr class="layout"> |
| 1403 | <td class="left"><tt><8 x float></tt></td> |
| 1404 | <td class="left">Vector of 8 32-bit floating-point values.</td> |
| 1405 | </tr> |
| 1406 | <tr class="layout"> |
| 1407 | <td class="left"><tt><2 x i64></tt></td> |
| 1408 | <td class="left">Vector of 2 64-bit integer values.</td> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 1409 | </tr> |
| 1410 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1411 | </div> |
| 1412 | |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1413 | <!-- _______________________________________________________________________ --> |
| 1414 | <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div> |
| 1415 | <div class="doc_text"> |
| 1416 | |
| 1417 | <h5>Overview:</h5> |
| 1418 | |
| 1419 | <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] | 1420 | 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] | 1421 | In LLVM, opaque types can eventually be resolved to any type (not just a |
| 1422 | structure type).</p> |
| 1423 | |
| 1424 | <h5>Syntax:</h5> |
| 1425 | |
| 1426 | <pre> |
| 1427 | opaque |
| 1428 | </pre> |
| 1429 | |
| 1430 | <h5>Examples:</h5> |
| 1431 | |
| 1432 | <table class="layout"> |
| 1433 | <tr class="layout"> |
Chris Lattner | 23ff1f9 | 2007-12-19 05:04:11 +0000 | [diff] [blame] | 1434 | <td class="left"><tt>opaque</tt></td> |
| 1435 | <td class="left">An opaque type.</td> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1436 | </tr> |
| 1437 | </table> |
| 1438 | </div> |
| 1439 | |
| 1440 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1441 | <!-- *********************************************************************** --> |
| 1442 | <div class="doc_section"> <a name="constants">Constants</a> </div> |
| 1443 | <!-- *********************************************************************** --> |
| 1444 | |
| 1445 | <div class="doc_text"> |
| 1446 | |
| 1447 | <p>LLVM has several different basic types of constants. This section describes |
| 1448 | them all and their syntax.</p> |
| 1449 | |
| 1450 | </div> |
| 1451 | |
| 1452 | <!-- ======================================================================= --> |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1453 | <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1454 | |
| 1455 | <div class="doc_text"> |
| 1456 | |
| 1457 | <dl> |
| 1458 | <dt><b>Boolean constants</b></dt> |
| 1459 | |
| 1460 | <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] | 1461 | constants of the <tt><a href="#t_primitive">i1</a></tt> type. |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1462 | </dd> |
| 1463 | |
| 1464 | <dt><b>Integer constants</b></dt> |
| 1465 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1466 | <dd>Standard integers (such as '4') are constants of the <a |
Reid Spencer | a517338 | 2007-01-04 16:43:23 +0000 | [diff] [blame] | 1467 | href="#t_integer">integer</a> type. Negative numbers may be used with |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1468 | integer types. |
| 1469 | </dd> |
| 1470 | |
| 1471 | <dt><b>Floating point constants</b></dt> |
| 1472 | |
| 1473 | <dd>Floating point constants use standard decimal notation (e.g. 123.421), |
| 1474 | exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 1475 | notation (see below). The assembler requires the exact decimal value of |
| 1476 | a floating-point constant. For example, the assembler accepts 1.25 but |
| 1477 | rejects 1.3 because 1.3 is a repeating decimal in binary. Floating point |
| 1478 | 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] | 1479 | |
| 1480 | <dt><b>Null pointer constants</b></dt> |
| 1481 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1482 | <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] | 1483 | and must be of <a href="#t_pointer">pointer type</a>.</dd> |
| 1484 | |
| 1485 | </dl> |
| 1486 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1487 | <p>The one non-intuitive notation for constants is the optional hexadecimal form |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1488 | of floating point constants. For example, the form '<tt>double |
| 1489 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double |
| 1490 | 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] | 1491 | (and the only time that they are generated by the disassembler) is when a |
| 1492 | floating point constant must be emitted but it cannot be represented as a |
| 1493 | decimal floating point number. For example, NaN's, infinities, and other |
| 1494 | special values are represented in their IEEE hexadecimal format so that |
| 1495 | assembly and disassembly do not cause any bits to change in the constants.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1496 | |
| 1497 | </div> |
| 1498 | |
| 1499 | <!-- ======================================================================= --> |
| 1500 | <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a> |
| 1501 | </div> |
| 1502 | |
| 1503 | <div class="doc_text"> |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1504 | <p>Aggregate constants arise from aggregation of simple constants |
| 1505 | and smaller aggregate constants.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1506 | |
| 1507 | <dl> |
| 1508 | <dt><b>Structure constants</b></dt> |
| 1509 | |
| 1510 | <dd>Structure constants are represented with notation similar to structure |
| 1511 | type definitions (a comma separated list of elements, surrounded by braces |
Chris Lattner | 64910ee | 2007-12-25 20:34:52 +0000 | [diff] [blame] | 1512 | (<tt>{}</tt>)). For example: "<tt>{ i32 4, float 17.0, i32* @G }</tt>", |
| 1513 | 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] | 1514 | 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] | 1515 | types of elements must match those specified by the type. |
| 1516 | </dd> |
| 1517 | |
| 1518 | <dt><b>Array constants</b></dt> |
| 1519 | |
| 1520 | <dd>Array constants are represented with notation similar to array type |
| 1521 | definitions (a comma separated list of elements, surrounded by square brackets |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1522 | (<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] | 1523 | constants must have <a href="#t_array">array type</a>, and the number and |
| 1524 | types of elements must match those specified by the type. |
| 1525 | </dd> |
| 1526 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1527 | <dt><b>Vector constants</b></dt> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1528 | |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1529 | <dd>Vector constants are represented with notation similar to vector type |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1530 | definitions (a comma separated list of elements, surrounded by |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1531 | less-than/greater-than's (<tt><></tt>)). For example: "<tt>< i32 42, |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 1532 | i32 11, i32 74, i32 100 ></tt>". Vector constants must have <a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1533 | 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] | 1534 | match those specified by the type. |
| 1535 | </dd> |
| 1536 | |
| 1537 | <dt><b>Zero initialization</b></dt> |
| 1538 | |
| 1539 | <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a |
| 1540 | value to zero of <em>any</em> type, including scalar and aggregate types. |
| 1541 | 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] | 1542 | large arrays) and is always exactly equivalent to using explicit zero |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1543 | initializers. |
| 1544 | </dd> |
| 1545 | </dl> |
| 1546 | |
| 1547 | </div> |
| 1548 | |
| 1549 | <!-- ======================================================================= --> |
| 1550 | <div class="doc_subsection"> |
| 1551 | <a name="globalconstants">Global Variable and Function Addresses</a> |
| 1552 | </div> |
| 1553 | |
| 1554 | <div class="doc_text"> |
| 1555 | |
| 1556 | <p>The addresses of <a href="#globalvars">global variables</a> and <a |
| 1557 | href="#functionstructure">functions</a> are always implicitly valid (link-time) |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1558 | constants. These constants are explicitly referenced when the <a |
| 1559 | 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] | 1560 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM |
| 1561 | file:</p> |
| 1562 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1563 | <div class="doc_code"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1564 | <pre> |
Chris Lattner | a18a424 | 2007-06-06 18:28:13 +0000 | [diff] [blame] | 1565 | @X = global i32 17 |
| 1566 | @Y = global i32 42 |
| 1567 | @Z = global [2 x i32*] [ i32* @X, i32* @Y ] |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1568 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1569 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1570 | |
| 1571 | </div> |
| 1572 | |
| 1573 | <!-- ======================================================================= --> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1574 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1575 | <div class="doc_text"> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1576 | <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] | 1577 | 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] | 1578 | a constant is permitted.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1579 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1580 | <p>Undefined values indicate to the compiler that the program is well defined |
| 1581 | no matter what value is used, giving the compiler more freedom to optimize. |
| 1582 | </p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1583 | </div> |
| 1584 | |
| 1585 | <!-- ======================================================================= --> |
| 1586 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> |
| 1587 | </div> |
| 1588 | |
| 1589 | <div class="doc_text"> |
| 1590 | |
| 1591 | <p>Constant expressions are used to allow expressions involving other constants |
| 1592 | to be used as constants. Constant expressions may be of any <a |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1593 | 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] | 1594 | that does not have side effects (e.g. load and call are not supported). The |
| 1595 | following is the syntax for constant expressions:</p> |
| 1596 | |
| 1597 | <dl> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1598 | <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt> |
| 1599 | <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] | 1600 | than the bit size of TYPE. Both types must be integers.</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1601 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1602 | <dt><b><tt>zext ( CST to TYPE )</tt></b></dt> |
| 1603 | <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] | 1604 | 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] | 1605 | |
| 1606 | <dt><b><tt>sext ( CST to TYPE )</tt></b></dt> |
| 1607 | <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] | 1608 | 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] | 1609 | |
| 1610 | <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt> |
| 1611 | <dd>Truncate a floating point constant to another floating point type. The |
| 1612 | size of CST must be larger than the size of TYPE. Both types must be |
| 1613 | floating point.</dd> |
| 1614 | |
| 1615 | <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt> |
| 1616 | <dd>Floating point extend a constant to another type. The size of CST must be |
| 1617 | smaller or equal to the size of TYPE. Both types must be floating point.</dd> |
| 1618 | |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 1619 | <dt><b><tt>fptoui ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1620 | <dd>Convert a floating point constant to the corresponding unsigned integer |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1621 | constant. TYPE must be a scalar or vector integer type. CST must be of scalar |
| 1622 | or vector floating point type. Both CST and TYPE must be scalars, or vectors |
| 1623 | of the same number of elements. If the value won't fit in the integer type, |
| 1624 | the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1625 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1626 | <dt><b><tt>fptosi ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1627 | <dd>Convert a floating point constant to the corresponding signed integer |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1628 | constant. TYPE must be a scalar or vector integer type. CST must be of scalar |
| 1629 | or vector floating point type. Both CST and TYPE must be scalars, or vectors |
| 1630 | of the same number of elements. If the value won't fit in the integer type, |
| 1631 | the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1632 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1633 | <dt><b><tt>uitofp ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1634 | <dd>Convert an unsigned integer constant to the corresponding floating point |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1635 | constant. TYPE must be a scalar or vector floating point type. CST must be of |
| 1636 | scalar or vector integer type. Both CST and TYPE must be scalars, or vectors |
| 1637 | of the same number of elements. If the value won't fit in the floating point |
| 1638 | type, the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1639 | |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 1640 | <dt><b><tt>sitofp ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1641 | <dd>Convert a signed integer constant to the corresponding floating point |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 1642 | constant. TYPE must be a scalar or vector floating point type. CST must be of |
| 1643 | scalar or vector integer type. Both CST and TYPE must be scalars, or vectors |
| 1644 | of the same number of elements. If the value won't fit in the floating point |
| 1645 | type, the results are undefined.</dd> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1646 | |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1647 | <dt><b><tt>ptrtoint ( CST to TYPE )</tt></b></dt> |
| 1648 | <dd>Convert a pointer typed constant to the corresponding integer constant |
| 1649 | TYPE must be an integer type. CST must be of pointer type. The CST value is |
| 1650 | zero extended, truncated, or unchanged to make it fit in TYPE.</dd> |
| 1651 | |
| 1652 | <dt><b><tt>inttoptr ( CST to TYPE )</tt></b></dt> |
| 1653 | <dd>Convert a integer constant to a pointer constant. TYPE must be a |
| 1654 | pointer type. CST must be of integer type. The CST value is zero extended, |
| 1655 | truncated, or unchanged to make it fit in a pointer size. This one is |
| 1656 | <i>really</i> dangerous!</dd> |
| 1657 | |
| 1658 | <dt><b><tt>bitcast ( CST to TYPE )</tt></b></dt> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1659 | <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be |
| 1660 | identical (same number of bits). The conversion is done as if the CST value |
| 1661 | was stored to memory and read back as TYPE. In other words, no bits change |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1662 | with this operator, just the type. This can be used for conversion of |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 1663 | vector types to any other type, as long as they have the same bit width. For |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 1664 | pointers it is only valid to cast to another pointer type. |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1665 | </dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1666 | |
| 1667 | <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> |
| 1668 | |
| 1669 | <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on |
| 1670 | constants. As with the <a href="#i_getelementptr">getelementptr</a> |
| 1671 | instruction, the index list may have zero or more indexes, which are required |
| 1672 | to make sense for the type of "CSTPTR".</dd> |
| 1673 | |
Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1674 | <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt> |
| 1675 | |
| 1676 | <dd>Perform the <a href="#i_select">select operation</a> on |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1677 | constants.</dd> |
| 1678 | |
| 1679 | <dt><b><tt>icmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 1680 | <dd>Performs the <a href="#i_icmp">icmp operation</a> on constants.</dd> |
| 1681 | |
| 1682 | <dt><b><tt>fcmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 1683 | <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] | 1684 | |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 1685 | <dt><b><tt>vicmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 1686 | <dd>Performs the <a href="#i_vicmp">vicmp operation</a> on constants.</dd> |
| 1687 | |
| 1688 | <dt><b><tt>vfcmp COND ( VAL1, VAL2 )</tt></b></dt> |
| 1689 | <dd>Performs the <a href="#i_vfcmp">vfcmp operation</a> on constants.</dd> |
| 1690 | |
Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1691 | <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt> |
| 1692 | |
| 1693 | <dd>Perform the <a href="#i_extractelement">extractelement |
| 1694 | operation</a> on constants. |
| 1695 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 1696 | <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt> |
| 1697 | |
| 1698 | <dd>Perform the <a href="#i_insertelement">insertelement |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1699 | operation</a> on constants.</dd> |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 1700 | |
Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 1701 | |
| 1702 | <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt> |
| 1703 | |
| 1704 | <dd>Perform the <a href="#i_shufflevector">shufflevector |
Reid Spencer | 01c4259 | 2006-12-04 19:23:19 +0000 | [diff] [blame] | 1705 | operation</a> on constants.</dd> |
Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 1706 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1707 | <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> |
| 1708 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1709 | <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may |
| 1710 | 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] | 1711 | binary</a> operations. The constraints on operands are the same as those for |
| 1712 | the corresponding instruction (e.g. no bitwise operations on floating point |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1713 | values are allowed).</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1714 | </dl> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1715 | </div> |
Chris Lattner | 9ee5d22 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 1716 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1717 | <!-- *********************************************************************** --> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1718 | <div class="doc_section"> <a name="othervalues">Other Values</a> </div> |
| 1719 | <!-- *********************************************************************** --> |
| 1720 | |
| 1721 | <!-- ======================================================================= --> |
| 1722 | <div class="doc_subsection"> |
| 1723 | <a name="inlineasm">Inline Assembler Expressions</a> |
| 1724 | </div> |
| 1725 | |
| 1726 | <div class="doc_text"> |
| 1727 | |
| 1728 | <p> |
| 1729 | LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm"> |
| 1730 | Module-Level Inline Assembly</a>) through the use of a special value. This |
| 1731 | value represents the inline assembler as a string (containing the instructions |
| 1732 | to emit), a list of operand constraints (stored as a string), and a flag that |
| 1733 | indicates whether or not the inline asm expression has side effects. An example |
| 1734 | inline assembler expression is: |
| 1735 | </p> |
| 1736 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1737 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1738 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1739 | i32 (i32) asm "bswap $0", "=r,r" |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1740 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1741 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1742 | |
| 1743 | <p> |
| 1744 | Inline assembler expressions may <b>only</b> be used as the callee operand of |
| 1745 | a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have: |
| 1746 | </p> |
| 1747 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1748 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1749 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1750 | %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] | 1751 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1752 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1753 | |
| 1754 | <p> |
| 1755 | Inline asms with side effects not visible in the constraint list must be marked |
| 1756 | as having side effects. This is done through the use of the |
| 1757 | '<tt>sideeffect</tt>' keyword, like so: |
| 1758 | </p> |
| 1759 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1760 | <div class="doc_code"> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1761 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1762 | call void asm sideeffect "eieio", ""() |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1763 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 1764 | </div> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1765 | |
| 1766 | <p>TODO: The format of the asm and constraints string still need to be |
| 1767 | documented here. Constraints on what can be done (e.g. duplication, moving, etc |
| 1768 | need to be documented). |
| 1769 | </p> |
| 1770 | |
| 1771 | </div> |
| 1772 | |
| 1773 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1774 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> |
| 1775 | <!-- *********************************************************************** --> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1776 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1777 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1778 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1779 | <p>The LLVM instruction set consists of several different |
| 1780 | classifications of instructions: <a href="#terminators">terminator |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1781 | instructions</a>, <a href="#binaryops">binary instructions</a>, |
| 1782 | <a href="#bitwiseops">bitwise binary instructions</a>, <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1783 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other |
| 1784 | instructions</a>.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1785 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1786 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1787 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1788 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1789 | <div class="doc_subsection"> <a name="terminators">Terminator |
| 1790 | Instructions</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1791 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1792 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1793 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1794 | <p>As mentioned <a href="#functionstructure">previously</a>, every |
| 1795 | basic block in a program ends with a "Terminator" instruction, which |
| 1796 | indicates which block should be executed after the current block is |
| 1797 | finished. These terminator instructions typically yield a '<tt>void</tt>' |
| 1798 | value: they produce control flow, not values (the one exception being |
| 1799 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1800 | <p>There are six different terminator instructions: the '<a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1801 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' |
| 1802 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1803 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a |
| 1804 | href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a |
| 1805 | href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1806 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1807 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1808 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1809 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1810 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' |
| 1811 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1812 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1813 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1814 | <pre> ret <type> <value> <i>; Return a value from a non-void function</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1815 | ret void <i>; Return from void function</i> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1816 | ret <type> <value>, <type> <value> <i>; Return two values from a non-void function </i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1817 | </pre> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1818 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1819 | <h5>Overview:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1820 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1821 | <p>The '<tt>ret</tt>' instruction is used to return control flow (and a |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1822 | value) from a function back to the caller.</p> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 1823 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1824 | returns value(s) and then causes control flow, and one that just causes |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1825 | control flow to occur.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1826 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1827 | <h5>Arguments:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1828 | |
| 1829 | <p>The '<tt>ret</tt>' instruction may return zero, one or multiple values. |
| 1830 | The type of each return value must be a '<a href="#t_firstclass">first |
| 1831 | class</a>' type. Note that a function is not <a href="#wellformed">well |
| 1832 | formed</a> if there exists a '<tt>ret</tt>' instruction inside of the |
| 1833 | function that returns values that do not match the return type of the |
| 1834 | function.</p> |
| 1835 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1836 | <h5>Semantics:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1837 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1838 | <p>When the '<tt>ret</tt>' instruction is executed, control flow |
| 1839 | 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] | 1840 | href="#i_call"><tt>call</tt></a>" instruction, execution continues at |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1841 | the instruction after the call. If the caller was an "<a |
| 1842 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1843 | at the beginning of the "normal" destination block. If the instruction |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1844 | returns a value, that value shall set the call or invoke instruction's |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1845 | return value. If the instruction returns multiple values then these |
Devang Patel | 0dbb4a1 | 2008-03-11 05:51:59 +0000 | [diff] [blame] | 1846 | values can only be accessed through a '<a href="#i_getresult"><tt>getresult</tt> |
| 1847 | </a>' instruction.</p> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1848 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1849 | <h5>Example:</h5> |
Chris Lattner | f4cde4e | 2008-04-23 04:59:35 +0000 | [diff] [blame] | 1850 | |
| 1851 | <pre> |
| 1852 | ret i32 5 <i>; Return an integer value of 5</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1853 | ret void <i>; Return from a void function</i> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1854 | ret i32 4, i8 2 <i>; Return two values 4 and 2 </i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1855 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1856 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1857 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1858 | <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] | 1859 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1860 | <h5>Syntax:</h5> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1861 | <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] | 1862 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1863 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1864 | <p>The '<tt>br</tt>' instruction is used to cause control flow to |
| 1865 | transfer to a different basic block in the current function. There are |
| 1866 | two forms of this instruction, corresponding to a conditional branch |
| 1867 | and an unconditional branch.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1868 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1869 | <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] | 1870 | single '<tt>i1</tt>' value and two '<tt>label</tt>' values. The |
Reid Spencer | de15194 | 2007-02-19 23:54:10 +0000 | [diff] [blame] | 1871 | unconditional form of the '<tt>br</tt>' instruction takes a single |
| 1872 | '<tt>label</tt>' value as a target.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1873 | <h5>Semantics:</h5> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1874 | <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] | 1875 | argument is evaluated. If the value is <tt>true</tt>, control flows |
| 1876 | to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>, |
| 1877 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1878 | <h5>Example:</h5> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1879 | <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] | 1880 | 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] | 1881 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1882 | <!-- _______________________________________________________________________ --> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1883 | <div class="doc_subsubsection"> |
| 1884 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> |
| 1885 | </div> |
| 1886 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1887 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1888 | <h5>Syntax:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1889 | |
| 1890 | <pre> |
| 1891 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] |
| 1892 | </pre> |
| 1893 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1894 | <h5>Overview:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1895 | |
| 1896 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of |
| 1897 | several different places. It is a generalization of the '<tt>br</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1898 | instruction, allowing a branch to occur to one of many possible |
| 1899 | destinations.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1900 | |
| 1901 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1902 | <h5>Arguments:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1903 | |
| 1904 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer |
| 1905 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and |
| 1906 | an array of pairs of comparison value constants and '<tt>label</tt>'s. The |
| 1907 | table is not allowed to contain duplicate constant entries.</p> |
| 1908 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1909 | <h5>Semantics:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1910 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1911 | <p>The <tt>switch</tt> instruction specifies a table of values and |
| 1912 | destinations. When the '<tt>switch</tt>' instruction is executed, this |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1913 | table is searched for the given value. If the value is found, control flow is |
| 1914 | transfered to the corresponding destination; otherwise, control flow is |
| 1915 | transfered to the default destination.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1916 | |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1917 | <h5>Implementation:</h5> |
| 1918 | |
| 1919 | <p>Depending on properties of the target machine and the particular |
| 1920 | <tt>switch</tt> instruction, this instruction may be code generated in different |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1921 | ways. For example, it could be generated as a series of chained conditional |
| 1922 | branches or with a lookup table.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1923 | |
| 1924 | <h5>Example:</h5> |
| 1925 | |
| 1926 | <pre> |
| 1927 | <i>; Emulate a conditional br instruction</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 1928 | %Val = <a href="#i_zext">zext</a> i1 %value to i32 |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1929 | switch i32 %Val, label %truedest [i32 0, label %falsedest ] |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1930 | |
| 1931 | <i>; Emulate an unconditional br instruction</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1932 | switch i32 0, label %dest [ ] |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1933 | |
| 1934 | <i>; Implement a jump table:</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 1935 | switch i32 %val, label %otherwise [ i32 0, label %onzero |
| 1936 | i32 1, label %onone |
| 1937 | i32 2, label %ontwo ] |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1938 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1939 | </div> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1940 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1941 | <!-- _______________________________________________________________________ --> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1942 | <div class="doc_subsubsection"> |
| 1943 | <a name="i_invoke">'<tt>invoke</tt>' Instruction</a> |
| 1944 | </div> |
| 1945 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1946 | <div class="doc_text"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1947 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1948 | <h5>Syntax:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1949 | |
| 1950 | <pre> |
Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 1951 | <result> = invoke [<a href="#callingconv">cconv</a>] <ptr to function ty> <function ptr val>(<function args>) |
Chris Lattner | 76b8a33 | 2006-05-14 18:23:06 +0000 | [diff] [blame] | 1952 | to label <normal label> unwind label <exception label> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1953 | </pre> |
| 1954 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1955 | <h5>Overview:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1956 | |
| 1957 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified |
| 1958 | function, with the possibility of control flow transfer to either the |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1959 | '<tt>normal</tt>' label or the |
| 1960 | '<tt>exception</tt>' label. If the callee function returns with the |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1961 | "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the |
| 1962 | "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] | 1963 | href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 1964 | continued at the dynamically nearest "exception" label. If the callee function |
Devang Patel | 0dbb4a1 | 2008-03-11 05:51:59 +0000 | [diff] [blame] | 1965 | returns multiple values then individual return values are only accessible through |
| 1966 | a '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1967 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1968 | <h5>Arguments:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1969 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1970 | <p>This instruction requires several arguments:</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1971 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1972 | <ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1973 | <li> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 1974 | The optional "cconv" marker indicates which <a href="#callingconv">calling |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1975 | convention</a> the call should use. If none is specified, the call defaults |
| 1976 | to using C calling conventions. |
| 1977 | </li> |
| 1978 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to |
| 1979 | function value being invoked. In most cases, this is a direct function |
| 1980 | invocation, but indirect <tt>invoke</tt>s are just as possible, branching off |
| 1981 | an arbitrary pointer to function value. |
| 1982 | </li> |
| 1983 | |
| 1984 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a |
| 1985 | function to be invoked. </li> |
| 1986 | |
| 1987 | <li>'<tt>function args</tt>': argument list whose types match the function |
| 1988 | signature argument types. If the function signature indicates the function |
| 1989 | accepts a variable number of arguments, the extra arguments can be |
| 1990 | specified. </li> |
| 1991 | |
| 1992 | <li>'<tt>normal label</tt>': the label reached when the called function |
| 1993 | executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> |
| 1994 | |
| 1995 | <li>'<tt>exception label</tt>': the label reached when a callee returns with |
| 1996 | the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> |
| 1997 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1998 | </ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1999 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2000 | <h5>Semantics:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2001 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2002 | <p>This instruction is designed to operate as a standard '<tt><a |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2003 | href="#i_call">call</a></tt>' instruction in most regards. The primary |
| 2004 | difference is that it establishes an association with a label, which is used by |
| 2005 | the runtime library to unwind the stack.</p> |
| 2006 | |
| 2007 | <p>This instruction is used in languages with destructors to ensure that proper |
| 2008 | cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown |
| 2009 | exception. Additionally, this is important for implementation of |
| 2010 | '<tt>catch</tt>' clauses in high-level languages that support them.</p> |
| 2011 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2012 | <h5>Example:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 2013 | <pre> |
Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2014 | %retval = invoke i32 @Test(i32 15) to label %Continue |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2015 | unwind label %TestCleanup <i>; {i32}:retval set</i> |
Nick Lewycky | d703f65 | 2008-03-16 07:18:12 +0000 | [diff] [blame] | 2016 | %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] | 2017 | unwind label %TestCleanup <i>; {i32}:retval set</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2018 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2019 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2020 | |
| 2021 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2022 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2023 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2024 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' |
| 2025 | Instruction</a> </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2026 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2027 | <div class="doc_text"> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2028 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2029 | <h5>Syntax:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2030 | <pre> |
| 2031 | unwind |
| 2032 | </pre> |
| 2033 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2034 | <h5>Overview:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2035 | |
| 2036 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow |
| 2037 | at the first callee in the dynamic call stack which used an <a |
| 2038 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is |
| 2039 | primarily used to implement exception handling.</p> |
| 2040 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2041 | <h5>Semantics:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2042 | |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2043 | <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] | 2044 | immediately halt. The dynamic call stack is then searched for the first <a |
| 2045 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found, |
| 2046 | execution continues at the "exceptional" destination block specified by the |
| 2047 | <tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the |
| 2048 | dynamic call chain, undefined behavior results.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2049 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 2050 | |
| 2051 | <!-- _______________________________________________________________________ --> |
| 2052 | |
| 2053 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' |
| 2054 | Instruction</a> </div> |
| 2055 | |
| 2056 | <div class="doc_text"> |
| 2057 | |
| 2058 | <h5>Syntax:</h5> |
| 2059 | <pre> |
| 2060 | unreachable |
| 2061 | </pre> |
| 2062 | |
| 2063 | <h5>Overview:</h5> |
| 2064 | |
| 2065 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics. This |
| 2066 | instruction is used to inform the optimizer that a particular portion of the |
| 2067 | code is not reachable. This can be used to indicate that the code after a |
| 2068 | no-return function cannot be reached, and other facts.</p> |
| 2069 | |
| 2070 | <h5>Semantics:</h5> |
| 2071 | |
| 2072 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> |
| 2073 | </div> |
| 2074 | |
| 2075 | |
| 2076 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2077 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2078 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2079 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2080 | <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] | 2081 | 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] | 2082 | produce a single value. The operands might represent |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2083 | 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] | 2084 | The result value has the same type as its operands.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2085 | <p>There are several different binary operators:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2086 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2087 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2088 | <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>' |
| 2089 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2090 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2091 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2092 | <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2093 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2094 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2095 | <p>The '<tt>add</tt>' instruction returns the sum of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2096 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2097 | <p>The two arguments to the '<tt>add</tt>' instruction must be either <a |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2098 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values. |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2099 | This instruction can also take <a href="#t_vector">vector</a> versions of the values. |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2100 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2101 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2102 | <p>The value produced is the integer or floating point sum of the two |
| 2103 | operands.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2104 | <p>If an integer sum has unsigned overflow, the result returned is the |
| 2105 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of |
| 2106 | the result.</p> |
| 2107 | <p>Because LLVM integers use a two's complement representation, this |
| 2108 | instruction is appropriate for both signed and unsigned integers.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2109 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2110 | <pre> <result> = add i32 4, %var <i>; yields {i32}:result = 4 + %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2111 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2112 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2113 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2114 | <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>' |
| 2115 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2116 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2117 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2118 | <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2119 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2120 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2121 | <p>The '<tt>sub</tt>' instruction returns the difference of its two |
| 2122 | operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2123 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>' |
| 2124 | instruction present in most other intermediate representations.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2125 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2126 | <p>The two arguments to the '<tt>sub</tt>' instruction must be either <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2127 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2128 | values. |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2129 | This instruction can also take <a href="#t_vector">vector</a> versions of the values. |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2130 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2131 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2132 | <p>The value produced is the integer or floating point difference of |
| 2133 | the two operands.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2134 | <p>If an integer difference has unsigned overflow, the result returned is the |
| 2135 | mathematical result modulo 2<sup>n</sup>, where n is the bit width of |
| 2136 | the result.</p> |
| 2137 | <p>Because LLVM integers use a two's complement representation, this |
| 2138 | instruction is appropriate for both signed and unsigned integers.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2139 | <h5>Example:</h5> |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 2140 | <pre> |
| 2141 | <result> = sub i32 4, %var <i>; yields {i32}:result = 4 - %var</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2142 | <result> = sub i32 0, %val <i>; yields {i32}:result = -%var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2143 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2144 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2145 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2146 | <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>' |
| 2147 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2148 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2149 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2150 | <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2151 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2152 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2153 | <p>The '<tt>mul</tt>' instruction returns the product of its two |
| 2154 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2155 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2156 | <p>The two arguments to the '<tt>mul</tt>' instruction must be either <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2157 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2158 | values. |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2159 | This instruction can also take <a href="#t_vector">vector</a> versions of the values. |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 2160 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2161 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2162 | <p>The value produced is the integer or floating point product of the |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2163 | two operands.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2164 | <p>If the result of an integer multiplication has unsigned overflow, |
| 2165 | the result returned is the mathematical result modulo |
| 2166 | 2<sup>n</sup>, where n is the bit width of the result.</p> |
| 2167 | <p>Because LLVM integers use a two's complement representation, and the |
| 2168 | result is the same width as the operands, this instruction returns the |
| 2169 | correct result for both signed and unsigned integers. If a full product |
| 2170 | (e.g. <tt>i32</tt>x<tt>i32</tt>-><tt>i64</tt>) is needed, the operands |
| 2171 | should be sign-extended or zero-extended as appropriate to the |
| 2172 | width of the full product.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2173 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2174 | <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] | 2175 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2176 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2177 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2178 | <div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction |
| 2179 | </a></div> |
| 2180 | <div class="doc_text"> |
| 2181 | <h5>Syntax:</h5> |
| 2182 | <pre> <result> = udiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2183 | </pre> |
| 2184 | <h5>Overview:</h5> |
| 2185 | <p>The '<tt>udiv</tt>' instruction returns the quotient of its two |
| 2186 | operands.</p> |
| 2187 | <h5>Arguments:</h5> |
| 2188 | <p>The two arguments to the '<tt>udiv</tt>' instruction must be |
| 2189 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2190 | types. This instruction can also take <a href="#t_vector">vector</a> versions |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2191 | of the values in which case the elements must be integers.</p> |
| 2192 | <h5>Semantics:</h5> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2193 | <p>The value produced is the unsigned integer quotient of the two operands.</p> |
| 2194 | <p>Note that unsigned integer division and signed integer division are distinct |
| 2195 | operations; for signed integer division, use '<tt>sdiv</tt>'.</p> |
| 2196 | <p>Division by zero leads to undefined behavior.</p> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2197 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2198 | <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] | 2199 | </pre> |
| 2200 | </div> |
| 2201 | <!-- _______________________________________________________________________ --> |
| 2202 | <div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction |
| 2203 | </a> </div> |
| 2204 | <div class="doc_text"> |
| 2205 | <h5>Syntax:</h5> |
| 2206 | <pre> <result> = sdiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2207 | </pre> |
| 2208 | <h5>Overview:</h5> |
| 2209 | <p>The '<tt>sdiv</tt>' instruction returns the quotient of its two |
| 2210 | operands.</p> |
| 2211 | <h5>Arguments:</h5> |
| 2212 | <p>The two arguments to the '<tt>sdiv</tt>' instruction must be |
| 2213 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2214 | types. This instruction can also take <a href="#t_vector">vector</a> versions |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2215 | of the values in which case the elements must be integers.</p> |
| 2216 | <h5>Semantics:</h5> |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2217 | <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] | 2218 | <p>Note that signed integer division and unsigned integer division are distinct |
| 2219 | operations; for unsigned integer division, use '<tt>udiv</tt>'.</p> |
| 2220 | <p>Division by zero leads to undefined behavior. Overflow also leads to |
| 2221 | undefined behavior; this is a rare case, but can occur, for example, |
| 2222 | by doing a 32-bit division of -2147483648 by -1.</p> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2223 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2224 | <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] | 2225 | </pre> |
| 2226 | </div> |
| 2227 | <!-- _______________________________________________________________________ --> |
| 2228 | <div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2229 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2230 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2231 | <h5>Syntax:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2232 | <pre> <result> = fdiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2233 | </pre> |
| 2234 | <h5>Overview:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2235 | <p>The '<tt>fdiv</tt>' instruction returns the quotient of its two |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2236 | operands.</p> |
| 2237 | <h5>Arguments:</h5> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2238 | <p>The two arguments to the '<tt>fdiv</tt>' instruction must be |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2239 | <a href="#t_floating">floating point</a> values. Both arguments must have |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2240 | identical types. This instruction can also take <a href="#t_vector">vector</a> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2241 | versions of floating point values.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2242 | <h5>Semantics:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2243 | <p>The value produced is the floating point quotient of the two operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2244 | <h5>Example:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 2245 | <pre> <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] | 2246 | </pre> |
| 2247 | </div> |
| 2248 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2249 | <div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a> |
| 2250 | </div> |
| 2251 | <div class="doc_text"> |
| 2252 | <h5>Syntax:</h5> |
| 2253 | <pre> <result> = urem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2254 | </pre> |
| 2255 | <h5>Overview:</h5> |
| 2256 | <p>The '<tt>urem</tt>' instruction returns the remainder from the |
| 2257 | unsigned division of its two arguments.</p> |
| 2258 | <h5>Arguments:</h5> |
| 2259 | <p>The two arguments to the '<tt>urem</tt>' instruction must be |
| 2260 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 2261 | types. This instruction can also take <a href="#t_vector">vector</a> versions |
| 2262 | of the values in which case the elements must be integers.</p> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2263 | <h5>Semantics:</h5> |
| 2264 | <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] | 2265 | This instruction always performs an unsigned division to get the remainder.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2266 | <p>Note that unsigned integer remainder and signed integer remainder are |
| 2267 | distinct operations; for signed integer remainder, use '<tt>srem</tt>'.</p> |
| 2268 | <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] | 2269 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2270 | <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] | 2271 | </pre> |
| 2272 | |
| 2273 | </div> |
| 2274 | <!-- _______________________________________________________________________ --> |
| 2275 | <div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2276 | Instruction</a> </div> |
| 2277 | <div class="doc_text"> |
| 2278 | <h5>Syntax:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2279 | <pre> <result> = srem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2280 | </pre> |
| 2281 | <h5>Overview:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2282 | <p>The '<tt>srem</tt>' instruction returns the remainder from the |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 2283 | signed division of its two operands. This instruction can also take |
| 2284 | <a href="#t_vector">vector</a> versions of the values in which case |
| 2285 | the elements must be integers.</p> |
Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 2286 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2287 | <h5>Arguments:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2288 | <p>The two arguments to the '<tt>srem</tt>' instruction must be |
| 2289 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
| 2290 | types.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2291 | <h5>Semantics:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2292 | <p>This instruction returns the <i>remainder</i> of a division (where the result |
Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2293 | has the same sign as the dividend, <tt>var1</tt>), not the <i>modulo</i> |
| 2294 | operator (where the result has the same sign as the divisor, <tt>var2</tt>) of |
| 2295 | a value. For more information about the difference, see <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2296 | 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] | 2297 | 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] | 2298 | please see <a href="http://en.wikipedia.org/wiki/Modulo_operation"> |
Reid Spencer | c9fdfc8 | 2007-03-24 22:23:39 +0000 | [diff] [blame] | 2299 | Wikipedia: modulo operation</a>.</p> |
Chris Lattner | 5ec8983 | 2008-01-28 00:36:27 +0000 | [diff] [blame] | 2300 | <p>Note that signed integer remainder and unsigned integer remainder are |
| 2301 | distinct operations; for unsigned integer remainder, use '<tt>urem</tt>'.</p> |
| 2302 | <p>Taking the remainder of a division by zero leads to undefined behavior. |
| 2303 | Overflow also leads to undefined behavior; this is a rare case, but can occur, |
| 2304 | for example, by taking the remainder of a 32-bit division of -2147483648 by -1. |
| 2305 | (The remainder doesn't actually overflow, but this rule lets srem be |
| 2306 | implemented using instructions that return both the result of the division |
| 2307 | and the remainder.)</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2308 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2309 | <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] | 2310 | </pre> |
| 2311 | |
| 2312 | </div> |
| 2313 | <!-- _______________________________________________________________________ --> |
| 2314 | <div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>' |
| 2315 | Instruction</a> </div> |
| 2316 | <div class="doc_text"> |
| 2317 | <h5>Syntax:</h5> |
| 2318 | <pre> <result> = frem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2319 | </pre> |
| 2320 | <h5>Overview:</h5> |
| 2321 | <p>The '<tt>frem</tt>' instruction returns the remainder from the |
| 2322 | division of its two operands.</p> |
| 2323 | <h5>Arguments:</h5> |
| 2324 | <p>The two arguments to the '<tt>frem</tt>' instruction must be |
| 2325 | <a href="#t_floating">floating point</a> values. Both arguments must have |
Dan Gohman | 8017631 | 2007-11-05 23:35:22 +0000 | [diff] [blame] | 2326 | identical types. This instruction can also take <a href="#t_vector">vector</a> |
| 2327 | versions of floating point values.</p> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2328 | <h5>Semantics:</h5> |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2329 | <p>This instruction returns the <i>remainder</i> of a division. |
| 2330 | The remainder has the same sign as the dividend.</p> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 2331 | <h5>Example:</h5> |
| 2332 | <pre> <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] | 2333 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2334 | </div> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 2335 | |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2336 | <!-- ======================================================================= --> |
| 2337 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary |
| 2338 | Operations</a> </div> |
| 2339 | <div class="doc_text"> |
| 2340 | <p>Bitwise binary operators are used to do various forms of |
| 2341 | bit-twiddling in a program. They are generally very efficient |
| 2342 | instructions and can commonly be strength reduced from other |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2343 | instructions. They require two operands of the same type, execute an operation on them, |
| 2344 | 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] | 2345 | </div> |
| 2346 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2347 | <!-- _______________________________________________________________________ --> |
| 2348 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' |
| 2349 | Instruction</a> </div> |
| 2350 | <div class="doc_text"> |
| 2351 | <h5>Syntax:</h5> |
| 2352 | <pre> <result> = shl <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2353 | </pre> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2354 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2355 | <h5>Overview:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2356 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2357 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to |
| 2358 | the left a specified number of bits.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2359 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2360 | <h5>Arguments:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2361 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2362 | <p>Both arguments to the '<tt>shl</tt>' instruction must be the same <a |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2363 | href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an |
| 2364 | unsigned value.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2365 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2366 | <h5>Semantics:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2367 | |
Chris Lattner | a73afe0 | 2008-04-01 18:45:27 +0000 | [diff] [blame] | 2368 | <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup> mod 2<sup>n</sup>, |
| 2369 | where n is the width of the result. If <tt>var2</tt> is (statically or dynamically) negative or |
| 2370 | equal to or larger than the number of bits in <tt>var1</tt>, the result is undefined.</p> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2371 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2372 | <h5>Example:</h5><pre> |
| 2373 | <result> = shl i32 4, %var <i>; yields {i32}: 4 << %var</i> |
| 2374 | <result> = shl i32 4, 2 <i>; yields {i32}: 16</i> |
| 2375 | <result> = shl i32 1, 10 <i>; yields {i32}: 1024</i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2376 | <result> = shl i32 1, 32 <i>; undefined</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2377 | </pre> |
| 2378 | </div> |
| 2379 | <!-- _______________________________________________________________________ --> |
| 2380 | <div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>' |
| 2381 | Instruction</a> </div> |
| 2382 | <div class="doc_text"> |
| 2383 | <h5>Syntax:</h5> |
| 2384 | <pre> <result> = lshr <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2385 | </pre> |
| 2386 | |
| 2387 | <h5>Overview:</h5> |
| 2388 | <p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2389 | 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] | 2390 | |
| 2391 | <h5>Arguments:</h5> |
| 2392 | <p>Both arguments to the '<tt>lshr</tt>' instruction must be the same |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2393 | <a href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an |
| 2394 | unsigned value.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2395 | |
| 2396 | <h5>Semantics:</h5> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2397 | |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2398 | <p>This instruction always performs a logical shift right operation. The most |
| 2399 | significant bits of the result will be filled with zero bits after the |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2400 | shift. If <tt>var2</tt> is (statically or dynamically) equal to or larger than |
| 2401 | the number of bits in <tt>var1</tt>, the result is undefined.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2402 | |
| 2403 | <h5>Example:</h5> |
| 2404 | <pre> |
| 2405 | <result> = lshr i32 4, 1 <i>; yields {i32}:result = 2</i> |
| 2406 | <result> = lshr i32 4, 2 <i>; yields {i32}:result = 1</i> |
| 2407 | <result> = lshr i8 4, 3 <i>; yields {i8}:result = 0</i> |
| 2408 | <result> = lshr i8 -2, 1 <i>; yields {i8}:result = 0x7FFFFFFF </i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2409 | <result> = lshr i32 1, 32 <i>; undefined</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2410 | </pre> |
| 2411 | </div> |
| 2412 | |
Reid Spencer | 8e11bf8 | 2007-02-02 13:57:07 +0000 | [diff] [blame] | 2413 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2414 | <div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>' |
| 2415 | Instruction</a> </div> |
| 2416 | <div class="doc_text"> |
| 2417 | |
| 2418 | <h5>Syntax:</h5> |
| 2419 | <pre> <result> = ashr <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 2420 | </pre> |
| 2421 | |
| 2422 | <h5>Overview:</h5> |
| 2423 | <p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2424 | 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] | 2425 | |
| 2426 | <h5>Arguments:</h5> |
| 2427 | <p>Both arguments to the '<tt>ashr</tt>' instruction must be the same |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2428 | <a href="#t_integer">integer</a> type. '<tt>var2</tt>' is treated as an |
| 2429 | unsigned value.</p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2430 | |
| 2431 | <h5>Semantics:</h5> |
| 2432 | <p>This instruction always performs an arithmetic shift right operation, |
| 2433 | The most significant bits of the result will be filled with the sign bit |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2434 | of <tt>var1</tt>. If <tt>var2</tt> is (statically or dynamically) equal to or |
| 2435 | larger than the number of bits in <tt>var1</tt>, the result is undefined. |
| 2436 | </p> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2437 | |
| 2438 | <h5>Example:</h5> |
| 2439 | <pre> |
| 2440 | <result> = ashr i32 4, 1 <i>; yields {i32}:result = 2</i> |
| 2441 | <result> = ashr i32 4, 2 <i>; yields {i32}:result = 1</i> |
| 2442 | <result> = ashr i8 4, 3 <i>; yields {i8}:result = 0</i> |
| 2443 | <result> = ashr i8 -2, 1 <i>; yields {i8}:result = -1</i> |
Chris Lattner | 6ccc2d5 | 2007-10-03 21:01:14 +0000 | [diff] [blame] | 2444 | <result> = ashr i32 1, 32 <i>; undefined</i> |
Reid Spencer | 569f2fa | 2007-01-31 21:39:12 +0000 | [diff] [blame] | 2445 | </pre> |
| 2446 | </div> |
| 2447 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2448 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2449 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' |
| 2450 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2451 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2452 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2453 | <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2454 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2455 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2456 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of |
| 2457 | its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2458 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2459 | <p>The two arguments to the '<tt>and</tt>' instruction must be <a |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 2460 | href="#t_integer">integer</a> values. Both arguments must have |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2461 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2462 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2463 | <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] | 2464 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2465 | <div style="align: center"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2466 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2467 | <tbody> |
| 2468 | <tr> |
| 2469 | <td>In0</td> |
| 2470 | <td>In1</td> |
| 2471 | <td>Out</td> |
| 2472 | </tr> |
| 2473 | <tr> |
| 2474 | <td>0</td> |
| 2475 | <td>0</td> |
| 2476 | <td>0</td> |
| 2477 | </tr> |
| 2478 | <tr> |
| 2479 | <td>0</td> |
| 2480 | <td>1</td> |
| 2481 | <td>0</td> |
| 2482 | </tr> |
| 2483 | <tr> |
| 2484 | <td>1</td> |
| 2485 | <td>0</td> |
| 2486 | <td>0</td> |
| 2487 | </tr> |
| 2488 | <tr> |
| 2489 | <td>1</td> |
| 2490 | <td>1</td> |
| 2491 | <td>1</td> |
| 2492 | </tr> |
| 2493 | </tbody> |
| 2494 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2495 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2496 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2497 | <pre> <result> = and i32 4, %var <i>; yields {i32}:result = 4 & %var</i> |
| 2498 | <result> = and i32 15, 40 <i>; yields {i32}:result = 8</i> |
| 2499 | <result> = and i32 4, 8 <i>; yields {i32}:result = 0</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2500 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2501 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2502 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2503 | <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] | 2504 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2505 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2506 | <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2507 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2508 | <h5>Overview:</h5> |
| 2509 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive |
| 2510 | or of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2511 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2512 | <p>The two arguments to the '<tt>or</tt>' instruction must be <a |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 2513 | href="#t_integer">integer</a> values. Both arguments must have |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2514 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2515 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2516 | <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] | 2517 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2518 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2519 | <table border="1" cellspacing="0" cellpadding="4"> |
| 2520 | <tbody> |
| 2521 | <tr> |
| 2522 | <td>In0</td> |
| 2523 | <td>In1</td> |
| 2524 | <td>Out</td> |
| 2525 | </tr> |
| 2526 | <tr> |
| 2527 | <td>0</td> |
| 2528 | <td>0</td> |
| 2529 | <td>0</td> |
| 2530 | </tr> |
| 2531 | <tr> |
| 2532 | <td>0</td> |
| 2533 | <td>1</td> |
| 2534 | <td>1</td> |
| 2535 | </tr> |
| 2536 | <tr> |
| 2537 | <td>1</td> |
| 2538 | <td>0</td> |
| 2539 | <td>1</td> |
| 2540 | </tr> |
| 2541 | <tr> |
| 2542 | <td>1</td> |
| 2543 | <td>1</td> |
| 2544 | <td>1</td> |
| 2545 | </tr> |
| 2546 | </tbody> |
| 2547 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2548 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2549 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2550 | <pre> <result> = or i32 4, %var <i>; yields {i32}:result = 4 | %var</i> |
| 2551 | <result> = or i32 15, 40 <i>; yields {i32}:result = 47</i> |
| 2552 | <result> = or i32 4, 8 <i>; yields {i32}:result = 12</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2553 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2554 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2555 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2556 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' |
| 2557 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2558 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2559 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2560 | <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2561 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2562 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2563 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive |
| 2564 | or of its two operands. The <tt>xor</tt> is used to implement the |
| 2565 | "one's complement" operation, which is the "~" operator in C.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2566 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2567 | <p>The two arguments to the '<tt>xor</tt>' instruction must be <a |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 2568 | href="#t_integer">integer</a> values. Both arguments must have |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2569 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2570 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2571 | <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] | 2572 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2573 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2574 | <table border="1" cellspacing="0" cellpadding="4"> |
| 2575 | <tbody> |
| 2576 | <tr> |
| 2577 | <td>In0</td> |
| 2578 | <td>In1</td> |
| 2579 | <td>Out</td> |
| 2580 | </tr> |
| 2581 | <tr> |
| 2582 | <td>0</td> |
| 2583 | <td>0</td> |
| 2584 | <td>0</td> |
| 2585 | </tr> |
| 2586 | <tr> |
| 2587 | <td>0</td> |
| 2588 | <td>1</td> |
| 2589 | <td>1</td> |
| 2590 | </tr> |
| 2591 | <tr> |
| 2592 | <td>1</td> |
| 2593 | <td>0</td> |
| 2594 | <td>1</td> |
| 2595 | </tr> |
| 2596 | <tr> |
| 2597 | <td>1</td> |
| 2598 | <td>1</td> |
| 2599 | <td>0</td> |
| 2600 | </tr> |
| 2601 | </tbody> |
| 2602 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2603 | </div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2604 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2605 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2606 | <pre> <result> = xor i32 4, %var <i>; yields {i32}:result = 4 ^ %var</i> |
| 2607 | <result> = xor i32 15, 40 <i>; yields {i32}:result = 39</i> |
| 2608 | <result> = xor i32 4, 8 <i>; yields {i32}:result = 12</i> |
| 2609 | <result> = xor i32 %V, -1 <i>; yields {i32}:result = ~%V</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2610 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2611 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2612 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2613 | <!-- ======================================================================= --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2614 | <div class="doc_subsection"> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2615 | <a name="vectorops">Vector Operations</a> |
| 2616 | </div> |
| 2617 | |
| 2618 | <div class="doc_text"> |
| 2619 | |
| 2620 | <p>LLVM supports several instructions to represent vector operations in a |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2621 | target-independent manner. These instructions cover the element-access and |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2622 | vector-specific operations needed to process vectors effectively. While LLVM |
| 2623 | does directly support these vector operations, many sophisticated algorithms |
| 2624 | will want to use target-specific intrinsics to take full advantage of a specific |
| 2625 | target.</p> |
| 2626 | |
| 2627 | </div> |
| 2628 | |
| 2629 | <!-- _______________________________________________________________________ --> |
| 2630 | <div class="doc_subsubsection"> |
| 2631 | <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a> |
| 2632 | </div> |
| 2633 | |
| 2634 | <div class="doc_text"> |
| 2635 | |
| 2636 | <h5>Syntax:</h5> |
| 2637 | |
| 2638 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2639 | <result> = extractelement <n x <ty>> <val>, i32 <idx> <i>; yields <ty></i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2640 | </pre> |
| 2641 | |
| 2642 | <h5>Overview:</h5> |
| 2643 | |
| 2644 | <p> |
| 2645 | The '<tt>extractelement</tt>' instruction extracts a single scalar |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2646 | element from a vector at a specified index. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2647 | </p> |
| 2648 | |
| 2649 | |
| 2650 | <h5>Arguments:</h5> |
| 2651 | |
| 2652 | <p> |
| 2653 | The first operand of an '<tt>extractelement</tt>' instruction is a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2654 | 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] | 2655 | an index indicating the position from which to extract the element. |
| 2656 | The index may be a variable.</p> |
| 2657 | |
| 2658 | <h5>Semantics:</h5> |
| 2659 | |
| 2660 | <p> |
| 2661 | The result is a scalar of the same type as the element type of |
| 2662 | <tt>val</tt>. Its value is the value at position <tt>idx</tt> of |
| 2663 | <tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the |
| 2664 | results are undefined. |
| 2665 | </p> |
| 2666 | |
| 2667 | <h5>Example:</h5> |
| 2668 | |
| 2669 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2670 | %result = extractelement <4 x i32> %vec, i32 0 <i>; yields i32</i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2671 | </pre> |
| 2672 | </div> |
| 2673 | |
| 2674 | |
| 2675 | <!-- _______________________________________________________________________ --> |
| 2676 | <div class="doc_subsubsection"> |
| 2677 | <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a> |
| 2678 | </div> |
| 2679 | |
| 2680 | <div class="doc_text"> |
| 2681 | |
| 2682 | <h5>Syntax:</h5> |
| 2683 | |
| 2684 | <pre> |
Dan Gohman | f3480b9 | 2008-05-12 23:38:42 +0000 | [diff] [blame^] | 2685 | <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] | 2686 | </pre> |
| 2687 | |
| 2688 | <h5>Overview:</h5> |
| 2689 | |
| 2690 | <p> |
| 2691 | The '<tt>insertelement</tt>' instruction inserts a scalar |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2692 | element into a vector at a specified index. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2693 | </p> |
| 2694 | |
| 2695 | |
| 2696 | <h5>Arguments:</h5> |
| 2697 | |
| 2698 | <p> |
| 2699 | The first operand of an '<tt>insertelement</tt>' instruction is a |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2700 | 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] | 2701 | scalar value whose type must equal the element type of the first |
| 2702 | operand. The third operand is an index indicating the position at |
| 2703 | which to insert the value. The index may be a variable.</p> |
| 2704 | |
| 2705 | <h5>Semantics:</h5> |
| 2706 | |
| 2707 | <p> |
Reid Spencer | 485bad1 | 2007-02-15 03:07:05 +0000 | [diff] [blame] | 2708 | 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] | 2709 | element values are those of <tt>val</tt> except at position |
| 2710 | <tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt> |
| 2711 | exceeds the length of <tt>val</tt>, the results are undefined. |
| 2712 | </p> |
| 2713 | |
| 2714 | <h5>Example:</h5> |
| 2715 | |
| 2716 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2717 | %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] | 2718 | </pre> |
| 2719 | </div> |
| 2720 | |
| 2721 | <!-- _______________________________________________________________________ --> |
| 2722 | <div class="doc_subsubsection"> |
| 2723 | <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a> |
| 2724 | </div> |
| 2725 | |
| 2726 | <div class="doc_text"> |
| 2727 | |
| 2728 | <h5>Syntax:</h5> |
| 2729 | |
| 2730 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2731 | <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x i32> <mask> <i>; yields <n x <ty>></i> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2732 | </pre> |
| 2733 | |
| 2734 | <h5>Overview:</h5> |
| 2735 | |
| 2736 | <p> |
| 2737 | The '<tt>shufflevector</tt>' instruction constructs a permutation of elements |
| 2738 | from two input vectors, returning a vector of the same type. |
| 2739 | </p> |
| 2740 | |
| 2741 | <h5>Arguments:</h5> |
| 2742 | |
| 2743 | <p> |
| 2744 | The first two operands of a '<tt>shufflevector</tt>' instruction are vectors |
| 2745 | with types that match each other and types that match the result of the |
| 2746 | instruction. The third argument is a shuffle mask, which has the same number |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2747 | of elements as the other vector type, but whose element type is always 'i32'. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2748 | </p> |
| 2749 | |
| 2750 | <p> |
| 2751 | The shuffle mask operand is required to be a constant vector with either |
| 2752 | constant integer or undef values. |
| 2753 | </p> |
| 2754 | |
| 2755 | <h5>Semantics:</h5> |
| 2756 | |
| 2757 | <p> |
| 2758 | The elements of the two input vectors are numbered from left to right across |
| 2759 | both of the vectors. The shuffle mask operand specifies, for each element of |
| 2760 | the result vector, which element of the two input registers the result element |
| 2761 | gets. The element selector may be undef (meaning "don't care") and the second |
| 2762 | operand may be undef if performing a shuffle from only one vector. |
| 2763 | </p> |
| 2764 | |
| 2765 | <h5>Example:</h5> |
| 2766 | |
| 2767 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2768 | %result = shufflevector <4 x i32> %v1, <4 x i32> %v2, |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2769 | <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] | 2770 | %result = shufflevector <4 x i32> %v1, <4 x i32> undef, |
| 2771 | <4 x i32> <i32 0, i32 1, i32 2, i32 3> <i>; yields <4 x i32></i> - Identity shuffle. |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2772 | </pre> |
| 2773 | </div> |
| 2774 | |
Tanya Lattner | 0947429 | 2006-04-14 19:24:33 +0000 | [diff] [blame] | 2775 | |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2776 | <!-- ======================================================================= --> |
| 2777 | <div class="doc_subsection"> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 2778 | <a name="memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2779 | </div> |
| 2780 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2781 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2782 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2783 | <p>A key design point of an SSA-based representation is how it |
| 2784 | represents memory. In LLVM, no memory locations are in SSA form, which |
| 2785 | makes things very simple. This section describes how to read, write, |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2786 | allocate, and free memory in LLVM.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2787 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2788 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2789 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2790 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2791 | <div class="doc_subsubsection"> |
| 2792 | <a name="i_malloc">'<tt>malloc</tt>' Instruction</a> |
| 2793 | </div> |
| 2794 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2795 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2796 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2797 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2798 | |
| 2799 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2800 | <result> = malloc <type>[, i32 <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2801 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2802 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2803 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2804 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2805 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 2806 | heap and returns a pointer to it. The object is always allocated in the generic |
| 2807 | address space (address space zero).</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2808 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2809 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2810 | |
| 2811 | <p>The '<tt>malloc</tt>' instruction allocates |
| 2812 | <tt>sizeof(<type>)*NumElements</tt> |
John Criswell | 6e4ca61 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 2813 | 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] | 2814 | appropriate type to the program. If "NumElements" is specified, it is the |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 2815 | number of elements allocated, otherwise "NumElements" is defaulted to be one. |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 2816 | If a constant alignment is specified, the value result of the allocation is guaranteed to |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 2817 | be aligned to at least that boundary. If not specified, or if zero, the target can |
| 2818 | choose to align the allocation on any convenient boundary.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2819 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2820 | <p>'<tt>type</tt>' must be a sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2821 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2822 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2823 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2824 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2825 | a pointer is returned. The result of a zero byte allocattion is undefined. The |
| 2826 | result is null if there is insufficient memory available.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2827 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2828 | <h5>Example:</h5> |
| 2829 | |
| 2830 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2831 | %array = malloc [4 x i8 ] <i>; yields {[%4 x i8]*}:array</i> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2832 | |
Bill Wendling | aac388b | 2007-05-29 09:42:13 +0000 | [diff] [blame] | 2833 | %size = <a href="#i_add">add</a> i32 2, 2 <i>; yields {i32}:size = i32 4</i> |
| 2834 | %array1 = malloc i8, i32 4 <i>; yields {i8*}:array1</i> |
| 2835 | %array2 = malloc [12 x i8], i32 %size <i>; yields {[12 x i8]*}:array2</i> |
| 2836 | %array3 = malloc i32, i32 4, align 1024 <i>; yields {i32*}:array3</i> |
| 2837 | %array4 = malloc i32, align 1024 <i>; yields {i32*}:array4</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2838 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2839 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2840 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2841 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2842 | <div class="doc_subsubsection"> |
| 2843 | <a name="i_free">'<tt>free</tt>' Instruction</a> |
| 2844 | </div> |
| 2845 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2846 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2847 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2848 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2849 | |
| 2850 | <pre> |
| 2851 | free <type> <value> <i>; yields {void}</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2852 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2853 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2854 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2855 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2856 | <p>The '<tt>free</tt>' instruction returns memory back to the unused |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2857 | memory heap to be reallocated in the future.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2858 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2859 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2860 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2861 | <p>'<tt>value</tt>' shall be a pointer value that points to a value |
| 2862 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' |
| 2863 | instruction.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2864 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2865 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2866 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2867 | <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] | 2868 | after this instruction executes. If the pointer is null, the operation |
| 2869 | is a noop.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2870 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2871 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2872 | |
| 2873 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2874 | %array = <a href="#i_malloc">malloc</a> [4 x i8] <i>; yields {[4 x i8]*}:array</i> |
| 2875 | free [4 x i8]* %array |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2876 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2877 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2878 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2879 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2880 | <div class="doc_subsubsection"> |
| 2881 | <a name="i_alloca">'<tt>alloca</tt>' Instruction</a> |
| 2882 | </div> |
| 2883 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2884 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2885 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2886 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2887 | |
| 2888 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2889 | <result> = alloca <type>[, i32 <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2890 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2891 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2892 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2893 | |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 2894 | <p>The '<tt>alloca</tt>' instruction allocates memory on the stack frame of the |
| 2895 | currently executing function, to be automatically released when this function |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 2896 | returns to its caller. The object is always allocated in the generic address |
| 2897 | space (address space zero).</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2898 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2899 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2900 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2901 | <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2902 | bytes of memory on the runtime stack, returning a pointer of the |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 2903 | appropriate type to the program. If "NumElements" is specified, it is the |
| 2904 | number of elements allocated, otherwise "NumElements" is defaulted to be one. |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 2905 | If a constant alignment is specified, the value result of the allocation is guaranteed |
Gabor Greif | 1acd2ee | 2008-02-09 22:24:34 +0000 | [diff] [blame] | 2906 | to be aligned to at least that boundary. If not specified, or if zero, the target |
| 2907 | can choose to align the allocation on any convenient boundary.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2908 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2909 | <p>'<tt>type</tt>' may be any sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2910 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2911 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2912 | |
Chris Lattner | 72ed200 | 2008-04-19 21:01:16 +0000 | [diff] [blame] | 2913 | <p>Memory is allocated; a pointer is returned. The operation is undefiend if |
| 2914 | there is insufficient stack space for the allocation. '<tt>alloca</tt>'d |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2915 | memory is automatically released when the function returns. The '<tt>alloca</tt>' |
| 2916 | instruction is commonly used to represent automatic variables that must |
| 2917 | 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] | 2918 | 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] | 2919 | instructions), the memory is reclaimed. Allocating zero bytes |
| 2920 | is legal, but the result is undefined.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2921 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2922 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2923 | |
| 2924 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2925 | %ptr = alloca i32 <i>; yields {i32*}:ptr</i> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 2926 | %ptr = alloca i32, i32 4 <i>; yields {i32*}:ptr</i> |
| 2927 | %ptr = alloca i32, i32 4, align 1024 <i>; yields {i32*}:ptr</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2928 | %ptr = alloca i32, align 1024 <i>; yields {i32*}:ptr</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2929 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2930 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2931 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2932 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2933 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' |
| 2934 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2935 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2936 | <h5>Syntax:</h5> |
Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 2937 | <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] | 2938 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2939 | <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] | 2940 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2941 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 2942 | address from which to load. The pointer must point to a <a |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 2943 | 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] | 2944 | 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] | 2945 | the number or order of execution of this <tt>load</tt> with other |
| 2946 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> |
| 2947 | instructions. </p> |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 2948 | <p> |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 2949 | The optional constant "align" argument specifies the alignment of the operation |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 2950 | (that is, the alignment of the memory address). A value of 0 or an |
| 2951 | omitted "align" argument means that the operation has the preferential |
| 2952 | alignment for the target. It is the responsibility of the code emitter |
| 2953 | to ensure that the alignment information is correct. Overestimating |
| 2954 | the alignment results in an undefined behavior. Underestimating the |
| 2955 | alignment may produce less efficient code. An alignment of 1 is always |
| 2956 | safe. |
| 2957 | </p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2958 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2959 | <p>The location of memory pointed to is loaded.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2960 | <h5>Examples:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2961 | <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] | 2962 | <a |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 2963 | href="#i_store">store</a> i32 3, i32* %ptr <i>; yields {void}</i> |
| 2964 | %val = load i32* %ptr <i>; yields {i32}:val = i32 3</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2965 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2966 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2967 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2968 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' |
| 2969 | Instruction</a> </div> |
Reid Spencer | 035ab57 | 2006-11-09 21:18:01 +0000 | [diff] [blame] | 2970 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2971 | <h5>Syntax:</h5> |
Christopher Lamb | 2330e4d | 2007-04-21 08:16:25 +0000 | [diff] [blame] | 2972 | <pre> store <ty> <value>, <ty>* <pointer>[, align <alignment>] <i>; yields {void}</i> |
| 2973 | volatile store <ty> <value>, <ty>* <pointer>[, align <alignment>] <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2974 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2975 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2976 | <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] | 2977 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2978 | <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] | 2979 | 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] | 2980 | operand must be a pointer to the <a href="#t_firstclass">first class</a> type |
| 2981 | of the '<tt><value></tt>' |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2982 | 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] | 2983 | optimizer is not allowed to modify the number or order of execution of |
| 2984 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a |
| 2985 | href="#i_store">store</a></tt> instructions.</p> |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 2986 | <p> |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 2987 | The optional constant "align" argument specifies the alignment of the operation |
Chris Lattner | a31d1d7 | 2008-01-06 21:04:43 +0000 | [diff] [blame] | 2988 | (that is, the alignment of the memory address). A value of 0 or an |
| 2989 | omitted "align" argument means that the operation has the preferential |
| 2990 | alignment for the target. It is the responsibility of the code emitter |
| 2991 | to ensure that the alignment information is correct. Overestimating |
| 2992 | the alignment results in an undefined behavior. Underestimating the |
| 2993 | alignment may produce less efficient code. An alignment of 1 is always |
| 2994 | safe. |
| 2995 | </p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2996 | <h5>Semantics:</h5> |
| 2997 | <p>The contents of memory are updated to contain '<tt><value></tt>' |
| 2998 | at the location specified by the '<tt><pointer></tt>' operand.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2999 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3000 | <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] | 3001 | store i32 3, i32* %ptr <i>; yields {void}</i> |
| 3002 | %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] | 3003 | </pre> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3004 | </div> |
| 3005 | |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 3006 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3007 | <div class="doc_subsubsection"> |
| 3008 | <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> |
| 3009 | </div> |
| 3010 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3011 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3012 | <h5>Syntax:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3013 | <pre> |
| 3014 | <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}* |
| 3015 | </pre> |
| 3016 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3017 | <h5>Overview:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3018 | |
| 3019 | <p> |
| 3020 | The '<tt>getelementptr</tt>' instruction is used to get the address of a |
| 3021 | subelement of an aggregate data structure.</p> |
| 3022 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3023 | <h5>Arguments:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3024 | |
Reid Spencer | 85f5b5b | 2006-12-04 21:29:24 +0000 | [diff] [blame] | 3025 | <p>This instruction takes a list of integer operands that indicate what |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3026 | elements of the aggregate object to index to. The actual types of the arguments |
| 3027 | provided depend on the type of the first pointer argument. The |
| 3028 | '<tt>getelementptr</tt>' instruction is used to index down through the type |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3029 | levels of a structure or to a specific index in an array. When indexing into a |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3030 | structure, only <tt>i32</tt> integer constants are allowed. When indexing |
Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 3031 | into an array or pointer, only integers of 32 or 64 bits are allowed; 32-bit |
| 3032 | values will be sign extended to 64-bits if required.</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3033 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3034 | <p>For example, let's consider a C code fragment and how it gets |
| 3035 | compiled to LLVM:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3036 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3037 | <div class="doc_code"> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3038 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3039 | struct RT { |
| 3040 | char A; |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3041 | int B[10][20]; |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3042 | char C; |
| 3043 | }; |
| 3044 | struct ST { |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3045 | int X; |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3046 | double Y; |
| 3047 | struct RT Z; |
| 3048 | }; |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3049 | |
Chris Lattner | cabc846 | 2007-05-29 15:43:56 +0000 | [diff] [blame] | 3050 | int *foo(struct ST *s) { |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3051 | return &s[1].Z.B[5][13]; |
| 3052 | } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3053 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3054 | </div> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3055 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3056 | <p>The LLVM code generated by the GCC frontend is:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3057 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3058 | <div class="doc_code"> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3059 | <pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3060 | %RT = type { i8 , [10 x [20 x i32]], i8 } |
| 3061 | %ST = type { i32, double, %RT } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3062 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3063 | define i32* %foo(%ST* %s) { |
| 3064 | entry: |
| 3065 | %reg = getelementptr %ST* %s, i32 1, i32 2, i32 1, i32 5, i32 13 |
| 3066 | ret i32* %reg |
| 3067 | } |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3068 | </pre> |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 3069 | </div> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3070 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3071 | <h5>Semantics:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3072 | |
| 3073 | <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 3074 | on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a> |
Reid Spencer | 85f5b5b | 2006-12-04 21:29:24 +0000 | [diff] [blame] | 3075 | and <a href="#t_array">array</a> types can use a 32-bit or 64-bit |
Reid Spencer | 42ddd84 | 2006-12-03 16:53:48 +0000 | [diff] [blame] | 3076 | <a href="#t_integer">integer</a> type but the value will always be sign extended |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3077 | to 64-bits. <a href="#t_struct">Structure</a> and <a href="#t_pstruct">packed |
| 3078 | structure</a> types require <tt>i32</tt> <b>constants</b>.</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3079 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3080 | <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] | 3081 | 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] | 3082 | }</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] | 3083 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ i8 , [10 x [20 x i32]], |
| 3084 | i8 }</tt>' type, another structure. The third index indexes into the second |
| 3085 | 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] | 3086 | array. The two dimensions of the array are subscripted into, yielding an |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3087 | '<tt>i32</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer |
| 3088 | 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] | 3089 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3090 | <p>Note that it is perfectly legal to index partially through a |
| 3091 | structure, returning a pointer to an inner element. Because of this, |
| 3092 | the LLVM code for the given testcase is equivalent to:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3093 | |
| 3094 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3095 | define i32* %foo(%ST* %s) { |
| 3096 | %t1 = getelementptr %ST* %s, i32 1 <i>; yields %ST*:%t1</i> |
Jeff Cohen | 6f1cc77 | 2007-04-22 01:17:39 +0000 | [diff] [blame] | 3097 | %t2 = getelementptr %ST* %t1, i32 0, i32 2 <i>; yields %RT*:%t2</i> |
| 3098 | %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] | 3099 | %t4 = getelementptr [10 x [20 x i32]]* %t3, i32 0, i32 5 <i>; yields [20 x i32]*:%t4</i> |
| 3100 | %t5 = getelementptr [20 x i32]* %t4, i32 0, i32 13 <i>; yields i32*:%t5</i> |
| 3101 | ret i32* %t5 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3102 | } |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3103 | </pre> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3104 | |
| 3105 | <p>Note that it is undefined to access an array out of bounds: array and |
| 3106 | pointer indexes must always be within the defined bounds of the array type. |
Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 3107 | The one exception for this rule is zero length arrays. These arrays are |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3108 | defined to be accessible as variable length arrays, which requires access |
| 3109 | beyond the zero'th element.</p> |
| 3110 | |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 3111 | <p>The getelementptr instruction is often confusing. For some more insight |
| 3112 | into how it works, see <a href="GetElementPtr.html">the getelementptr |
| 3113 | FAQ</a>.</p> |
| 3114 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 3115 | <h5>Example:</h5> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 3116 | |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3117 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3118 | <i>; yields [12 x i8]*:aptr</i> |
| 3119 | %aptr = getelementptr {i32, [12 x i8]}* %sptr, i64 0, i32 1 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3120 | </pre> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 3121 | </div> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame] | 3122 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3123 | <!-- ======================================================================= --> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3124 | <div class="doc_subsection"> <a name="convertops">Conversion Operations</a> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3125 | </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3126 | <div class="doc_text"> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3127 | <p>The instructions in this category are the conversion instructions (casting) |
| 3128 | which all take a single operand and a type. They perform various bit conversions |
| 3129 | on the operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3130 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3131 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3132 | <!-- _______________________________________________________________________ --> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3133 | <div class="doc_subsubsection"> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3134 | <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a> |
| 3135 | </div> |
| 3136 | <div class="doc_text"> |
| 3137 | |
| 3138 | <h5>Syntax:</h5> |
| 3139 | <pre> |
| 3140 | <result> = trunc <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3141 | </pre> |
| 3142 | |
| 3143 | <h5>Overview:</h5> |
| 3144 | <p> |
| 3145 | The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>. |
| 3146 | </p> |
| 3147 | |
| 3148 | <h5>Arguments:</h5> |
| 3149 | <p> |
| 3150 | The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must |
| 3151 | 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] | 3152 | 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] | 3153 | type. The bit size of <tt>value</tt> must be larger than the bit size of |
| 3154 | <tt>ty2</tt>. Equal sized types are not allowed.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3155 | |
| 3156 | <h5>Semantics:</h5> |
| 3157 | <p> |
| 3158 | 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] | 3159 | and converts the remaining bits to <tt>ty2</tt>. Since the source size must be |
| 3160 | larger than the destination size, <tt>trunc</tt> cannot be a <i>no-op cast</i>. |
| 3161 | It will always truncate bits.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3162 | |
| 3163 | <h5>Example:</h5> |
| 3164 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3165 | %X = trunc i32 257 to i8 <i>; yields i8:1</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3166 | %Y = trunc i32 123 to i1 <i>; yields i1:true</i> |
| 3167 | %Y = trunc i32 122 to i1 <i>; yields i1:false</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3168 | </pre> |
| 3169 | </div> |
| 3170 | |
| 3171 | <!-- _______________________________________________________________________ --> |
| 3172 | <div class="doc_subsubsection"> |
| 3173 | <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a> |
| 3174 | </div> |
| 3175 | <div class="doc_text"> |
| 3176 | |
| 3177 | <h5>Syntax:</h5> |
| 3178 | <pre> |
| 3179 | <result> = zext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3180 | </pre> |
| 3181 | |
| 3182 | <h5>Overview:</h5> |
| 3183 | <p>The '<tt>zext</tt>' instruction zero extends its operand to type |
| 3184 | <tt>ty2</tt>.</p> |
| 3185 | |
| 3186 | |
| 3187 | <h5>Arguments:</h5> |
| 3188 | <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] | 3189 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must |
| 3190 | 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] | 3191 | <tt>value</tt> must be smaller than the bit size of the destination type, |
| 3192 | <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3193 | |
| 3194 | <h5>Semantics:</h5> |
| 3195 | <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] | 3196 | 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] | 3197 | |
Reid Spencer | b592952 | 2007-01-12 15:46:11 +0000 | [diff] [blame] | 3198 | <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] | 3199 | |
| 3200 | <h5>Example:</h5> |
| 3201 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3202 | %X = zext i32 257 to i64 <i>; yields i64:257</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3203 | %Y = zext i1 true to i32 <i>; yields i32:1</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3204 | </pre> |
| 3205 | </div> |
| 3206 | |
| 3207 | <!-- _______________________________________________________________________ --> |
| 3208 | <div class="doc_subsubsection"> |
| 3209 | <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a> |
| 3210 | </div> |
| 3211 | <div class="doc_text"> |
| 3212 | |
| 3213 | <h5>Syntax:</h5> |
| 3214 | <pre> |
| 3215 | <result> = sext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3216 | </pre> |
| 3217 | |
| 3218 | <h5>Overview:</h5> |
| 3219 | <p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p> |
| 3220 | |
| 3221 | <h5>Arguments:</h5> |
| 3222 | <p> |
| 3223 | 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] | 3224 | <a href="#t_integer">integer</a> type, and a type to cast it to, which must |
| 3225 | 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] | 3226 | <tt>value</tt> must be smaller than the bit size of the destination type, |
| 3227 | <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3228 | |
| 3229 | <h5>Semantics:</h5> |
| 3230 | <p> |
| 3231 | The '<tt>sext</tt>' instruction performs a sign extension by copying the sign |
| 3232 | 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] | 3233 | the type <tt>ty2</tt>.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3234 | |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3235 | <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] | 3236 | |
| 3237 | <h5>Example:</h5> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3238 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3239 | %X = sext i8 -1 to i16 <i>; yields i16 :65535</i> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3240 | %Y = sext i1 true to i32 <i>; yields i32:-1</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3241 | </pre> |
| 3242 | </div> |
| 3243 | |
| 3244 | <!-- _______________________________________________________________________ --> |
| 3245 | <div class="doc_subsubsection"> |
Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 3246 | <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a> |
| 3247 | </div> |
| 3248 | |
| 3249 | <div class="doc_text"> |
| 3250 | |
| 3251 | <h5>Syntax:</h5> |
| 3252 | |
| 3253 | <pre> |
| 3254 | <result> = fptrunc <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3255 | </pre> |
| 3256 | |
| 3257 | <h5>Overview:</h5> |
| 3258 | <p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type |
| 3259 | <tt>ty2</tt>.</p> |
| 3260 | |
| 3261 | |
| 3262 | <h5>Arguments:</h5> |
| 3263 | <p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating |
| 3264 | point</a> value to cast and a <a href="#t_floating">floating point</a> type to |
| 3265 | cast it to. The size of <tt>value</tt> must be larger than the size of |
| 3266 | <tt>ty2</tt>. This implies that <tt>fptrunc</tt> cannot be used to make a |
| 3267 | <i>no-op cast</i>.</p> |
| 3268 | |
| 3269 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3270 | <p> The '<tt>fptrunc</tt>' instruction truncates a <tt>value</tt> from a larger |
| 3271 | <a href="#t_floating">floating point</a> type to a smaller |
| 3272 | <a href="#t_floating">floating point</a> type. If the value cannot fit within |
| 3273 | the destination type, <tt>ty2</tt>, then the results are undefined.</p> |
Reid Spencer | 3fa91b0 | 2006-11-09 21:48:10 +0000 | [diff] [blame] | 3274 | |
| 3275 | <h5>Example:</h5> |
| 3276 | <pre> |
| 3277 | %X = fptrunc double 123.0 to float <i>; yields float:123.0</i> |
| 3278 | %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i> |
| 3279 | </pre> |
| 3280 | </div> |
| 3281 | |
| 3282 | <!-- _______________________________________________________________________ --> |
| 3283 | <div class="doc_subsubsection"> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3284 | <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a> |
| 3285 | </div> |
| 3286 | <div class="doc_text"> |
| 3287 | |
| 3288 | <h5>Syntax:</h5> |
| 3289 | <pre> |
| 3290 | <result> = fpext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3291 | </pre> |
| 3292 | |
| 3293 | <h5>Overview:</h5> |
| 3294 | <p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger |
| 3295 | floating point value.</p> |
| 3296 | |
| 3297 | <h5>Arguments:</h5> |
| 3298 | <p>The '<tt>fpext</tt>' instruction takes a |
| 3299 | <a href="#t_floating">floating point</a> <tt>value</tt> to cast, |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3300 | and a <a href="#t_floating">floating point</a> type to cast it to. The source |
| 3301 | type must be smaller than the destination type.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3302 | |
| 3303 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3304 | <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] | 3305 | <a href="#t_floating">floating point</a> type to a larger |
| 3306 | <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] | 3307 | 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] | 3308 | <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] | 3309 | |
| 3310 | <h5>Example:</h5> |
| 3311 | <pre> |
| 3312 | %X = fpext float 3.1415 to double <i>; yields double:3.1415</i> |
| 3313 | %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i> |
| 3314 | </pre> |
| 3315 | </div> |
| 3316 | |
| 3317 | <!-- _______________________________________________________________________ --> |
| 3318 | <div class="doc_subsubsection"> |
Reid Spencer | 24d6da5 | 2007-01-21 00:29:26 +0000 | [diff] [blame] | 3319 | <a name="i_fptoui">'<tt>fptoui .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3320 | </div> |
| 3321 | <div class="doc_text"> |
| 3322 | |
| 3323 | <h5>Syntax:</h5> |
| 3324 | <pre> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3325 | <result> = fptoui <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3326 | </pre> |
| 3327 | |
| 3328 | <h5>Overview:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3329 | <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] | 3330 | unsigned integer equivalent of type <tt>ty2</tt>. |
| 3331 | </p> |
| 3332 | |
| 3333 | <h5>Arguments:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3334 | <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] | 3335 | scalar or vector <a href="#t_floating">floating point</a> value, and a type |
| 3336 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> |
| 3337 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a |
| 3338 | 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] | 3339 | |
| 3340 | <h5>Semantics:</h5> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3341 | <p> The '<tt>fptoui</tt>' instruction converts its |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3342 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 3343 | towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>, |
| 3344 | the results are undefined.</p> |
| 3345 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3346 | <h5>Example:</h5> |
| 3347 | <pre> |
Reid Spencer | 1539a1c | 2007-07-31 14:40:14 +0000 | [diff] [blame] | 3348 | %X = fptoui double 123.0 to i32 <i>; yields i32:123</i> |
Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 3349 | %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] | 3350 | %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] | 3351 | </pre> |
| 3352 | </div> |
| 3353 | |
| 3354 | <!-- _______________________________________________________________________ --> |
| 3355 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3356 | <a name="i_fptosi">'<tt>fptosi .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3357 | </div> |
| 3358 | <div class="doc_text"> |
| 3359 | |
| 3360 | <h5>Syntax:</h5> |
| 3361 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3362 | <result> = fptosi <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3363 | </pre> |
| 3364 | |
| 3365 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3366 | <p>The '<tt>fptosi</tt>' instruction converts |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3367 | <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] | 3368 | </p> |
| 3369 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3370 | <h5>Arguments:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3371 | <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] | 3372 | scalar or vector <a href="#t_floating">floating point</a> value, and a type |
| 3373 | to cast it to <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> |
| 3374 | type. If <tt>ty</tt> is a vector floating point type, <tt>ty2</tt> must be a |
| 3375 | 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] | 3376 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3377 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3378 | <p>The '<tt>fptosi</tt>' instruction converts its |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3379 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 3380 | towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>, |
| 3381 | the results are undefined.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3382 | |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3383 | <h5>Example:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3384 | <pre> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3385 | %X = fptosi double -123.0 to i32 <i>; yields i32:-123</i> |
Chris Lattner | 8851904 | 2007-09-22 03:17:52 +0000 | [diff] [blame] | 3386 | %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] | 3387 | %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] | 3388 | </pre> |
| 3389 | </div> |
| 3390 | |
| 3391 | <!-- _______________________________________________________________________ --> |
| 3392 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3393 | <a name="i_uitofp">'<tt>uitofp .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3394 | </div> |
| 3395 | <div class="doc_text"> |
| 3396 | |
| 3397 | <h5>Syntax:</h5> |
| 3398 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3399 | <result> = uitofp <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3400 | </pre> |
| 3401 | |
| 3402 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3403 | <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] | 3404 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 3405 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3406 | <h5>Arguments:</h5> |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3407 | <p>The '<tt>uitofp</tt>' instruction takes a value to cast, which must be a |
| 3408 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it |
| 3409 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a> |
| 3410 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector |
| 3411 | 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] | 3412 | |
| 3413 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3414 | <p>The '<tt>uitofp</tt>' instruction interprets its operand as an unsigned |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3415 | integer quantity and converts it to the corresponding floating point value. If |
Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 3416 | 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] | 3417 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3418 | <h5>Example:</h5> |
| 3419 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3420 | %X = uitofp i32 257 to float <i>; yields float:257.0</i> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3421 | %Y = uitofp i8 -1 to double <i>; yields double:255.0</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3422 | </pre> |
| 3423 | </div> |
| 3424 | |
| 3425 | <!-- _______________________________________________________________________ --> |
| 3426 | <div class="doc_subsubsection"> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3427 | <a name="i_sitofp">'<tt>sitofp .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3428 | </div> |
| 3429 | <div class="doc_text"> |
| 3430 | |
| 3431 | <h5>Syntax:</h5> |
| 3432 | <pre> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3433 | <result> = sitofp <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3434 | </pre> |
| 3435 | |
| 3436 | <h5>Overview:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3437 | <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] | 3438 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 3439 | |
| 3440 | <h5>Arguments:</h5> |
Nate Begeman | b348d18 | 2007-11-17 03:58:34 +0000 | [diff] [blame] | 3441 | <p>The '<tt>sitofp</tt>' instruction takes a value to cast, which must be a |
| 3442 | scalar or vector <a href="#t_integer">integer</a> value, and a type to cast it |
| 3443 | to <tt>ty2</tt>, which must be an <a href="#t_floating">floating point</a> |
| 3444 | type. If <tt>ty</tt> is a vector integer type, <tt>ty2</tt> must be a vector |
| 3445 | 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] | 3446 | |
| 3447 | <h5>Semantics:</h5> |
Reid Spencer | d444879 | 2006-11-09 23:03:26 +0000 | [diff] [blame] | 3448 | <p>The '<tt>sitofp</tt>' instruction interprets its operand as a signed |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3449 | integer quantity and converts it to the corresponding floating point value. If |
Jeff Cohen | cb75731 | 2007-04-22 14:56:37 +0000 | [diff] [blame] | 3450 | 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] | 3451 | |
| 3452 | <h5>Example:</h5> |
| 3453 | <pre> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3454 | %X = sitofp i32 257 to float <i>; yields float:257.0</i> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3455 | %Y = sitofp i8 -1 to double <i>; yields double:-1.0</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3456 | </pre> |
| 3457 | </div> |
| 3458 | |
| 3459 | <!-- _______________________________________________________________________ --> |
| 3460 | <div class="doc_subsubsection"> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3461 | <a name="i_ptrtoint">'<tt>ptrtoint .. to</tt>' Instruction</a> |
| 3462 | </div> |
| 3463 | <div class="doc_text"> |
| 3464 | |
| 3465 | <h5>Syntax:</h5> |
| 3466 | <pre> |
| 3467 | <result> = ptrtoint <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3468 | </pre> |
| 3469 | |
| 3470 | <h5>Overview:</h5> |
| 3471 | <p>The '<tt>ptrtoint</tt>' instruction converts the pointer <tt>value</tt> to |
| 3472 | the integer type <tt>ty2</tt>.</p> |
| 3473 | |
| 3474 | <h5>Arguments:</h5> |
| 3475 | <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] | 3476 | must be a <a href="#t_pointer">pointer</a> value, and a type to cast it to |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3477 | <tt>ty2</tt>, which must be an <a href="#t_integer">integer</a> type. |
| 3478 | |
| 3479 | <h5>Semantics:</h5> |
| 3480 | <p>The '<tt>ptrtoint</tt>' instruction converts <tt>value</tt> to integer type |
| 3481 | <tt>ty2</tt> by interpreting the pointer value as an integer and either |
| 3482 | truncating or zero extending that value to the size of the integer type. If |
| 3483 | <tt>value</tt> is smaller than <tt>ty2</tt> then a zero extension is done. If |
| 3484 | <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] | 3485 | are the same size, then nothing is done (<i>no-op cast</i>) other than a type |
| 3486 | change.</p> |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3487 | |
| 3488 | <h5>Example:</h5> |
| 3489 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3490 | %X = ptrtoint i32* %X to i8 <i>; yields truncation on 32-bit architecture</i> |
| 3491 | %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] | 3492 | </pre> |
| 3493 | </div> |
| 3494 | |
| 3495 | <!-- _______________________________________________________________________ --> |
| 3496 | <div class="doc_subsubsection"> |
| 3497 | <a name="i_inttoptr">'<tt>inttoptr .. to</tt>' Instruction</a> |
| 3498 | </div> |
| 3499 | <div class="doc_text"> |
| 3500 | |
| 3501 | <h5>Syntax:</h5> |
| 3502 | <pre> |
| 3503 | <result> = inttoptr <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3504 | </pre> |
| 3505 | |
| 3506 | <h5>Overview:</h5> |
| 3507 | <p>The '<tt>inttoptr</tt>' instruction converts an integer <tt>value</tt> to |
| 3508 | a pointer type, <tt>ty2</tt>.</p> |
| 3509 | |
| 3510 | <h5>Arguments:</h5> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 3511 | <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] | 3512 | value to cast, and a type to cast it to, which must be a |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 3513 | <a href="#t_pointer">pointer</a> type. |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3514 | |
| 3515 | <h5>Semantics:</h5> |
| 3516 | <p>The '<tt>inttoptr</tt>' instruction converts <tt>value</tt> to type |
| 3517 | <tt>ty2</tt> by applying either a zero extension or a truncation depending on |
| 3518 | the size of the integer <tt>value</tt>. If <tt>value</tt> is larger than the |
| 3519 | size of a pointer then a truncation is done. If <tt>value</tt> is smaller than |
| 3520 | the size of a pointer then a zero extension is done. If they are the same size, |
| 3521 | nothing is done (<i>no-op cast</i>).</p> |
| 3522 | |
| 3523 | <h5>Example:</h5> |
| 3524 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3525 | %X = inttoptr i32 255 to i32* <i>; yields zero extension on 64-bit architecture</i> |
| 3526 | %X = inttoptr i32 255 to i32* <i>; yields no-op on 32-bit architecture</i> |
| 3527 | %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] | 3528 | </pre> |
| 3529 | </div> |
| 3530 | |
| 3531 | <!-- _______________________________________________________________________ --> |
| 3532 | <div class="doc_subsubsection"> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3533 | <a name="i_bitcast">'<tt>bitcast .. to</tt>' Instruction</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3534 | </div> |
| 3535 | <div class="doc_text"> |
| 3536 | |
| 3537 | <h5>Syntax:</h5> |
| 3538 | <pre> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3539 | <result> = bitcast <ty> <value> to <ty2> <i>; yields ty2</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3540 | </pre> |
| 3541 | |
| 3542 | <h5>Overview:</h5> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3543 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3544 | <tt>ty2</tt> without changing any bits.</p> |
| 3545 | |
| 3546 | <h5>Arguments:</h5> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3547 | <p>The '<tt>bitcast</tt>' instruction takes a value to cast, which must be |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3548 | a first class value, and a type to cast it to, which must also be a <a |
| 3549 | href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt> |
Reid Spencer | 19b569f | 2007-01-09 20:08:58 +0000 | [diff] [blame] | 3550 | and the destination type, <tt>ty2</tt>, must be identical. If the source |
| 3551 | type is a pointer, the destination type must also be a pointer.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3552 | |
| 3553 | <h5>Semantics:</h5> |
Reid Spencer | 5c0ef47 | 2006-11-11 23:08:07 +0000 | [diff] [blame] | 3554 | <p>The '<tt>bitcast</tt>' instruction converts <tt>value</tt> to type |
Reid Spencer | 7267925 | 2006-11-11 21:00:47 +0000 | [diff] [blame] | 3555 | <tt>ty2</tt>. It is always a <i>no-op cast</i> because no bits change with |
| 3556 | this conversion. The conversion is done as if the <tt>value</tt> had been |
| 3557 | stored to memory and read back as type <tt>ty2</tt>. Pointer types may only be |
| 3558 | converted to other pointer types with this instruction. To convert pointers to |
| 3559 | other types, use the <a href="#i_inttoptr">inttoptr</a> or |
| 3560 | <a href="#i_ptrtoint">ptrtoint</a> instructions first.</p> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3561 | |
| 3562 | <h5>Example:</h5> |
| 3563 | <pre> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3564 | %X = bitcast i8 255 to i8 <i>; yields i8 :-1</i> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3565 | %Y = bitcast i32* %x to sint* <i>; yields sint*:%x</i> |
| 3566 | %Z = bitcast <2xint> %V to i64; <i>; yields i64: %V</i> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3567 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3568 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3569 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3570 | <!-- ======================================================================= --> |
| 3571 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> |
| 3572 | <div class="doc_text"> |
| 3573 | <p>The instructions in this category are the "miscellaneous" |
| 3574 | instructions, which defy better classification.</p> |
| 3575 | </div> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3576 | |
| 3577 | <!-- _______________________________________________________________________ --> |
| 3578 | <div class="doc_subsubsection"><a name="i_icmp">'<tt>icmp</tt>' Instruction</a> |
| 3579 | </div> |
| 3580 | <div class="doc_text"> |
| 3581 | <h5>Syntax:</h5> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3582 | <pre> <result> = icmp <cond> <ty> <var1>, <var2> <i>; yields {i1}:result</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3583 | </pre> |
| 3584 | <h5>Overview:</h5> |
| 3585 | <p>The '<tt>icmp</tt>' instruction returns a boolean value based on comparison |
Chris Lattner | 4316dec | 2008-04-02 00:38:26 +0000 | [diff] [blame] | 3586 | of its two integer or pointer operands.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3587 | <h5>Arguments:</h5> |
| 3588 | <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] | 3589 | the condition code indicating the kind of comparison to perform. It is not |
| 3590 | a value, just a keyword. The possible condition code are: |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3591 | <ol> |
| 3592 | <li><tt>eq</tt>: equal</li> |
| 3593 | <li><tt>ne</tt>: not equal </li> |
| 3594 | <li><tt>ugt</tt>: unsigned greater than</li> |
| 3595 | <li><tt>uge</tt>: unsigned greater or equal</li> |
| 3596 | <li><tt>ult</tt>: unsigned less than</li> |
| 3597 | <li><tt>ule</tt>: unsigned less or equal</li> |
| 3598 | <li><tt>sgt</tt>: signed greater than</li> |
| 3599 | <li><tt>sge</tt>: signed greater or equal</li> |
| 3600 | <li><tt>slt</tt>: signed less than</li> |
| 3601 | <li><tt>sle</tt>: signed less or equal</li> |
| 3602 | </ol> |
Chris Lattner | 3b19d65 | 2007-01-15 01:54:13 +0000 | [diff] [blame] | 3603 | <p>The remaining two arguments must be <a href="#t_integer">integer</a> or |
Reid Spencer | 350f8aa | 2007-01-04 05:19:58 +0000 | [diff] [blame] | 3604 | <a href="#t_pointer">pointer</a> typed. They must also be identical types.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3605 | <h5>Semantics:</h5> |
| 3606 | <p>The '<tt>icmp</tt>' compares <tt>var1</tt> and <tt>var2</tt> according to |
| 3607 | the condition code given as <tt>cond</tt>. The comparison performed always |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3608 | yields a <a href="#t_primitive">i1</a> result, as follows: |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3609 | <ol> |
| 3610 | <li><tt>eq</tt>: yields <tt>true</tt> if the operands are equal, |
| 3611 | <tt>false</tt> otherwise. No sign interpretation is necessary or performed. |
| 3612 | </li> |
| 3613 | <li><tt>ne</tt>: yields <tt>true</tt> if the operands are unequal, |
| 3614 | <tt>false</tt> otherwise. No sign interpretation is necessary or performed. |
| 3615 | <li><tt>ugt</tt>: interprets the operands as unsigned values and yields |
| 3616 | <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li> |
| 3617 | <li><tt>uge</tt>: interprets the operands as unsigned values and yields |
| 3618 | <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> |
| 3619 | <li><tt>ult</tt>: interprets the operands as unsigned values and yields |
| 3620 | <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li> |
| 3621 | <li><tt>ule</tt>: interprets the operands as unsigned values and yields |
| 3622 | <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> |
| 3623 | <li><tt>sgt</tt>: interprets the operands as signed values and yields |
| 3624 | <tt>true</tt> if <tt>var1</tt> is greater than <tt>var2</tt>.</li> |
| 3625 | <li><tt>sge</tt>: interprets the operands as signed values and yields |
| 3626 | <tt>true</tt> if <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> |
| 3627 | <li><tt>slt</tt>: interprets the operands as signed values and yields |
| 3628 | <tt>true</tt> if <tt>var1</tt> is less than <tt>var2</tt>.</li> |
| 3629 | <li><tt>sle</tt>: interprets the operands as signed values and yields |
| 3630 | <tt>true</tt> if <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3631 | </ol> |
| 3632 | <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] | 3633 | values are compared as if they were integers.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3634 | |
| 3635 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3636 | <pre> <result> = icmp eq i32 4, 5 <i>; yields: result=false</i> |
| 3637 | <result> = icmp ne float* %X, %X <i>; yields: result=false</i> |
| 3638 | <result> = icmp ult i16 4, 5 <i>; yields: result=true</i> |
| 3639 | <result> = icmp sgt i16 4, 5 <i>; yields: result=false</i> |
| 3640 | <result> = icmp ule i16 -4, 5 <i>; yields: result=false</i> |
| 3641 | <result> = icmp sge i16 4, 5 <i>; yields: result=false</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3642 | </pre> |
| 3643 | </div> |
| 3644 | |
| 3645 | <!-- _______________________________________________________________________ --> |
| 3646 | <div class="doc_subsubsection"><a name="i_fcmp">'<tt>fcmp</tt>' Instruction</a> |
| 3647 | </div> |
| 3648 | <div class="doc_text"> |
| 3649 | <h5>Syntax:</h5> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3650 | <pre> <result> = fcmp <cond> <ty> <var1>, <var2> <i>; yields {i1}:result</i> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3651 | </pre> |
| 3652 | <h5>Overview:</h5> |
| 3653 | <p>The '<tt>fcmp</tt>' instruction returns a boolean value based on comparison |
| 3654 | of its floating point operands.</p> |
| 3655 | <h5>Arguments:</h5> |
| 3656 | <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] | 3657 | the condition code indicating the kind of comparison to perform. It is not |
| 3658 | a value, just a keyword. The possible condition code are: |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3659 | <ol> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3660 | <li><tt>false</tt>: no comparison, always returns false</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3661 | <li><tt>oeq</tt>: ordered and equal</li> |
| 3662 | <li><tt>ogt</tt>: ordered and greater than </li> |
| 3663 | <li><tt>oge</tt>: ordered and greater than or equal</li> |
| 3664 | <li><tt>olt</tt>: ordered and less than </li> |
| 3665 | <li><tt>ole</tt>: ordered and less than or equal</li> |
| 3666 | <li><tt>one</tt>: ordered and not equal</li> |
| 3667 | <li><tt>ord</tt>: ordered (no nans)</li> |
| 3668 | <li><tt>ueq</tt>: unordered or equal</li> |
| 3669 | <li><tt>ugt</tt>: unordered or greater than </li> |
| 3670 | <li><tt>uge</tt>: unordered or greater than or equal</li> |
| 3671 | <li><tt>ult</tt>: unordered or less than </li> |
| 3672 | <li><tt>ule</tt>: unordered or less than or equal</li> |
| 3673 | <li><tt>une</tt>: unordered or not equal</li> |
| 3674 | <li><tt>uno</tt>: unordered (either nans)</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3675 | <li><tt>true</tt>: no comparison, always returns true</li> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3676 | </ol> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3677 | <p><i>Ordered</i> means that neither operand is a QNAN while |
Reid Spencer | 93a4985 | 2006-12-06 07:08:07 +0000 | [diff] [blame] | 3678 | <i>unordered</i> means that either operand may be a QNAN.</p> |
Reid Spencer | 350f8aa | 2007-01-04 05:19:58 +0000 | [diff] [blame] | 3679 | <p>The <tt>val1</tt> and <tt>val2</tt> arguments must be |
| 3680 | <a href="#t_floating">floating point</a> typed. They must have identical |
| 3681 | types.</p> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3682 | <h5>Semantics:</h5> |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3683 | <p>The '<tt>fcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> |
| 3684 | according to the condition code given as <tt>cond</tt>. The comparison performed |
| 3685 | always yields a <a href="#t_primitive">i1</a> result, as follows: |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3686 | <ol> |
| 3687 | <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] | 3688 | <li><tt>oeq</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3689 | <tt>var1</tt> is equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3690 | <li><tt>ogt</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3691 | <tt>var1</tt> is greather than <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3692 | <li><tt>oge</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3693 | <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3694 | <li><tt>olt</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3695 | <tt>var1</tt> is less than <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3696 | <li><tt>ole</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3697 | <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3698 | <li><tt>one</tt>: yields <tt>true</tt> if both operands are not a QNAN and |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3699 | <tt>var1</tt> is not equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3700 | <li><tt>ord</tt>: yields <tt>true</tt> if both operands are not a QNAN.</li> |
| 3701 | <li><tt>ueq</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3702 | <tt>var1</tt> is equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3703 | <li><tt>ugt</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3704 | <tt>var1</tt> is greater than <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3705 | <li><tt>uge</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3706 | <tt>var1</tt> is greater than or equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3707 | <li><tt>ult</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3708 | <tt>var1</tt> is less than <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3709 | <li><tt>ule</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3710 | <tt>var1</tt> is less than or equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3711 | <li><tt>une</tt>: yields <tt>true</tt> if either operand is a QNAN or |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3712 | <tt>var1</tt> is not equal to <tt>var2</tt>.</li> |
Reid Spencer | b7f2628 | 2006-11-19 03:00:14 +0000 | [diff] [blame] | 3713 | <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] | 3714 | <li><tt>true</tt>: always yields <tt>true</tt>, regardless of operands.</li> |
| 3715 | </ol> |
Reid Spencer | f3a70a6 | 2006-11-18 21:50:54 +0000 | [diff] [blame] | 3716 | |
| 3717 | <h5>Example:</h5> |
| 3718 | <pre> <result> = fcmp oeq float 4.0, 5.0 <i>; yields: result=false</i> |
| 3719 | <result> = icmp one float 4.0, 5.0 <i>; yields: result=true</i> |
| 3720 | <result> = icmp olt float 4.0, 5.0 <i>; yields: result=true</i> |
| 3721 | <result> = icmp ueq double 1.0, 2.0 <i>; yields: result=false</i> |
| 3722 | </pre> |
| 3723 | </div> |
| 3724 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3725 | <!-- _______________________________________________________________________ --> |
Nate Begeman | ac80ade | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 3726 | <div class="doc_subsubsection"> |
| 3727 | <a name="i_vicmp">'<tt>vicmp</tt>' Instruction</a> |
| 3728 | </div> |
| 3729 | <div class="doc_text"> |
| 3730 | <h5>Syntax:</h5> |
| 3731 | <pre> <result> = vicmp <cond> <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 3732 | </pre> |
| 3733 | <h5>Overview:</h5> |
| 3734 | <p>The '<tt>vicmp</tt>' instruction returns an integer vector value based on |
| 3735 | element-wise comparison of its two integer vector operands.</p> |
| 3736 | <h5>Arguments:</h5> |
| 3737 | <p>The '<tt>vicmp</tt>' instruction takes three operands. The first operand is |
| 3738 | the condition code indicating the kind of comparison to perform. It is not |
| 3739 | a value, just a keyword. The possible condition code are: |
| 3740 | <ol> |
| 3741 | <li><tt>eq</tt>: equal</li> |
| 3742 | <li><tt>ne</tt>: not equal </li> |
| 3743 | <li><tt>ugt</tt>: unsigned greater than</li> |
| 3744 | <li><tt>uge</tt>: unsigned greater or equal</li> |
| 3745 | <li><tt>ult</tt>: unsigned less than</li> |
| 3746 | <li><tt>ule</tt>: unsigned less or equal</li> |
| 3747 | <li><tt>sgt</tt>: signed greater than</li> |
| 3748 | <li><tt>sge</tt>: signed greater or equal</li> |
| 3749 | <li><tt>slt</tt>: signed less than</li> |
| 3750 | <li><tt>sle</tt>: signed less or equal</li> |
| 3751 | </ol> |
| 3752 | <p>The remaining two arguments must be <a href="#t_vector">vector</a> of |
| 3753 | <a href="#t_integer">integer</a> typed. They must also be identical types.</p> |
| 3754 | <h5>Semantics:</h5> |
| 3755 | <p>The '<tt>vicmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> |
| 3756 | according to the condition code given as <tt>cond</tt>. The comparison yields a |
| 3757 | <a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, of |
| 3758 | identical type as the values being compared. The most significant bit in each |
| 3759 | element is 1 if the element-wise comparison evaluates to true, and is 0 |
| 3760 | otherwise. All other bits of the result are undefined. The condition codes |
| 3761 | are evaluated identically to the <a href="#i_icmp">'<tt>icmp</tt>' |
| 3762 | instruction</a>. |
| 3763 | |
| 3764 | <h5>Example:</h5> |
| 3765 | <pre> |
| 3766 | <result> = vicmp eq <2 x i32> < i32 4, i32 0 >, < i32 5, i32 0 > <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i> |
| 3767 | <result> = vicmp ult <2 x i8> < i8 1, i8 2 >, < i8 2, i8 2> <i>; yields: result=<2 x i8> < i8 -1, i8 0 ></i> |
| 3768 | </pre> |
| 3769 | </div> |
| 3770 | |
| 3771 | <!-- _______________________________________________________________________ --> |
| 3772 | <div class="doc_subsubsection"> |
| 3773 | <a name="i_vfcmp">'<tt>vfcmp</tt>' Instruction</a> |
| 3774 | </div> |
| 3775 | <div class="doc_text"> |
| 3776 | <h5>Syntax:</h5> |
| 3777 | <pre> <result> = vfcmp <cond> <ty> <var1>, <var2></pre> |
| 3778 | <h5>Overview:</h5> |
| 3779 | <p>The '<tt>vfcmp</tt>' instruction returns an integer vector value based on |
| 3780 | element-wise comparison of its two floating point vector operands. The output |
| 3781 | elements have the same width as the input elements.</p> |
| 3782 | <h5>Arguments:</h5> |
| 3783 | <p>The '<tt>vfcmp</tt>' instruction takes three operands. The first operand is |
| 3784 | the condition code indicating the kind of comparison to perform. It is not |
| 3785 | a value, just a keyword. The possible condition code are: |
| 3786 | <ol> |
| 3787 | <li><tt>false</tt>: no comparison, always returns false</li> |
| 3788 | <li><tt>oeq</tt>: ordered and equal</li> |
| 3789 | <li><tt>ogt</tt>: ordered and greater than </li> |
| 3790 | <li><tt>oge</tt>: ordered and greater than or equal</li> |
| 3791 | <li><tt>olt</tt>: ordered and less than </li> |
| 3792 | <li><tt>ole</tt>: ordered and less than or equal</li> |
| 3793 | <li><tt>one</tt>: ordered and not equal</li> |
| 3794 | <li><tt>ord</tt>: ordered (no nans)</li> |
| 3795 | <li><tt>ueq</tt>: unordered or equal</li> |
| 3796 | <li><tt>ugt</tt>: unordered or greater than </li> |
| 3797 | <li><tt>uge</tt>: unordered or greater than or equal</li> |
| 3798 | <li><tt>ult</tt>: unordered or less than </li> |
| 3799 | <li><tt>ule</tt>: unordered or less than or equal</li> |
| 3800 | <li><tt>une</tt>: unordered or not equal</li> |
| 3801 | <li><tt>uno</tt>: unordered (either nans)</li> |
| 3802 | <li><tt>true</tt>: no comparison, always returns true</li> |
| 3803 | </ol> |
| 3804 | <p>The remaining two arguments must be <a href="#t_vector">vector</a> of |
| 3805 | <a href="#t_floating">floating point</a> typed. They must also be identical |
| 3806 | types.</p> |
| 3807 | <h5>Semantics:</h5> |
| 3808 | <p>The '<tt>vfcmp</tt>' instruction compares <tt>var1</tt> and <tt>var2</tt> |
| 3809 | according to the condition code given as <tt>cond</tt>. The comparison yields a |
| 3810 | <a href="#t_vector">vector</a> of <a href="#t_integer">integer</a> result, with |
| 3811 | an identical number of elements as the values being compared, and each element |
| 3812 | having identical with to the width of the floating point elements. The most |
| 3813 | significant bit in each element is 1 if the element-wise comparison evaluates to |
| 3814 | true, and is 0 otherwise. All other bits of the result are undefined. The |
| 3815 | condition codes are evaluated identically to the |
| 3816 | <a href="#i_fcmp">'<tt>fcmp</tt>' instruction</a>. |
| 3817 | |
| 3818 | <h5>Example:</h5> |
| 3819 | <pre> |
| 3820 | <result> = vfcmp oeq <2 x float> < float 4, float 0 >, < float 5, float 0 > <i>; yields: result=<2 x i32> < i32 0, i32 -1 ></i> |
| 3821 | <result> = vfcmp ult <2 x double> < double 1, double 2 >, < double 2, double 2> <i>; yields: result=<2 x i64> < i64 -1, i64 0 ></i> |
| 3822 | </pre> |
| 3823 | </div> |
| 3824 | |
| 3825 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3826 | <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>' |
| 3827 | Instruction</a> </div> |
| 3828 | <div class="doc_text"> |
| 3829 | <h5>Syntax:</h5> |
| 3830 | <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> |
| 3831 | <h5>Overview:</h5> |
| 3832 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in |
| 3833 | the SSA graph representing the function.</p> |
| 3834 | <h5>Arguments:</h5> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3835 | <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] | 3836 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs |
| 3837 | as arguments, with one pair for each predecessor basic block of the |
| 3838 | current block. Only values of <a href="#t_firstclass">first class</a> |
| 3839 | type may be used as the value arguments to the PHI node. Only labels |
| 3840 | may be used as the label arguments.</p> |
| 3841 | <p>There must be no non-phi instructions between the start of a basic |
| 3842 | block and the PHI instructions: i.e. PHI instructions must be first in |
| 3843 | a basic block.</p> |
| 3844 | <h5>Semantics:</h5> |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 3845 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the value |
| 3846 | specified by the pair corresponding to the predecessor basic block that executed |
| 3847 | just prior to the current block.</p> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3848 | <h5>Example:</h5> |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 3849 | <pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi i32 [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add i32 %indvar, 1<br> br label %Loop<br></pre> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3850 | </div> |
| 3851 | |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3852 | <!-- _______________________________________________________________________ --> |
| 3853 | <div class="doc_subsubsection"> |
| 3854 | <a name="i_select">'<tt>select</tt>' Instruction</a> |
| 3855 | </div> |
| 3856 | |
| 3857 | <div class="doc_text"> |
| 3858 | |
| 3859 | <h5>Syntax:</h5> |
| 3860 | |
| 3861 | <pre> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3862 | <result> = select i1 <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3863 | </pre> |
| 3864 | |
| 3865 | <h5>Overview:</h5> |
| 3866 | |
| 3867 | <p> |
| 3868 | The '<tt>select</tt>' instruction is used to choose one value based on a |
| 3869 | condition, without branching. |
| 3870 | </p> |
| 3871 | |
| 3872 | |
| 3873 | <h5>Arguments:</h5> |
| 3874 | |
| 3875 | <p> |
| 3876 | The '<tt>select</tt>' instruction requires a boolean value indicating the condition, and two values of the same <a href="#t_firstclass">first class</a> type. |
| 3877 | </p> |
| 3878 | |
| 3879 | <h5>Semantics:</h5> |
| 3880 | |
| 3881 | <p> |
| 3882 | If the boolean condition evaluates to true, the instruction returns the first |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3883 | value argument; otherwise, it returns the second value argument. |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3884 | </p> |
| 3885 | |
| 3886 | <h5>Example:</h5> |
| 3887 | |
| 3888 | <pre> |
Reid Spencer | c78f337 | 2007-01-12 03:35:51 +0000 | [diff] [blame] | 3889 | %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] | 3890 | </pre> |
| 3891 | </div> |
| 3892 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 3893 | |
| 3894 | <!-- _______________________________________________________________________ --> |
| 3895 | <div class="doc_subsubsection"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3896 | <a name="i_call">'<tt>call</tt>' Instruction</a> |
| 3897 | </div> |
| 3898 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3899 | <div class="doc_text"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3900 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3901 | <h5>Syntax:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3902 | <pre> |
Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 3903 | <result> = [tail] call [<a href="#callingconv">cconv</a>] <ty> [<fnty>*] <fnptrval>(<param list>) |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3904 | </pre> |
| 3905 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3906 | <h5>Overview:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3907 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3908 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3909 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3910 | <h5>Arguments:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3911 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3912 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3913 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3914 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3915 | <li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3916 | <p>The optional "tail" marker indicates whether the callee function accesses |
| 3917 | 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] | 3918 | function call is eligible for tail call optimization. Note that calls may |
| 3919 | be marked "tail" even if they do not occur before a <a |
| 3920 | href="#i_ret"><tt>ret</tt></a> instruction. |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3921 | </li> |
| 3922 | <li> |
Duncan Sands | 8036ca4 | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 3923 | <p>The optional "cconv" marker indicates which <a href="#callingconv">calling |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3924 | convention</a> the call should use. If none is specified, the call defaults |
| 3925 | to using C calling conventions. |
| 3926 | </li> |
| 3927 | <li> |
Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 3928 | <p>'<tt>ty</tt>': the type of the call instruction itself which is also |
| 3929 | the type of the return value. Functions that return no value are marked |
| 3930 | <tt><a href="#t_void">void</a></tt>.</p> |
| 3931 | </li> |
| 3932 | <li> |
| 3933 | <p>'<tt>fnty</tt>': shall be the signature of the pointer to function |
| 3934 | value being invoked. The argument types must match the types implied by |
| 3935 | this signature. This type can be omitted if the function is not varargs |
| 3936 | 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] | 3937 | </li> |
| 3938 | <li> |
| 3939 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to |
| 3940 | be invoked. In most cases, this is a direct function invocation, but |
| 3941 | 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] | 3942 | to function value.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3943 | </li> |
| 3944 | <li> |
| 3945 | <p>'<tt>function args</tt>': argument list whose types match the |
Reid Spencer | a7e302a | 2005-05-01 22:22:57 +0000 | [diff] [blame] | 3946 | function signature argument types. All arguments must be of |
| 3947 | <a href="#t_firstclass">first class</a> type. If the function signature |
| 3948 | indicates the function accepts a variable number of arguments, the extra |
| 3949 | arguments can be specified.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3950 | </li> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3951 | </ol> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3952 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3953 | <h5>Semantics:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3954 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3955 | <p>The '<tt>call</tt>' instruction is used to cause control flow to |
| 3956 | transfer to a specified function, with its incoming arguments bound to |
| 3957 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' |
| 3958 | instruction in the called function, control flow continues with the |
| 3959 | instruction after the function call, and the return value of the |
Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 3960 | function is bound to the result argument. If the callee returns multiple |
| 3961 | values then the return values of the function are only accessible through |
| 3962 | the '<tt><a href="#i_getresult">getresult</a></tt>' instruction.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3963 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3964 | <h5>Example:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3965 | |
| 3966 | <pre> |
Nick Lewycky | db7e3c9 | 2007-09-08 13:57:50 +0000 | [diff] [blame] | 3967 | %retval = call i32 @test(i32 %argc) |
Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 3968 | call i32 (i8 *, ...)* @printf(i8 * %msg, i32 12, i8 42) <i>; yields i32</i> |
| 3969 | %X = tail call i32 @foo() <i>; yields i32</i> |
| 3970 | %Y = tail call <a href="#callingconv">fastcc</a> i32 @foo() <i>; yields i32</i> |
| 3971 | call void %foo(i8 97 signext) |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 3972 | |
| 3973 | %struct.A = type { i32, i8 } |
Chris Lattner | 772fccf | 2008-03-21 17:24:17 +0000 | [diff] [blame] | 3974 | %r = call %struct.A @foo() <i>; yields { 32, i8 }</i> |
| 3975 | %gr = getresult %struct.A %r, 0 <i>; yields i32</i> |
| 3976 | %gr1 = getresult %struct.A %r, 1 <i>; yields i8</i> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3977 | </pre> |
| 3978 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3979 | </div> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3980 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3981 | <!-- _______________________________________________________________________ --> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3982 | <div class="doc_subsubsection"> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 3983 | <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3984 | </div> |
| 3985 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3986 | <div class="doc_text"> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3987 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3988 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3989 | |
| 3990 | <pre> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3991 | <resultval> = va_arg <va_list*> <arglist>, <argty> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3992 | </pre> |
| 3993 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3994 | <h5>Overview:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3995 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3996 | <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] | 3997 | the "variable argument" area of a function call. It is used to implement the |
| 3998 | <tt>va_arg</tt> macro in C.</p> |
| 3999 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4000 | <h5>Arguments:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4001 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4002 | <p>This instruction takes a <tt>va_list*</tt> value and the type of |
| 4003 | the argument. It returns a value of the specified argument type and |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4004 | 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] | 4005 | actual type of <tt>va_list</tt> is target specific.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4006 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4007 | <h5>Semantics:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4008 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4009 | <p>The '<tt>va_arg</tt>' instruction loads an argument of the specified |
| 4010 | type from the specified <tt>va_list</tt> and causes the |
| 4011 | <tt>va_list</tt> to point to the next argument. For more information, |
| 4012 | see the variable argument handling <a href="#int_varargs">Intrinsic |
| 4013 | Functions</a>.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4014 | |
| 4015 | <p>It is legal for this instruction to be called in a function which does not |
| 4016 | take a variable number of arguments, for example, the <tt>vfprintf</tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4017 | function.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4018 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4019 | <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] | 4020 | href="#intrinsics">intrinsic function</a> because it takes a type as an |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4021 | argument.</p> |
| 4022 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 4023 | <h5>Example:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 4024 | |
| 4025 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> |
| 4026 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4027 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4028 | |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4029 | <!-- _______________________________________________________________________ --> |
| 4030 | <div class="doc_subsubsection"> |
| 4031 | <a name="i_getresult">'<tt>getresult</tt>' Instruction</a> |
| 4032 | </div> |
| 4033 | |
| 4034 | <div class="doc_text"> |
| 4035 | |
| 4036 | <h5>Syntax:</h5> |
| 4037 | <pre> |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4038 | <resultval> = getresult <type> <retval>, <index> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4039 | </pre> |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4040 | |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4041 | <h5>Overview:</h5> |
| 4042 | |
| 4043 | <p> The '<tt>getresult</tt>' instruction is used to extract individual values |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4044 | from a '<tt><a href="#i_call">call</a></tt>' |
| 4045 | or '<tt><a href="#i_invoke">invoke</a></tt>' instruction that returns multiple |
| 4046 | results.</p> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4047 | |
| 4048 | <h5>Arguments:</h5> |
| 4049 | |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4050 | <p>The '<tt>getresult</tt>' instruction takes a call or invoke value as its |
Chris Lattner | 1c406d7 | 2008-04-23 04:06:52 +0000 | [diff] [blame] | 4051 | first argument, or an undef value. The value must have <a |
| 4052 | href="#t_struct">structure type</a>. The second argument is a constant |
| 4053 | unsigned index value which must be in range for the number of values returned |
| 4054 | by the call.</p> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4055 | |
| 4056 | <h5>Semantics:</h5> |
| 4057 | |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4058 | <p>The '<tt>getresult</tt>' instruction extracts the element identified by |
| 4059 | '<tt>index</tt>' from the aggregate value.</p> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4060 | |
| 4061 | <h5>Example:</h5> |
| 4062 | |
| 4063 | <pre> |
| 4064 | %struct.A = type { i32, i8 } |
| 4065 | |
| 4066 | %r = call %struct.A @foo() |
Chris Lattner | 45c5e8b | 2008-03-21 17:20:51 +0000 | [diff] [blame] | 4067 | %gr = getresult %struct.A %r, 0 <i>; yields i32:%gr</i> |
| 4068 | %gr1 = getresult %struct.A %r, 1 <i>; yields i8:%gr1</i> |
Devang Patel | c3fc6df | 2008-03-10 20:49:15 +0000 | [diff] [blame] | 4069 | add i32 %gr, 42 |
| 4070 | add i8 %gr1, 41 |
| 4071 | </pre> |
| 4072 | |
| 4073 | </div> |
| 4074 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4075 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4076 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> |
| 4077 | <!-- *********************************************************************** --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4078 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4079 | <div class="doc_text"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4080 | |
| 4081 | <p>LLVM supports the notion of an "intrinsic function". These functions have |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4082 | well known names and semantics and are required to follow certain restrictions. |
| 4083 | Overall, these intrinsics represent an extension mechanism for the LLVM |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4084 | 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] | 4085 | 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] | 4086 | |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4087 | <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] | 4088 | prefix is reserved in LLVM for intrinsic names; thus, function names may not |
| 4089 | begin with this prefix. Intrinsic functions must always be external functions: |
| 4090 | you cannot define the body of intrinsic functions. Intrinsic functions may |
| 4091 | only be used in call or invoke instructions: it is illegal to take the address |
| 4092 | of an intrinsic function. Additionally, because intrinsic functions are part |
| 4093 | of the LLVM language, it is required if any are added that they be documented |
| 4094 | here.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4095 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4096 | <p>Some intrinsic functions can be overloaded, i.e., the intrinsic represents |
| 4097 | a family of functions that perform the same operation but on different data |
| 4098 | types. Because LLVM can represent over 8 million different integer types, |
| 4099 | overloading is used commonly to allow an intrinsic function to operate on any |
| 4100 | integer type. One or more of the argument types or the result type can be |
| 4101 | overloaded to accept any integer type. Argument types may also be defined as |
| 4102 | exactly matching a previous argument's type or the result type. This allows an |
| 4103 | intrinsic function which accepts multiple arguments, but needs all of them to |
| 4104 | be of the same type, to only be overloaded with respect to a single argument or |
| 4105 | the result.</p> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4106 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 4107 | <p>Overloaded intrinsics will have the names of its overloaded argument types |
| 4108 | encoded into its function name, each preceded by a period. Only those types |
| 4109 | which are overloaded result in a name suffix. Arguments whose type is matched |
| 4110 | against another type do not. For example, the <tt>llvm.ctpop</tt> function can |
| 4111 | take an integer of any width and returns an integer of exactly the same integer |
| 4112 | width. This leads to a family of functions such as |
| 4113 | <tt>i8 @llvm.ctpop.i8(i8 %val)</tt> and <tt>i29 @llvm.ctpop.i29(i29 %val)</tt>. |
| 4114 | Only one type, the return type, is overloaded, and only one type suffix is |
| 4115 | required. Because the argument's type is matched against the return type, it |
| 4116 | does not require its own name suffix.</p> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 4117 | |
| 4118 | <p>To learn how to add an intrinsic function, please see the |
| 4119 | <a href="ExtendingLLVM.html">Extending LLVM Guide</a>. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4120 | </p> |
| 4121 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4122 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4123 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4124 | <!-- ======================================================================= --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4125 | <div class="doc_subsection"> |
| 4126 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> |
| 4127 | </div> |
| 4128 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4129 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4130 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4131 | <p>Variable argument support is defined in LLVM with the <a |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 4132 | 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] | 4133 | intrinsic functions. These functions are related to the similarly |
| 4134 | named macros defined in the <tt><stdarg.h></tt> header file.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4135 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 4136 | <p>All of these functions operate on arguments that use a |
| 4137 | target-specific value type "<tt>va_list</tt>". The LLVM assembly |
| 4138 | language reference manual does not define what this type is, so all |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4139 | transformations should be prepared to handle these functions regardless of |
| 4140 | the type used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4141 | |
Chris Lattner | 374ab30 | 2006-05-15 17:26:46 +0000 | [diff] [blame] | 4142 | <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] | 4143 | instruction and the variable argument handling intrinsic functions are |
| 4144 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4145 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4146 | <div class="doc_code"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4147 | <pre> |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4148 | define i32 @test(i32 %X, ...) { |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4149 | ; Initialize variable argument processing |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4150 | %ap = alloca i8* |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4151 | %ap2 = bitcast i8** %ap to i8* |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4152 | call void @llvm.va_start(i8* %ap2) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4153 | |
| 4154 | ; Read a single integer argument |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4155 | %tmp = va_arg i8** %ap, i32 |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4156 | |
| 4157 | ; Demonstrate usage of llvm.va_copy and llvm.va_end |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4158 | %aq = alloca i8* |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4159 | %aq2 = bitcast i8** %aq to i8* |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4160 | call void @llvm.va_copy(i8* %aq2, i8* %ap2) |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4161 | call void @llvm.va_end(i8* %aq2) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4162 | |
| 4163 | ; Stop processing of arguments. |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4164 | call void @llvm.va_end(i8* %ap2) |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4165 | ret i32 %tmp |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4166 | } |
Anton Korobeynikov | 5d522f3 | 2007-03-21 23:58:04 +0000 | [diff] [blame] | 4167 | |
| 4168 | declare void @llvm.va_start(i8*) |
| 4169 | declare void @llvm.va_copy(i8*, i8*) |
| 4170 | declare void @llvm.va_end(i8*) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4171 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4172 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4173 | |
Bill Wendling | 2f7a8b0 | 2007-05-29 09:04:49 +0000 | [diff] [blame] | 4174 | </div> |
| 4175 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4176 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4177 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4178 | <a name="int_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4179 | </div> |
| 4180 | |
| 4181 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4182 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4183 | <h5>Syntax:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4184 | <pre> declare void %llvm.va_start(i8* <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4185 | <h5>Overview:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4186 | <P>The '<tt>llvm.va_start</tt>' intrinsic initializes |
| 4187 | <tt>*<arglist></tt> for subsequent use by <tt><a |
| 4188 | href="#i_va_arg">va_arg</a></tt>.</p> |
| 4189 | |
| 4190 | <h5>Arguments:</h5> |
| 4191 | |
| 4192 | <P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p> |
| 4193 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4194 | <h5>Semantics:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4195 | |
| 4196 | <P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> |
| 4197 | macro available in C. In a target-dependent way, it initializes the |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4198 | <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] | 4199 | <tt>va_arg</tt> will produce the first variable argument passed to the function. |
| 4200 | 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] | 4201 | 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] | 4202 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4203 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4204 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4205 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4206 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4207 | <a name="int_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4208 | </div> |
| 4209 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4210 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4211 | <h5>Syntax:</h5> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4212 | <pre> declare void @llvm.va_end(i8* <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4213 | <h5>Overview:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4214 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4215 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt>*<arglist></tt>, |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4216 | 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] | 4217 | 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] | 4218 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4219 | <h5>Arguments:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4220 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4221 | <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] | 4222 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4223 | <h5>Semantics:</h5> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4224 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4225 | <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] | 4226 | macro available in C. In a target-dependent way, it destroys the |
| 4227 | <tt>va_list</tt> element to which the argument points. Calls to <a |
| 4228 | href="#int_va_start"><tt>llvm.va_start</tt></a> and <a href="#int_va_copy"> |
| 4229 | <tt>llvm.va_copy</tt></a> must be matched exactly with calls to |
| 4230 | <tt>llvm.va_end</tt>.</p> |
Chris Lattner | b75137d | 2007-01-08 07:55:15 +0000 | [diff] [blame] | 4231 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4232 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4233 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4234 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4235 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4236 | <a name="int_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4237 | </div> |
| 4238 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4239 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4240 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4241 | <h5>Syntax:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4242 | |
| 4243 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4244 | declare void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4245 | </pre> |
| 4246 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4247 | <h5>Overview:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4248 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4249 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position |
| 4250 | from the source argument list to the destination argument list.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4251 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4252 | <h5>Arguments:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4253 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 4254 | <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] | 4255 | 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] | 4256 | |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4257 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 4258 | <h5>Semantics:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4259 | |
Jeff Cohen | b627eab | 2007-04-29 01:07:00 +0000 | [diff] [blame] | 4260 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> |
| 4261 | macro available in C. In a target-dependent way, it copies the source |
| 4262 | <tt>va_list</tt> element into the destination <tt>va_list</tt> element. This |
| 4263 | intrinsic is necessary because the <tt><a href="#int_va_start"> |
| 4264 | llvm.va_start</a></tt> intrinsic may be arbitrarily complex and require, for |
| 4265 | example, memory allocation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4266 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4267 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4268 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4269 | <!-- ======================================================================= --> |
| 4270 | <div class="doc_subsection"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4271 | <a name="int_gc">Accurate Garbage Collection Intrinsics</a> |
| 4272 | </div> |
| 4273 | |
| 4274 | <div class="doc_text"> |
| 4275 | |
| 4276 | <p> |
| 4277 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage |
| 4278 | Collection</a> requires the implementation and generation of these intrinsics. |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4279 | 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] | 4280 | stack</a>, as well as garbage collector implementations that require <a |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4281 | 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] | 4282 | Front-ends for type-safe garbage collected languages should generate these |
| 4283 | intrinsics to make use of the LLVM garbage collectors. For more details, see <a |
| 4284 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. |
| 4285 | </p> |
Christopher Lamb | 303dae9 | 2007-12-17 01:00:21 +0000 | [diff] [blame] | 4286 | |
| 4287 | <p>The garbage collection intrinsics only operate on objects in the generic |
| 4288 | address space (address space zero).</p> |
| 4289 | |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4290 | </div> |
| 4291 | |
| 4292 | <!-- _______________________________________________________________________ --> |
| 4293 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4294 | <a name="int_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4295 | </div> |
| 4296 | |
| 4297 | <div class="doc_text"> |
| 4298 | |
| 4299 | <h5>Syntax:</h5> |
| 4300 | |
| 4301 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4302 | declare void @llvm.gcroot(i8** %ptrloc, i8* %metadata) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4303 | </pre> |
| 4304 | |
| 4305 | <h5>Overview:</h5> |
| 4306 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 4307 | <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] | 4308 | the code generator, and allows some metadata to be associated with it.</p> |
| 4309 | |
| 4310 | <h5>Arguments:</h5> |
| 4311 | |
| 4312 | <p>The first argument specifies the address of a stack object that contains the |
| 4313 | root pointer. The second pointer (which must be either a constant or a global |
| 4314 | value address) contains the meta-data to be associated with the root.</p> |
| 4315 | |
| 4316 | <h5>Semantics:</h5> |
| 4317 | |
Chris Lattner | 05d6709 | 2008-04-24 05:59:56 +0000 | [diff] [blame] | 4318 | <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] | 4319 | location. At compile-time, the code generator generates information to allow |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4320 | the runtime to find the pointer at GC safe points. The '<tt>llvm.gcroot</tt>' |
| 4321 | intrinsic may only be used in a function which <a href="#gc">specifies a GC |
| 4322 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4323 | |
| 4324 | </div> |
| 4325 | |
| 4326 | |
| 4327 | <!-- _______________________________________________________________________ --> |
| 4328 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4329 | <a name="int_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4330 | </div> |
| 4331 | |
| 4332 | <div class="doc_text"> |
| 4333 | |
| 4334 | <h5>Syntax:</h5> |
| 4335 | |
| 4336 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4337 | declare i8* @llvm.gcread(i8* %ObjPtr, i8** %Ptr) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4338 | </pre> |
| 4339 | |
| 4340 | <h5>Overview:</h5> |
| 4341 | |
| 4342 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap |
| 4343 | locations, allowing garbage collector implementations that require read |
| 4344 | barriers.</p> |
| 4345 | |
| 4346 | <h5>Arguments:</h5> |
| 4347 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 4348 | <p>The second argument is the address to read from, which should be an address |
| 4349 | allocated from the garbage collector. The first object is a pointer to the |
| 4350 | start of the referenced object, if needed by the language runtime (otherwise |
| 4351 | null).</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4352 | |
| 4353 | <h5>Semantics:</h5> |
| 4354 | |
| 4355 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load |
| 4356 | instruction, but may be replaced with substantially more complex code by the |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4357 | garbage collector runtime, as needed. The '<tt>llvm.gcread</tt>' intrinsic |
| 4358 | may only be used in a function which <a href="#gc">specifies a GC |
| 4359 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4360 | |
| 4361 | </div> |
| 4362 | |
| 4363 | |
| 4364 | <!-- _______________________________________________________________________ --> |
| 4365 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4366 | <a name="int_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4367 | </div> |
| 4368 | |
| 4369 | <div class="doc_text"> |
| 4370 | |
| 4371 | <h5>Syntax:</h5> |
| 4372 | |
| 4373 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4374 | declare void @llvm.gcwrite(i8* %P1, i8* %Obj, i8** %P2) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4375 | </pre> |
| 4376 | |
| 4377 | <h5>Overview:</h5> |
| 4378 | |
| 4379 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap |
| 4380 | locations, allowing garbage collector implementations that require write |
| 4381 | barriers (such as generational or reference counting collectors).</p> |
| 4382 | |
| 4383 | <h5>Arguments:</h5> |
| 4384 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 4385 | <p>The first argument is the reference to store, the second is the start of the |
| 4386 | object to store it to, and the third is the address of the field of Obj to |
| 4387 | store to. If the runtime does not require a pointer to the object, Obj may be |
| 4388 | null.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4389 | |
| 4390 | <h5>Semantics:</h5> |
| 4391 | |
| 4392 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store |
| 4393 | instruction, but may be replaced with substantially more complex code by the |
Gordon Henriksen | e1433f2 | 2007-12-25 02:31:26 +0000 | [diff] [blame] | 4394 | garbage collector runtime, as needed. The '<tt>llvm.gcwrite</tt>' intrinsic |
| 4395 | may only be used in a function which <a href="#gc">specifies a GC |
| 4396 | algorithm</a>.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 4397 | |
| 4398 | </div> |
| 4399 | |
| 4400 | |
| 4401 | |
| 4402 | <!-- ======================================================================= --> |
| 4403 | <div class="doc_subsection"> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4404 | <a name="int_codegen">Code Generator Intrinsics</a> |
| 4405 | </div> |
| 4406 | |
| 4407 | <div class="doc_text"> |
| 4408 | <p> |
| 4409 | These intrinsics are provided by LLVM to expose special features that may only |
| 4410 | be implemented with code generator support. |
| 4411 | </p> |
| 4412 | |
| 4413 | </div> |
| 4414 | |
| 4415 | <!-- _______________________________________________________________________ --> |
| 4416 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4417 | <a name="int_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4418 | </div> |
| 4419 | |
| 4420 | <div class="doc_text"> |
| 4421 | |
| 4422 | <h5>Syntax:</h5> |
| 4423 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4424 | declare i8 *@llvm.returnaddress(i32 <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4425 | </pre> |
| 4426 | |
| 4427 | <h5>Overview:</h5> |
| 4428 | |
| 4429 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 4430 | The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a |
| 4431 | target-specific value indicating the return address of the current function |
| 4432 | or one of its callers. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4433 | </p> |
| 4434 | |
| 4435 | <h5>Arguments:</h5> |
| 4436 | |
| 4437 | <p> |
| 4438 | The argument to this intrinsic indicates which function to return the address |
| 4439 | for. Zero indicates the calling function, one indicates its caller, etc. The |
| 4440 | argument is <b>required</b> to be a constant integer value. |
| 4441 | </p> |
| 4442 | |
| 4443 | <h5>Semantics:</h5> |
| 4444 | |
| 4445 | <p> |
| 4446 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating |
| 4447 | the return address of the specified call frame, or zero if it cannot be |
| 4448 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 4449 | for arguments other than zero, so it should only be used for debugging purposes. |
| 4450 | </p> |
| 4451 | |
| 4452 | <p> |
| 4453 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 4454 | 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] | 4455 | source-language caller. |
| 4456 | </p> |
| 4457 | </div> |
| 4458 | |
| 4459 | |
| 4460 | <!-- _______________________________________________________________________ --> |
| 4461 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4462 | <a name="int_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4463 | </div> |
| 4464 | |
| 4465 | <div class="doc_text"> |
| 4466 | |
| 4467 | <h5>Syntax:</h5> |
| 4468 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4469 | declare i8 *@llvm.frameaddress(i32 <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4470 | </pre> |
| 4471 | |
| 4472 | <h5>Overview:</h5> |
| 4473 | |
| 4474 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 4475 | The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the |
| 4476 | target-specific frame pointer value for the specified stack frame. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4477 | </p> |
| 4478 | |
| 4479 | <h5>Arguments:</h5> |
| 4480 | |
| 4481 | <p> |
| 4482 | The argument to this intrinsic indicates which function to return the frame |
| 4483 | pointer for. Zero indicates the calling function, one indicates its caller, |
| 4484 | etc. The argument is <b>required</b> to be a constant integer value. |
| 4485 | </p> |
| 4486 | |
| 4487 | <h5>Semantics:</h5> |
| 4488 | |
| 4489 | <p> |
| 4490 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating |
| 4491 | the frame address of the specified call frame, or zero if it cannot be |
| 4492 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 4493 | for arguments other than zero, so it should only be used for debugging purposes. |
| 4494 | </p> |
| 4495 | |
| 4496 | <p> |
| 4497 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 4498 | 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] | 4499 | source-language caller. |
| 4500 | </p> |
| 4501 | </div> |
| 4502 | |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4503 | <!-- _______________________________________________________________________ --> |
| 4504 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4505 | <a name="int_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4506 | </div> |
| 4507 | |
| 4508 | <div class="doc_text"> |
| 4509 | |
| 4510 | <h5>Syntax:</h5> |
| 4511 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4512 | declare i8 *@llvm.stacksave() |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4513 | </pre> |
| 4514 | |
| 4515 | <h5>Overview:</h5> |
| 4516 | |
| 4517 | <p> |
| 4518 | 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] | 4519 | the function stack, for use with <a href="#int_stackrestore"> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4520 | <tt>llvm.stackrestore</tt></a>. This is useful for implementing language |
| 4521 | features like scoped automatic variable sized arrays in C99. |
| 4522 | </p> |
| 4523 | |
| 4524 | <h5>Semantics:</h5> |
| 4525 | |
| 4526 | <p> |
| 4527 | 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] | 4528 | href="#int_stackrestore"><tt>llvm.stackrestore</tt></a>. When an |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4529 | <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from |
| 4530 | <tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the |
| 4531 | state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In |
| 4532 | practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack |
| 4533 | that were allocated after the <tt>llvm.stacksave</tt> was executed. |
| 4534 | </p> |
| 4535 | |
| 4536 | </div> |
| 4537 | |
| 4538 | <!-- _______________________________________________________________________ --> |
| 4539 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4540 | <a name="int_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4541 | </div> |
| 4542 | |
| 4543 | <div class="doc_text"> |
| 4544 | |
| 4545 | <h5>Syntax:</h5> |
| 4546 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4547 | declare void @llvm.stackrestore(i8 * %ptr) |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4548 | </pre> |
| 4549 | |
| 4550 | <h5>Overview:</h5> |
| 4551 | |
| 4552 | <p> |
| 4553 | The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of |
| 4554 | 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] | 4555 | href="#int_stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 4556 | useful for implementing language features like scoped automatic variable sized |
| 4557 | arrays in C99. |
| 4558 | </p> |
| 4559 | |
| 4560 | <h5>Semantics:</h5> |
| 4561 | |
| 4562 | <p> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4563 | 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] | 4564 | </p> |
| 4565 | |
| 4566 | </div> |
| 4567 | |
| 4568 | |
| 4569 | <!-- _______________________________________________________________________ --> |
| 4570 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4571 | <a name="int_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a> |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4572 | </div> |
| 4573 | |
| 4574 | <div class="doc_text"> |
| 4575 | |
| 4576 | <h5>Syntax:</h5> |
| 4577 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4578 | declare void @llvm.prefetch(i8* <address>, i32 <rw>, i32 <locality>) |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4579 | </pre> |
| 4580 | |
| 4581 | <h5>Overview:</h5> |
| 4582 | |
| 4583 | |
| 4584 | <p> |
| 4585 | 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] | 4586 | a prefetch instruction if supported; otherwise, it is a noop. Prefetches have |
| 4587 | no |
| 4588 | effect on the behavior of the program but can change its performance |
Chris Lattner | 2a61536 | 2005-02-28 19:47:14 +0000 | [diff] [blame] | 4589 | characteristics. |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 4590 | </p> |
| 4591 | |
| 4592 | <h5>Arguments:</h5> |
| 4593 | |
| 4594 | <p> |
| 4595 | <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier |
| 4596 | determining if the fetch should be for a read (0) or write (1), and |
| 4597 | <tt>locality</tt> is a temporal locality specifier ranging from (0) - no |
Chris Lattner | aeffb4a | 2005-03-07 20:31:38 +0000 | [diff] [blame] | 4598 | 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] | 4599 | <tt>locality</tt> arguments must be constant integers. |
| 4600 | </p> |
| 4601 | |
| 4602 | <h5>Semantics:</h5> |
| 4603 | |
| 4604 | <p> |
| 4605 | This intrinsic does not modify the behavior of the program. In particular, |
| 4606 | prefetches cannot trap and do not produce a value. On targets that support this |
| 4607 | intrinsic, the prefetch can provide hints to the processor cache for better |
| 4608 | performance. |
| 4609 | </p> |
| 4610 | |
| 4611 | </div> |
| 4612 | |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4613 | <!-- _______________________________________________________________________ --> |
| 4614 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4615 | <a name="int_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a> |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4616 | </div> |
| 4617 | |
| 4618 | <div class="doc_text"> |
| 4619 | |
| 4620 | <h5>Syntax:</h5> |
| 4621 | <pre> |
Chris Lattner | 1df4f75 | 2007-09-21 17:30:40 +0000 | [diff] [blame] | 4622 | declare void @llvm.pcmarker(i32 <id>) |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4623 | </pre> |
| 4624 | |
| 4625 | <h5>Overview:</h5> |
| 4626 | |
| 4627 | |
| 4628 | <p> |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4629 | The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter |
| 4630 | (PC) in a region of |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4631 | code to simulators and other tools. The method is target specific, but it is |
| 4632 | expected that the marker will use exported symbols to transmit the PC of the marker. |
Jeff Cohen | 25d4f7e | 2005-11-11 02:15:27 +0000 | [diff] [blame] | 4633 | The marker makes no guarantees that it will remain with any specific instruction |
Chris Lattner | d07c3f4 | 2005-11-15 06:07:55 +0000 | [diff] [blame] | 4634 | 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] | 4635 | optimizations. The intended use is to be inserted after optimizations to allow |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 4636 | correlations of simulation runs. |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 4637 | </p> |
| 4638 | |
| 4639 | <h5>Arguments:</h5> |
| 4640 | |
| 4641 | <p> |
| 4642 | <tt>id</tt> is a numerical id identifying the marker. |
| 4643 | </p> |
| 4644 | |
| 4645 | <h5>Semantics:</h5> |
| 4646 | |
| 4647 | <p> |
| 4648 | This intrinsic does not modify the behavior of the program. Backends that do not |
| 4649 | support this intrinisic may ignore it. |
| 4650 | </p> |
| 4651 | |
| 4652 | </div> |
| 4653 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4654 | <!-- _______________________________________________________________________ --> |
| 4655 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4656 | <a name="int_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a> |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4657 | </div> |
| 4658 | |
| 4659 | <div class="doc_text"> |
| 4660 | |
| 4661 | <h5>Syntax:</h5> |
| 4662 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4663 | declare i64 @llvm.readcyclecounter( ) |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 4664 | </pre> |
| 4665 | |
| 4666 | <h5>Overview:</h5> |
| 4667 | |
| 4668 | |
| 4669 | <p> |
| 4670 | The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle |
| 4671 | counter register (or similar low latency, high accuracy clocks) on those targets |
| 4672 | that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC. |
| 4673 | As the backing counters overflow quickly (on the order of 9 seconds on alpha), this |
| 4674 | should only be used for small timings. |
| 4675 | </p> |
| 4676 | |
| 4677 | <h5>Semantics:</h5> |
| 4678 | |
| 4679 | <p> |
| 4680 | When directly supported, reading the cycle counter should not modify any memory. |
| 4681 | Implementations are allowed to either return a application specific value or a |
| 4682 | system wide value. On backends without support, this is lowered to a constant 0. |
| 4683 | </p> |
| 4684 | |
| 4685 | </div> |
| 4686 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4687 | <!-- ======================================================================= --> |
| 4688 | <div class="doc_subsection"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4689 | <a name="int_libc">Standard C Library Intrinsics</a> |
| 4690 | </div> |
| 4691 | |
| 4692 | <div class="doc_text"> |
| 4693 | <p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4694 | LLVM provides intrinsics for a few important standard C library functions. |
| 4695 | These intrinsics allow source-language front-ends to pass information about the |
| 4696 | alignment of the pointer arguments to the code generator, providing opportunity |
| 4697 | for more efficient code generation. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4698 | </p> |
| 4699 | |
| 4700 | </div> |
| 4701 | |
| 4702 | <!-- _______________________________________________________________________ --> |
| 4703 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4704 | <a name="int_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4705 | </div> |
| 4706 | |
| 4707 | <div class="doc_text"> |
| 4708 | |
| 4709 | <h5>Syntax:</h5> |
| 4710 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4711 | declare void @llvm.memcpy.i32(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4712 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4713 | declare void @llvm.memcpy.i64(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4714 | i64 <len>, i32 <align>) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4715 | </pre> |
| 4716 | |
| 4717 | <h5>Overview:</h5> |
| 4718 | |
| 4719 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4720 | 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] | 4721 | location to the destination location. |
| 4722 | </p> |
| 4723 | |
| 4724 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4725 | Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt> |
| 4726 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4727 | </p> |
| 4728 | |
| 4729 | <h5>Arguments:</h5> |
| 4730 | |
| 4731 | <p> |
| 4732 | 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] | 4733 | the source. The third argument is an integer argument |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4734 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 4735 | of the source and destination locations. |
| 4736 | </p> |
| 4737 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4738 | <p> |
| 4739 | 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] | 4740 | the caller guarantees that both the source and destination pointers are aligned |
| 4741 | to that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4742 | </p> |
| 4743 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4744 | <h5>Semantics:</h5> |
| 4745 | |
| 4746 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4747 | 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] | 4748 | location to the destination location, which are not allowed to overlap. It |
| 4749 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 4750 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 4751 | be set to 0 or 1. |
| 4752 | </p> |
| 4753 | </div> |
| 4754 | |
| 4755 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4756 | <!-- _______________________________________________________________________ --> |
| 4757 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4758 | <a name="int_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4759 | </div> |
| 4760 | |
| 4761 | <div class="doc_text"> |
| 4762 | |
| 4763 | <h5>Syntax:</h5> |
| 4764 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4765 | declare void @llvm.memmove.i32(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4766 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4767 | declare void @llvm.memmove.i64(i8 * <dest>, i8 * <src>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4768 | i64 <len>, i32 <align>) |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4769 | </pre> |
| 4770 | |
| 4771 | <h5>Overview:</h5> |
| 4772 | |
| 4773 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4774 | The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source |
| 4775 | location to the destination location. It is similar to the |
Chris Lattner | 4b2cbcf | 2008-01-06 19:51:52 +0000 | [diff] [blame] | 4776 | '<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] | 4777 | </p> |
| 4778 | |
| 4779 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4780 | Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt> |
| 4781 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4782 | </p> |
| 4783 | |
| 4784 | <h5>Arguments:</h5> |
| 4785 | |
| 4786 | <p> |
| 4787 | 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] | 4788 | the source. The third argument is an integer argument |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4789 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 4790 | of the source and destination locations. |
| 4791 | </p> |
| 4792 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4793 | <p> |
| 4794 | 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] | 4795 | the caller guarantees that the source and destination pointers are aligned to |
| 4796 | that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4797 | </p> |
| 4798 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4799 | <h5>Semantics:</h5> |
| 4800 | |
| 4801 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4802 | 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] | 4803 | location to the destination location, which may overlap. It |
| 4804 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 4805 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 4806 | be set to 0 or 1. |
| 4807 | </p> |
| 4808 | </div> |
| 4809 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4810 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4811 | <!-- _______________________________________________________________________ --> |
| 4812 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4813 | <a name="int_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4814 | </div> |
| 4815 | |
| 4816 | <div class="doc_text"> |
| 4817 | |
| 4818 | <h5>Syntax:</h5> |
| 4819 | <pre> |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4820 | declare void @llvm.memset.i32(i8 * <dest>, i8 <val>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4821 | i32 <len>, i32 <align>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 4822 | declare void @llvm.memset.i64(i8 * <dest>, i8 <val>, |
Reid Spencer | ca86e16 | 2006-12-31 07:07:53 +0000 | [diff] [blame] | 4823 | i64 <len>, i32 <align>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4824 | </pre> |
| 4825 | |
| 4826 | <h5>Overview:</h5> |
| 4827 | |
| 4828 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4829 | 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] | 4830 | byte value. |
| 4831 | </p> |
| 4832 | |
| 4833 | <p> |
| 4834 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic |
| 4835 | does not return a value, and takes an extra alignment argument. |
| 4836 | </p> |
| 4837 | |
| 4838 | <h5>Arguments:</h5> |
| 4839 | |
| 4840 | <p> |
| 4841 | 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] | 4842 | byte value to fill it with, the third argument is an integer |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4843 | argument specifying the number of bytes to fill, and the fourth argument is the |
| 4844 | known alignment of destination location. |
| 4845 | </p> |
| 4846 | |
| 4847 | <p> |
| 4848 | 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] | 4849 | the caller guarantees that the destination pointer is aligned to that boundary. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4850 | </p> |
| 4851 | |
| 4852 | <h5>Semantics:</h5> |
| 4853 | |
| 4854 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4855 | The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at |
| 4856 | the |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4857 | destination location. If the argument is known to be aligned to some boundary, |
| 4858 | this can be specified as the fourth argument, otherwise it should be set to 0 or |
| 4859 | 1. |
| 4860 | </p> |
| 4861 | </div> |
| 4862 | |
| 4863 | |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 4864 | <!-- _______________________________________________________________________ --> |
| 4865 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4866 | <a name="int_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a> |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4867 | </div> |
| 4868 | |
| 4869 | <div class="doc_text"> |
| 4870 | |
| 4871 | <h5>Syntax:</h5> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 4872 | <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] | 4873 | floating point or vector of floating point type. Not all targets support all |
| 4874 | types however. |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4875 | <pre> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 4876 | declare float @llvm.sqrt.f32(float %Val) |
| 4877 | declare double @llvm.sqrt.f64(double %Val) |
| 4878 | declare x86_fp80 @llvm.sqrt.f80(x86_fp80 %Val) |
| 4879 | declare fp128 @llvm.sqrt.f128(fp128 %Val) |
| 4880 | declare ppc_fp128 @llvm.sqrt.ppcf128(ppc_fp128 %Val) |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4881 | </pre> |
| 4882 | |
| 4883 | <h5>Overview:</h5> |
| 4884 | |
| 4885 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4886 | 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] | 4887 | 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] | 4888 | <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] | 4889 | negative numbers other than -0.0 (which allows for better optimization, because |
| 4890 | there is no need to worry about errno being set). <tt>llvm.sqrt(-0.0)</tt> is |
| 4891 | defined to return -0.0 like IEEE sqrt. |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4892 | </p> |
| 4893 | |
| 4894 | <h5>Arguments:</h5> |
| 4895 | |
| 4896 | <p> |
| 4897 | The argument and return value are floating point numbers of the same type. |
| 4898 | </p> |
| 4899 | |
| 4900 | <h5>Semantics:</h5> |
| 4901 | |
| 4902 | <p> |
Dan Gohman | d6257fe | 2007-07-16 14:37:41 +0000 | [diff] [blame] | 4903 | 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] | 4904 | floating point number. |
| 4905 | </p> |
| 4906 | </div> |
| 4907 | |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4908 | <!-- _______________________________________________________________________ --> |
| 4909 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 4910 | <a name="int_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a> |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4911 | </div> |
| 4912 | |
| 4913 | <div class="doc_text"> |
| 4914 | |
| 4915 | <h5>Syntax:</h5> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 4916 | <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] | 4917 | floating point or vector of floating point type. Not all targets support all |
| 4918 | types however. |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4919 | <pre> |
Dale Johannesen | 408f9c1 | 2007-10-02 17:47:38 +0000 | [diff] [blame] | 4920 | declare float @llvm.powi.f32(float %Val, i32 %power) |
| 4921 | declare double @llvm.powi.f64(double %Val, i32 %power) |
| 4922 | declare x86_fp80 @llvm.powi.f80(x86_fp80 %Val, i32 %power) |
| 4923 | declare fp128 @llvm.powi.f128(fp128 %Val, i32 %power) |
| 4924 | declare ppc_fp128 @llvm.powi.ppcf128(ppc_fp128 %Val, i32 %power) |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4925 | </pre> |
| 4926 | |
| 4927 | <h5>Overview:</h5> |
| 4928 | |
| 4929 | <p> |
| 4930 | The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the |
| 4931 | specified (positive or negative) power. The order of evaluation of |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 4932 | multiplications is not defined. When a vector of floating point type is |
| 4933 | used, the second argument remains a scalar integer value. |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4934 | </p> |
| 4935 | |
| 4936 | <h5>Arguments:</h5> |
| 4937 | |
| 4938 | <p> |
| 4939 | The second argument is an integer power, and the first is a value to raise to |
| 4940 | that power. |
| 4941 | </p> |
| 4942 | |
| 4943 | <h5>Semantics:</h5> |
| 4944 | |
| 4945 | <p> |
| 4946 | This function returns the first value raised to the second power with an |
| 4947 | unspecified sequence of rounding operations.</p> |
| 4948 | </div> |
| 4949 | |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 4950 | <!-- _______________________________________________________________________ --> |
| 4951 | <div class="doc_subsubsection"> |
| 4952 | <a name="int_sin">'<tt>llvm.sin.*</tt>' Intrinsic</a> |
| 4953 | </div> |
| 4954 | |
| 4955 | <div class="doc_text"> |
| 4956 | |
| 4957 | <h5>Syntax:</h5> |
| 4958 | <p>This is an overloaded intrinsic. You can use <tt>llvm.sin</tt> on any |
| 4959 | floating point or vector of floating point type. Not all targets support all |
| 4960 | types however. |
| 4961 | <pre> |
| 4962 | declare float @llvm.sin.f32(float %Val) |
| 4963 | declare double @llvm.sin.f64(double %Val) |
| 4964 | declare x86_fp80 @llvm.sin.f80(x86_fp80 %Val) |
| 4965 | declare fp128 @llvm.sin.f128(fp128 %Val) |
| 4966 | declare ppc_fp128 @llvm.sin.ppcf128(ppc_fp128 %Val) |
| 4967 | </pre> |
| 4968 | |
| 4969 | <h5>Overview:</h5> |
| 4970 | |
| 4971 | <p> |
| 4972 | The '<tt>llvm.sin.*</tt>' intrinsics return the sine of the operand. |
| 4973 | </p> |
| 4974 | |
| 4975 | <h5>Arguments:</h5> |
| 4976 | |
| 4977 | <p> |
| 4978 | The argument and return value are floating point numbers of the same type. |
| 4979 | </p> |
| 4980 | |
| 4981 | <h5>Semantics:</h5> |
| 4982 | |
| 4983 | <p> |
| 4984 | This function returns the sine of the specified operand, returning the |
| 4985 | 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] | 4986 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 4987 | </div> |
| 4988 | |
| 4989 | <!-- _______________________________________________________________________ --> |
| 4990 | <div class="doc_subsubsection"> |
| 4991 | <a name="int_cos">'<tt>llvm.cos.*</tt>' Intrinsic</a> |
| 4992 | </div> |
| 4993 | |
| 4994 | <div class="doc_text"> |
| 4995 | |
| 4996 | <h5>Syntax:</h5> |
| 4997 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cos</tt> on any |
| 4998 | floating point or vector of floating point type. Not all targets support all |
| 4999 | types however. |
| 5000 | <pre> |
| 5001 | declare float @llvm.cos.f32(float %Val) |
| 5002 | declare double @llvm.cos.f64(double %Val) |
| 5003 | declare x86_fp80 @llvm.cos.f80(x86_fp80 %Val) |
| 5004 | declare fp128 @llvm.cos.f128(fp128 %Val) |
| 5005 | declare ppc_fp128 @llvm.cos.ppcf128(ppc_fp128 %Val) |
| 5006 | </pre> |
| 5007 | |
| 5008 | <h5>Overview:</h5> |
| 5009 | |
| 5010 | <p> |
| 5011 | The '<tt>llvm.cos.*</tt>' intrinsics return the cosine of the operand. |
| 5012 | </p> |
| 5013 | |
| 5014 | <h5>Arguments:</h5> |
| 5015 | |
| 5016 | <p> |
| 5017 | The argument and return value are floating point numbers of the same type. |
| 5018 | </p> |
| 5019 | |
| 5020 | <h5>Semantics:</h5> |
| 5021 | |
| 5022 | <p> |
| 5023 | This function returns the cosine of the specified operand, returning the |
| 5024 | 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] | 5025 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5026 | </div> |
| 5027 | |
| 5028 | <!-- _______________________________________________________________________ --> |
| 5029 | <div class="doc_subsubsection"> |
| 5030 | <a name="int_pow">'<tt>llvm.pow.*</tt>' Intrinsic</a> |
| 5031 | </div> |
| 5032 | |
| 5033 | <div class="doc_text"> |
| 5034 | |
| 5035 | <h5>Syntax:</h5> |
| 5036 | <p>This is an overloaded intrinsic. You can use <tt>llvm.pow</tt> on any |
| 5037 | floating point or vector of floating point type. Not all targets support all |
| 5038 | types however. |
| 5039 | <pre> |
| 5040 | declare float @llvm.pow.f32(float %Val, float %Power) |
| 5041 | declare double @llvm.pow.f64(double %Val, double %Power) |
| 5042 | declare x86_fp80 @llvm.pow.f80(x86_fp80 %Val, x86_fp80 %Power) |
| 5043 | declare fp128 @llvm.pow.f128(fp128 %Val, fp128 %Power) |
| 5044 | declare ppc_fp128 @llvm.pow.ppcf128(ppc_fp128 %Val, ppc_fp128 Power) |
| 5045 | </pre> |
| 5046 | |
| 5047 | <h5>Overview:</h5> |
| 5048 | |
| 5049 | <p> |
| 5050 | The '<tt>llvm.pow.*</tt>' intrinsics return the first operand raised to the |
| 5051 | specified (positive or negative) power. |
| 5052 | </p> |
| 5053 | |
| 5054 | <h5>Arguments:</h5> |
| 5055 | |
| 5056 | <p> |
| 5057 | The second argument is a floating point power, and the first is a value to |
| 5058 | raise to that power. |
| 5059 | </p> |
| 5060 | |
| 5061 | <h5>Semantics:</h5> |
| 5062 | |
| 5063 | <p> |
| 5064 | This function returns the first value raised to the second power, |
| 5065 | returning the |
| 5066 | 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] | 5067 | conditions in the same way.</p> |
Dan Gohman | 91c284c | 2007-10-15 20:30:11 +0000 | [diff] [blame] | 5068 | </div> |
| 5069 | |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 5070 | |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5071 | <!-- ======================================================================= --> |
| 5072 | <div class="doc_subsection"> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5073 | <a name="int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5074 | </div> |
| 5075 | |
| 5076 | <div class="doc_text"> |
| 5077 | <p> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5078 | LLVM provides intrinsics for a few important bit manipulation operations. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5079 | These allow efficient code generation for some algorithms. |
| 5080 | </p> |
| 5081 | |
| 5082 | </div> |
| 5083 | |
| 5084 | <!-- _______________________________________________________________________ --> |
| 5085 | <div class="doc_subsubsection"> |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5086 | <a name="int_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5087 | </div> |
| 5088 | |
| 5089 | <div class="doc_text"> |
| 5090 | |
| 5091 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5092 | <p>This is an overloaded intrinsic function. You can use bswap on any integer |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5093 | type that is an even number of bytes (i.e. BitWidth % 16 == 0). |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5094 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5095 | declare i16 @llvm.bswap.i16(i16 <id>) |
| 5096 | declare i32 @llvm.bswap.i32(i32 <id>) |
| 5097 | declare i64 @llvm.bswap.i64(i64 <id>) |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5098 | </pre> |
| 5099 | |
| 5100 | <h5>Overview:</h5> |
| 5101 | |
| 5102 | <p> |
Reid Spencer | 338ea09 | 2007-04-02 02:25:19 +0000 | [diff] [blame] | 5103 | 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] | 5104 | values with an even number of bytes (positive multiple of 16 bits). These are |
| 5105 | useful for performing operations on data that is not in the target's native |
| 5106 | byte order. |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5107 | </p> |
| 5108 | |
| 5109 | <h5>Semantics:</h5> |
| 5110 | |
| 5111 | <p> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5112 | 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] | 5113 | and low byte of the input i16 swapped. Similarly, the <tt>llvm.bswap.i32</tt> |
| 5114 | intrinsic returns an i32 value that has the four bytes of the input i32 |
| 5115 | 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] | 5116 | i32 will have its bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i48</tt>, |
| 5117 | <tt>llvm.bswap.i64</tt> and other intrinsics extend this concept to |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5118 | additional even-byte lengths (6 bytes, 8 bytes and more, respectively). |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 5119 | </p> |
| 5120 | |
| 5121 | </div> |
| 5122 | |
| 5123 | <!-- _______________________________________________________________________ --> |
| 5124 | <div class="doc_subsubsection"> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5125 | <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5126 | </div> |
| 5127 | |
| 5128 | <div class="doc_text"> |
| 5129 | |
| 5130 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5131 | <p>This is an overloaded intrinsic. You can use llvm.ctpop on any integer bit |
| 5132 | width. Not all targets support all bit widths however. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5133 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5134 | declare i8 @llvm.ctpop.i8 (i8 <src>) |
| 5135 | declare i16 @llvm.ctpop.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5136 | declare i32 @llvm.ctpop.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5137 | declare i64 @llvm.ctpop.i64(i64 <src>) |
| 5138 | declare i256 @llvm.ctpop.i256(i256 <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5139 | </pre> |
| 5140 | |
| 5141 | <h5>Overview:</h5> |
| 5142 | |
| 5143 | <p> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 5144 | The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a |
| 5145 | value. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5146 | </p> |
| 5147 | |
| 5148 | <h5>Arguments:</h5> |
| 5149 | |
| 5150 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5151 | 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] | 5152 | integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5153 | </p> |
| 5154 | |
| 5155 | <h5>Semantics:</h5> |
| 5156 | |
| 5157 | <p> |
| 5158 | The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable. |
| 5159 | </p> |
| 5160 | </div> |
| 5161 | |
| 5162 | <!-- _______________________________________________________________________ --> |
| 5163 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5164 | <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5165 | </div> |
| 5166 | |
| 5167 | <div class="doc_text"> |
| 5168 | |
| 5169 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5170 | <p>This is an overloaded intrinsic. You can use <tt>llvm.ctlz</tt> on any |
| 5171 | integer bit width. Not all targets support all bit widths however. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5172 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5173 | declare i8 @llvm.ctlz.i8 (i8 <src>) |
| 5174 | declare i16 @llvm.ctlz.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5175 | declare i32 @llvm.ctlz.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5176 | declare i64 @llvm.ctlz.i64(i64 <src>) |
| 5177 | declare i256 @llvm.ctlz.i256(i256 <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5178 | </pre> |
| 5179 | |
| 5180 | <h5>Overview:</h5> |
| 5181 | |
| 5182 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5183 | The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of |
| 5184 | leading zeros in a variable. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5185 | </p> |
| 5186 | |
| 5187 | <h5>Arguments:</h5> |
| 5188 | |
| 5189 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 5190 | 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] | 5191 | integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5192 | </p> |
| 5193 | |
| 5194 | <h5>Semantics:</h5> |
| 5195 | |
| 5196 | <p> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5197 | The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros |
| 5198 | 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] | 5199 | of src. For example, <tt>llvm.ctlz(i32 2) = 30</tt>. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 5200 | </p> |
| 5201 | </div> |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 5202 | |
| 5203 | |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5204 | |
| 5205 | <!-- _______________________________________________________________________ --> |
| 5206 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 5207 | <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5208 | </div> |
| 5209 | |
| 5210 | <div class="doc_text"> |
| 5211 | |
| 5212 | <h5>Syntax:</h5> |
Reid Spencer | 409e28f | 2007-04-01 08:04:23 +0000 | [diff] [blame] | 5213 | <p>This is an overloaded intrinsic. You can use <tt>llvm.cttz</tt> on any |
| 5214 | integer bit width. Not all targets support all bit widths however. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5215 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5216 | declare i8 @llvm.cttz.i8 (i8 <src>) |
| 5217 | declare i16 @llvm.cttz.i16(i16 <src>) |
Anton Korobeynikov | ec43a06 | 2007-03-22 00:02:17 +0000 | [diff] [blame] | 5218 | declare i32 @llvm.cttz.i32(i32 <src>) |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5219 | declare i64 @llvm.cttz.i64(i64 <src>) |
| 5220 | declare i256 @llvm.cttz.i256(i256 <src>) |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5221 | </pre> |
| 5222 | |
| 5223 | <h5>Overview:</h5> |
| 5224 | |
| 5225 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 5226 | The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of |
| 5227 | trailing zeros. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5228 | </p> |
| 5229 | |
| 5230 | <h5>Arguments:</h5> |
| 5231 | |
| 5232 | <p> |
| 5233 | 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] | 5234 | integer type. The return type must match the argument type. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 5235 | </p> |
| 5236 | |
| 5237 | <h5>Semantics:</h5> |
| 5238 | |
| 5239 | <p> |
| 5240 | The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros |
| 5241 | in a variable. If the src == 0 then the result is the size in bits of the type |
| 5242 | of src. For example, <tt>llvm.cttz(2) = 1</tt>. |
| 5243 | </p> |
| 5244 | </div> |
| 5245 | |
Reid Spencer | 497d93e | 2007-04-01 08:27:01 +0000 | [diff] [blame] | 5246 | <!-- _______________________________________________________________________ --> |
| 5247 | <div class="doc_subsubsection"> |
Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5248 | <a name="int_part_select">'<tt>llvm.part.select.*</tt>' Intrinsic</a> |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5249 | </div> |
| 5250 | |
| 5251 | <div class="doc_text"> |
| 5252 | |
| 5253 | <h5>Syntax:</h5> |
Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5254 | <p>This is an overloaded intrinsic. You can use <tt>llvm.part.select</tt> |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5255 | on any integer bit width. |
| 5256 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5257 | declare i17 @llvm.part.select.i17 (i17 %val, i32 %loBit, i32 %hiBit) |
| 5258 | declare i29 @llvm.part.select.i29 (i29 %val, i32 %loBit, i32 %hiBit) |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5259 | </pre> |
| 5260 | |
| 5261 | <h5>Overview:</h5> |
Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5262 | <p>The '<tt>llvm.part.select</tt>' family of intrinsic functions selects a |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5263 | range of bits from an integer value and returns them in the same bit width as |
| 5264 | the original value.</p> |
| 5265 | |
| 5266 | <h5>Arguments:</h5> |
| 5267 | <p>The first argument, <tt>%val</tt> and the result may be integer types of |
| 5268 | any bit width but they must have the same bit width. The second and third |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5269 | arguments must be <tt>i32</tt> type since they specify only a bit index.</p> |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5270 | |
| 5271 | <h5>Semantics:</h5> |
Reid Spencer | beacf66 | 2007-04-10 02:51:31 +0000 | [diff] [blame] | 5272 | <p>The operation of the '<tt>llvm.part.select</tt>' intrinsic has two modes |
Reid Spencer | a3e435f | 2007-04-04 02:42:35 +0000 | [diff] [blame] | 5273 | of operation: forwards and reverse. If <tt>%loBit</tt> is greater than |
| 5274 | <tt>%hiBits</tt> then the intrinsic operates in reverse mode. Otherwise it |
| 5275 | operates in forward mode.</p> |
| 5276 | <p>In forward mode, this intrinsic is the equivalent of shifting <tt>%val</tt> |
| 5277 | right by <tt>%loBit</tt> bits and then ANDing it with a mask with |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5278 | only the <tt>%hiBit - %loBit</tt> bits set, as follows:</p> |
| 5279 | <ol> |
| 5280 | <li>The <tt>%val</tt> is shifted right (LSHR) by the number of bits specified |
| 5281 | by <tt>%loBits</tt>. This normalizes the value to the low order bits.</li> |
| 5282 | <li>The <tt>%loBits</tt> value is subtracted from the <tt>%hiBits</tt> value |
| 5283 | to determine the number of bits to retain.</li> |
| 5284 | <li>A mask of the retained bits is created by shifting a -1 value.</li> |
| 5285 | <li>The mask is ANDed with <tt>%val</tt> to produce the result. |
| 5286 | </ol> |
Reid Spencer | d6a85b5 | 2007-05-14 16:14:57 +0000 | [diff] [blame] | 5287 | <p>In reverse mode, a similar computation is made except that the bits are |
| 5288 | returned in the reverse order. So, for example, if <tt>X</tt> has the value |
| 5289 | <tt>i16 0x0ACF (101011001111)</tt> and we apply |
| 5290 | <tt>part.select(i16 X, 8, 3)</tt> to it, we get back the value |
| 5291 | <tt>i16 0x0026 (000000100110)</tt>.</p> |
Reid Spencer | a13ba7d | 2007-04-01 19:00:37 +0000 | [diff] [blame] | 5292 | </div> |
| 5293 | |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5294 | <div class="doc_subsubsection"> |
| 5295 | <a name="int_part_set">'<tt>llvm.part.set.*</tt>' Intrinsic</a> |
| 5296 | </div> |
| 5297 | |
| 5298 | <div class="doc_text"> |
| 5299 | |
| 5300 | <h5>Syntax:</h5> |
| 5301 | <p>This is an overloaded intrinsic. You can use <tt>llvm.part.set</tt> |
| 5302 | on any integer bit width. |
| 5303 | <pre> |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 5304 | declare i17 @llvm.part.set.i17.i9 (i17 %val, i9 %repl, i32 %lo, i32 %hi) |
| 5305 | declare i29 @llvm.part.set.i29.i9 (i29 %val, i9 %repl, i32 %lo, i32 %hi) |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5306 | </pre> |
| 5307 | |
| 5308 | <h5>Overview:</h5> |
| 5309 | <p>The '<tt>llvm.part.set</tt>' family of intrinsic functions replaces a range |
| 5310 | of bits in an integer value with another integer value. It returns the integer |
| 5311 | with the replaced bits.</p> |
| 5312 | |
| 5313 | <h5>Arguments:</h5> |
| 5314 | <p>The first argument, <tt>%val</tt> and the result may be integer types of |
| 5315 | any bit width but they must have the same bit width. <tt>%val</tt> is the value |
| 5316 | whose bits will be replaced. The second argument, <tt>%repl</tt> may be an |
| 5317 | integer of any bit width. The third and fourth arguments must be <tt>i32</tt> |
| 5318 | type since they specify only a bit index.</p> |
| 5319 | |
| 5320 | <h5>Semantics:</h5> |
| 5321 | <p>The operation of the '<tt>llvm.part.set</tt>' intrinsic has two modes |
| 5322 | of operation: forwards and reverse. If <tt>%lo</tt> is greater than |
| 5323 | <tt>%hi</tt> then the intrinsic operates in reverse mode. Otherwise it |
| 5324 | operates in forward mode.</p> |
| 5325 | <p>For both modes, the <tt>%repl</tt> value is prepared for use by either |
| 5326 | truncating it down to the size of the replacement area or zero extending it |
| 5327 | up to that size.</p> |
| 5328 | <p>In forward mode, the bits between <tt>%lo</tt> and <tt>%hi</tt> (inclusive) |
| 5329 | are replaced with corresponding bits from <tt>%repl</tt>. That is the 0th bit |
| 5330 | in <tt>%repl</tt> replaces the <tt>%lo</tt>th bit in <tt>%val</tt> and etc. up |
| 5331 | to the <tt>%hi</tt>th bit. |
Reid Spencer | c6749c4 | 2007-05-14 16:50:20 +0000 | [diff] [blame] | 5332 | <p>In reverse mode, a similar computation is made except that the bits are |
| 5333 | reversed. That is, the <tt>0</tt>th bit in <tt>%repl</tt> replaces the |
| 5334 | <tt>%hi</tt> bit in <tt>%val</tt> and etc. down to the <tt>%lo</tt>th bit. |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5335 | <h5>Examples:</h5> |
| 5336 | <pre> |
Reid Spencer | f0dbf64 | 2007-04-12 01:03:03 +0000 | [diff] [blame] | 5337 | llvm.part.set(0xFFFF, 0, 4, 7) -> 0xFF0F |
Reid Spencer | c6749c4 | 2007-05-14 16:50:20 +0000 | [diff] [blame] | 5338 | llvm.part.set(0xFFFF, 0, 7, 4) -> 0xFF0F |
| 5339 | llvm.part.set(0xFFFF, 1, 7, 4) -> 0xFF8F |
| 5340 | llvm.part.set(0xFFFF, F, 8, 3) -> 0xFFE7 |
Reid Spencer | f0dbf64 | 2007-04-12 01:03:03 +0000 | [diff] [blame] | 5341 | llvm.part.set(0xFFFF, 0, 3, 8) -> 0xFE07 |
Reid Spencer | c891084 | 2007-04-11 23:49:50 +0000 | [diff] [blame] | 5342 | </pre> |
Reid Spencer | f86037f | 2007-04-11 23:23:49 +0000 | [diff] [blame] | 5343 | </div> |
| 5344 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 5345 | <!-- ======================================================================= --> |
| 5346 | <div class="doc_subsection"> |
| 5347 | <a name="int_debugger">Debugger Intrinsics</a> |
| 5348 | </div> |
| 5349 | |
| 5350 | <div class="doc_text"> |
| 5351 | <p> |
| 5352 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), |
| 5353 | are described in the <a |
| 5354 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level |
| 5355 | Debugging</a> document. |
| 5356 | </p> |
| 5357 | </div> |
| 5358 | |
| 5359 | |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 5360 | <!-- ======================================================================= --> |
| 5361 | <div class="doc_subsection"> |
| 5362 | <a name="int_eh">Exception Handling Intrinsics</a> |
| 5363 | </div> |
| 5364 | |
| 5365 | <div class="doc_text"> |
| 5366 | <p> The LLVM exception handling intrinsics (which all start with |
| 5367 | <tt>llvm.eh.</tt> prefix), are described in the <a |
| 5368 | href="ExceptionHandling.html#format_common_intrinsics">LLVM Exception |
| 5369 | Handling</a> document. </p> |
| 5370 | </div> |
| 5371 | |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5372 | <!-- ======================================================================= --> |
| 5373 | <div class="doc_subsection"> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5374 | <a name="int_trampoline">Trampoline Intrinsic</a> |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5375 | </div> |
| 5376 | |
| 5377 | <div class="doc_text"> |
| 5378 | <p> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5379 | This intrinsic makes it possible to excise one parameter, marked with |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5380 | the <tt>nest</tt> attribute, from a function. The result is a callable |
| 5381 | function pointer lacking the nest parameter - the caller does not need |
| 5382 | to provide a value for it. Instead, the value to use is stored in |
| 5383 | advance in a "trampoline", a block of memory usually allocated |
| 5384 | on the stack, which also contains code to splice the nest value into the |
| 5385 | argument list. This is used to implement the GCC nested function address |
| 5386 | extension. |
| 5387 | </p> |
| 5388 | <p> |
| 5389 | For example, if the function is |
| 5390 | <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] | 5391 | 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] | 5392 | <pre> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5393 | %tramp = alloca [10 x i8], align 4 ; size and alignment only correct for X86 |
| 5394 | %tramp1 = getelementptr [10 x i8]* %tramp, i32 0, i32 0 |
| 5395 | %p = call i8* @llvm.init.trampoline( i8* %tramp1, i8* bitcast (i32 (i8* nest , i32, i32)* @f to i8*), i8* %nval ) |
| 5396 | %fp = bitcast i8* %p to i32 (i32, i32)* |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5397 | </pre> |
Bill Wendling | 03295ca | 2007-09-22 09:23:55 +0000 | [diff] [blame] | 5398 | <p>The call <tt>%val = call i32 %fp( i32 %x, i32 %y )</tt> is then equivalent |
| 5399 | 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] | 5400 | </div> |
| 5401 | |
| 5402 | <!-- _______________________________________________________________________ --> |
| 5403 | <div class="doc_subsubsection"> |
| 5404 | <a name="int_it">'<tt>llvm.init.trampoline</tt>' Intrinsic</a> |
| 5405 | </div> |
| 5406 | <div class="doc_text"> |
| 5407 | <h5>Syntax:</h5> |
| 5408 | <pre> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5409 | declare i8* @llvm.init.trampoline(i8* <tramp>, i8* <func>, i8* <nval>) |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5410 | </pre> |
| 5411 | <h5>Overview:</h5> |
| 5412 | <p> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5413 | This fills the memory pointed to by <tt>tramp</tt> with code |
| 5414 | and returns a function pointer suitable for executing it. |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5415 | </p> |
| 5416 | <h5>Arguments:</h5> |
| 5417 | <p> |
| 5418 | The <tt>llvm.init.trampoline</tt> intrinsic takes three arguments, all |
| 5419 | pointers. The <tt>tramp</tt> argument must point to a sufficiently large |
| 5420 | 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] | 5421 | intrinsic. Note that the size and the alignment are target-specific - LLVM |
| 5422 | currently provides no portable way of determining them, so a front-end that |
| 5423 | generates this intrinsic needs to have some target-specific knowledge. |
| 5424 | 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] | 5425 | </p> |
| 5426 | <h5>Semantics:</h5> |
| 5427 | <p> |
| 5428 | 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] | 5429 | dependent code, turning it into a function. A pointer to this function is |
| 5430 | returned, but needs to be bitcast to an |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5431 | <a href="#int_trampoline">appropriate function pointer type</a> |
Duncan Sands | f7331b3 | 2007-09-11 14:10:23 +0000 | [diff] [blame] | 5432 | before being called. The new function's signature is the same as that of |
| 5433 | <tt>func</tt> with any arguments marked with the <tt>nest</tt> attribute |
| 5434 | removed. At most one such <tt>nest</tt> argument is allowed, and it must be |
| 5435 | of pointer type. Calling the new function is equivalent to calling |
| 5436 | <tt>func</tt> with the same argument list, but with <tt>nval</tt> used for the |
| 5437 | missing <tt>nest</tt> argument. If, after calling |
| 5438 | <tt>llvm.init.trampoline</tt>, the memory pointed to by <tt>tramp</tt> is |
| 5439 | modified, then the effect of any later call to the returned function pointer is |
| 5440 | undefined. |
Duncan Sands | 36397f5 | 2007-07-27 12:58:54 +0000 | [diff] [blame] | 5441 | </p> |
| 5442 | </div> |
| 5443 | |
| 5444 | <!-- ======================================================================= --> |
| 5445 | <div class="doc_subsection"> |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 5446 | <a name="int_atomics">Atomic Operations and Synchronization Intrinsics</a> |
| 5447 | </div> |
| 5448 | |
| 5449 | <div class="doc_text"> |
| 5450 | <p> |
| 5451 | These intrinsic functions expand the "universal IR" of LLVM to represent |
| 5452 | hardware constructs for atomic operations and memory synchronization. This |
| 5453 | provides an interface to the hardware, not an interface to the programmer. It |
| 5454 | is aimed at a low enough level to allow any programming models or APIs which |
| 5455 | need atomic behaviors to map cleanly onto it. It is also modeled primarily on |
| 5456 | hardware behavior. Just as hardware provides a "universal IR" for source |
| 5457 | languages, it also provides a starting point for developing a "universal" |
| 5458 | atomic operation and synchronization IR. |
| 5459 | </p> |
| 5460 | <p> |
| 5461 | These do <em>not</em> form an API such as high-level threading libraries, |
| 5462 | software transaction memory systems, atomic primitives, and intrinsic |
| 5463 | functions as found in BSD, GNU libc, atomic_ops, APR, and other system and |
| 5464 | application libraries. The hardware interface provided by LLVM should allow |
| 5465 | a clean implementation of all of these APIs and parallel programming models. |
| 5466 | No one model or paradigm should be selected above others unless the hardware |
| 5467 | itself ubiquitously does so. |
| 5468 | |
| 5469 | </p> |
| 5470 | </div> |
| 5471 | |
| 5472 | <!-- _______________________________________________________________________ --> |
| 5473 | <div class="doc_subsubsection"> |
| 5474 | <a name="int_memory_barrier">'<tt>llvm.memory.barrier</tt>' Intrinsic</a> |
| 5475 | </div> |
| 5476 | <div class="doc_text"> |
| 5477 | <h5>Syntax:</h5> |
| 5478 | <pre> |
| 5479 | declare void @llvm.memory.barrier( i1 <ll>, i1 <ls>, i1 <sl>, i1 <ss>, |
| 5480 | i1 <device> ) |
| 5481 | |
| 5482 | </pre> |
| 5483 | <h5>Overview:</h5> |
| 5484 | <p> |
| 5485 | The <tt>llvm.memory.barrier</tt> intrinsic guarantees ordering between |
| 5486 | specific pairs of memory access types. |
| 5487 | </p> |
| 5488 | <h5>Arguments:</h5> |
| 5489 | <p> |
| 5490 | The <tt>llvm.memory.barrier</tt> intrinsic requires five boolean arguments. |
| 5491 | The first four arguments enables a specific barrier as listed below. The fith |
| 5492 | argument specifies that the barrier applies to io or device or uncached memory. |
| 5493 | |
| 5494 | </p> |
| 5495 | <ul> |
| 5496 | <li><tt>ll</tt>: load-load barrier</li> |
| 5497 | <li><tt>ls</tt>: load-store barrier</li> |
| 5498 | <li><tt>sl</tt>: store-load barrier</li> |
| 5499 | <li><tt>ss</tt>: store-store barrier</li> |
| 5500 | <li><tt>device</tt>: barrier applies to device and uncached memory also. |
| 5501 | </ul> |
| 5502 | <h5>Semantics:</h5> |
| 5503 | <p> |
| 5504 | This intrinsic causes the system to enforce some ordering constraints upon |
| 5505 | the loads and stores of the program. This barrier does not indicate |
| 5506 | <em>when</em> any events will occur, it only enforces an <em>order</em> in |
| 5507 | which they occur. For any of the specified pairs of load and store operations |
| 5508 | (f.ex. load-load, or store-load), all of the first operations preceding the |
| 5509 | barrier will complete before any of the second operations succeeding the |
| 5510 | barrier begin. Specifically the semantics for each pairing is as follows: |
| 5511 | </p> |
| 5512 | <ul> |
| 5513 | <li><tt>ll</tt>: All loads before the barrier must complete before any load |
| 5514 | after the barrier begins.</li> |
| 5515 | |
| 5516 | <li><tt>ls</tt>: All loads before the barrier must complete before any |
| 5517 | store after the barrier begins.</li> |
| 5518 | <li><tt>ss</tt>: All stores before the barrier must complete before any |
| 5519 | store after the barrier begins.</li> |
| 5520 | <li><tt>sl</tt>: All stores before the barrier must complete before any |
| 5521 | load after the barrier begins.</li> |
| 5522 | </ul> |
| 5523 | <p> |
| 5524 | These semantics are applied with a logical "and" behavior when more than one |
| 5525 | is enabled in a single memory barrier intrinsic. |
| 5526 | </p> |
| 5527 | <p> |
| 5528 | Backends may implement stronger barriers than those requested when they do not |
| 5529 | support as fine grained a barrier as requested. Some architectures do not |
| 5530 | need all types of barriers and on such architectures, these become noops. |
| 5531 | </p> |
| 5532 | <h5>Example:</h5> |
| 5533 | <pre> |
| 5534 | %ptr = malloc i32 |
| 5535 | store i32 4, %ptr |
| 5536 | |
| 5537 | %result1 = load i32* %ptr <i>; yields {i32}:result1 = 4</i> |
| 5538 | call void @llvm.memory.barrier( i1 false, i1 true, i1 false, i1 false ) |
| 5539 | <i>; guarantee the above finishes</i> |
| 5540 | store i32 8, %ptr <i>; before this begins</i> |
| 5541 | </pre> |
| 5542 | </div> |
| 5543 | |
Andrew Lenharth | ab0b949 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 5544 | <!-- _______________________________________________________________________ --> |
| 5545 | <div class="doc_subsubsection"> |
| 5546 | <a name="int_atomic_lcs">'<tt>llvm.atomic.lcs.*</tt>' Intrinsic</a> |
| 5547 | </div> |
| 5548 | <div class="doc_text"> |
| 5549 | <h5>Syntax:</h5> |
| 5550 | <p> |
| 5551 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.lcs</tt> on any |
| 5552 | integer bit width. Not all targets support all bit widths however.</p> |
| 5553 | |
| 5554 | <pre> |
| 5555 | declare i8 @llvm.atomic.lcs.i8( i8* <ptr>, i8 <cmp>, i8 <val> ) |
| 5556 | declare i16 @llvm.atomic.lcs.i16( i16* <ptr>, i16 <cmp>, i16 <val> ) |
| 5557 | declare i32 @llvm.atomic.lcs.i32( i32* <ptr>, i32 <cmp>, i32 <val> ) |
| 5558 | declare i64 @llvm.atomic.lcs.i64( i64* <ptr>, i64 <cmp>, i64 <val> ) |
| 5559 | |
| 5560 | </pre> |
| 5561 | <h5>Overview:</h5> |
| 5562 | <p> |
| 5563 | This loads a value in memory and compares it to a given value. If they are |
| 5564 | equal, it stores a new value into the memory. |
| 5565 | </p> |
| 5566 | <h5>Arguments:</h5> |
| 5567 | <p> |
| 5568 | The <tt>llvm.atomic.lcs</tt> intrinsic takes three arguments. The result as |
| 5569 | well as both <tt>cmp</tt> and <tt>val</tt> must be integer values with the |
| 5570 | same bit width. The <tt>ptr</tt> argument must be a pointer to a value of |
| 5571 | this integer type. While any bit width integer may be used, targets may only |
| 5572 | lower representations they support in hardware. |
| 5573 | |
| 5574 | </p> |
| 5575 | <h5>Semantics:</h5> |
| 5576 | <p> |
| 5577 | This entire intrinsic must be executed atomically. It first loads the value |
| 5578 | in memory pointed to by <tt>ptr</tt> and compares it with the value |
| 5579 | <tt>cmp</tt>. If they are equal, <tt>val</tt> is stored into the memory. The |
| 5580 | loaded value is yielded in all cases. This provides the equivalent of an |
| 5581 | atomic compare-and-swap operation within the SSA framework. |
| 5582 | </p> |
| 5583 | <h5>Examples:</h5> |
| 5584 | |
| 5585 | <pre> |
| 5586 | %ptr = malloc i32 |
| 5587 | store i32 4, %ptr |
| 5588 | |
| 5589 | %val1 = add i32 4, 4 |
| 5590 | %result1 = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 4, %val1 ) |
| 5591 | <i>; yields {i32}:result1 = 4</i> |
| 5592 | %stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i> |
| 5593 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i> |
| 5594 | |
| 5595 | %val2 = add i32 1, 1 |
| 5596 | %result2 = call i32 @llvm.atomic.lcs.i32( i32* %ptr, i32 5, %val2 ) |
| 5597 | <i>; yields {i32}:result2 = 8</i> |
| 5598 | %stored2 = icmp eq i32 %result2, 5 <i>; yields {i1}:stored2 = false</i> |
| 5599 | |
| 5600 | %memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 8</i> |
| 5601 | </pre> |
| 5602 | </div> |
| 5603 | |
| 5604 | <!-- _______________________________________________________________________ --> |
| 5605 | <div class="doc_subsubsection"> |
| 5606 | <a name="int_atomic_swap">'<tt>llvm.atomic.swap.*</tt>' Intrinsic</a> |
| 5607 | </div> |
| 5608 | <div class="doc_text"> |
| 5609 | <h5>Syntax:</h5> |
| 5610 | |
| 5611 | <p> |
| 5612 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.swap</tt> on any |
| 5613 | integer bit width. Not all targets support all bit widths however.</p> |
| 5614 | <pre> |
| 5615 | declare i8 @llvm.atomic.swap.i8( i8* <ptr>, i8 <val> ) |
| 5616 | declare i16 @llvm.atomic.swap.i16( i16* <ptr>, i16 <val> ) |
| 5617 | declare i32 @llvm.atomic.swap.i32( i32* <ptr>, i32 <val> ) |
| 5618 | declare i64 @llvm.atomic.swap.i64( i64* <ptr>, i64 <val> ) |
| 5619 | |
| 5620 | </pre> |
| 5621 | <h5>Overview:</h5> |
| 5622 | <p> |
| 5623 | This intrinsic loads the value stored in memory at <tt>ptr</tt> and yields |
| 5624 | the value from memory. It then stores the value in <tt>val</tt> in the memory |
| 5625 | at <tt>ptr</tt>. |
| 5626 | </p> |
| 5627 | <h5>Arguments:</h5> |
| 5628 | |
| 5629 | <p> |
| 5630 | The <tt>llvm.atomic.ls</tt> intrinsic takes two arguments. Both the |
| 5631 | <tt>val</tt> argument and the result must be integers of the same bit width. |
| 5632 | The first argument, <tt>ptr</tt>, must be a pointer to a value of this |
| 5633 | integer type. The targets may only lower integer representations they |
| 5634 | support. |
| 5635 | </p> |
| 5636 | <h5>Semantics:</h5> |
| 5637 | <p> |
| 5638 | This intrinsic loads the value pointed to by <tt>ptr</tt>, yields it, and |
| 5639 | stores <tt>val</tt> back into <tt>ptr</tt> atomically. This provides the |
| 5640 | equivalent of an atomic swap operation within the SSA framework. |
| 5641 | |
| 5642 | </p> |
| 5643 | <h5>Examples:</h5> |
| 5644 | <pre> |
| 5645 | %ptr = malloc i32 |
| 5646 | store i32 4, %ptr |
| 5647 | |
| 5648 | %val1 = add i32 4, 4 |
| 5649 | %result1 = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val1 ) |
| 5650 | <i>; yields {i32}:result1 = 4</i> |
| 5651 | %stored1 = icmp eq i32 %result1, 4 <i>; yields {i1}:stored1 = true</i> |
| 5652 | %memval1 = load i32* %ptr <i>; yields {i32}:memval1 = 8</i> |
| 5653 | |
| 5654 | %val2 = add i32 1, 1 |
| 5655 | %result2 = call i32 @llvm.atomic.swap.i32( i32* %ptr, i32 %val2 ) |
| 5656 | <i>; yields {i32}:result2 = 8</i> |
| 5657 | |
| 5658 | %stored2 = icmp eq i32 %result2, 8 <i>; yields {i1}:stored2 = true</i> |
| 5659 | %memval2 = load i32* %ptr <i>; yields {i32}:memval2 = 2</i> |
| 5660 | </pre> |
| 5661 | </div> |
| 5662 | |
| 5663 | <!-- _______________________________________________________________________ --> |
| 5664 | <div class="doc_subsubsection"> |
| 5665 | <a name="int_atomic_las">'<tt>llvm.atomic.las.*</tt>' Intrinsic</a> |
| 5666 | |
| 5667 | </div> |
| 5668 | <div class="doc_text"> |
| 5669 | <h5>Syntax:</h5> |
| 5670 | <p> |
| 5671 | This is an overloaded intrinsic. You can use <tt>llvm.atomic.las</tt> on any |
| 5672 | integer bit width. Not all targets support all bit widths however.</p> |
| 5673 | <pre> |
| 5674 | declare i8 @llvm.atomic.las.i8.( i8* <ptr>, i8 <delta> ) |
| 5675 | declare i16 @llvm.atomic.las.i16.( i16* <ptr>, i16 <delta> ) |
| 5676 | declare i32 @llvm.atomic.las.i32.( i32* <ptr>, i32 <delta> ) |
| 5677 | declare i64 @llvm.atomic.las.i64.( i64* <ptr>, i64 <delta> ) |
| 5678 | |
| 5679 | </pre> |
| 5680 | <h5>Overview:</h5> |
| 5681 | <p> |
| 5682 | This intrinsic adds <tt>delta</tt> to the value stored in memory at |
| 5683 | <tt>ptr</tt>. It yields the original value at <tt>ptr</tt>. |
| 5684 | </p> |
| 5685 | <h5>Arguments:</h5> |
| 5686 | <p> |
| 5687 | |
| 5688 | The intrinsic takes two arguments, the first a pointer to an integer value |
| 5689 | and the second an integer value. The result is also an integer value. These |
| 5690 | integer types can have any bit width, but they must all have the same bit |
| 5691 | width. The targets may only lower integer representations they support. |
| 5692 | </p> |
| 5693 | <h5>Semantics:</h5> |
| 5694 | <p> |
| 5695 | This intrinsic does a series of operations atomically. It first loads the |
| 5696 | value stored at <tt>ptr</tt>. It then adds <tt>delta</tt>, stores the result |
| 5697 | to <tt>ptr</tt>. It yields the original value stored at <tt>ptr</tt>. |
| 5698 | </p> |
| 5699 | |
| 5700 | <h5>Examples:</h5> |
| 5701 | <pre> |
| 5702 | %ptr = malloc i32 |
| 5703 | store i32 4, %ptr |
| 5704 | %result1 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 4 ) |
| 5705 | <i>; yields {i32}:result1 = 4</i> |
| 5706 | %result2 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 2 ) |
| 5707 | <i>; yields {i32}:result2 = 8</i> |
| 5708 | %result3 = call i32 @llvm.atomic.las.i32( i32* %ptr, i32 5 ) |
| 5709 | <i>; yields {i32}:result3 = 10</i> |
| 5710 | %memval = load i32* %ptr <i>; yields {i32}:memval1 = 15</i> |
| 5711 | </pre> |
| 5712 | </div> |
| 5713 | |
Andrew Lenharth | 22c5c1b | 2008-02-16 01:24:58 +0000 | [diff] [blame] | 5714 | |
| 5715 | <!-- ======================================================================= --> |
| 5716 | <div class="doc_subsection"> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5717 | <a name="int_general">General Intrinsics</a> |
| 5718 | </div> |
| 5719 | |
| 5720 | <div class="doc_text"> |
| 5721 | <p> This class of intrinsics is designed to be generic and has |
| 5722 | no specific purpose. </p> |
| 5723 | </div> |
| 5724 | |
| 5725 | <!-- _______________________________________________________________________ --> |
| 5726 | <div class="doc_subsubsection"> |
| 5727 | <a name="int_var_annotation">'<tt>llvm.var.annotation</tt>' Intrinsic</a> |
| 5728 | </div> |
| 5729 | |
| 5730 | <div class="doc_text"> |
| 5731 | |
| 5732 | <h5>Syntax:</h5> |
| 5733 | <pre> |
Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 5734 | 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] | 5735 | </pre> |
| 5736 | |
| 5737 | <h5>Overview:</h5> |
| 5738 | |
| 5739 | <p> |
| 5740 | The '<tt>llvm.var.annotation</tt>' intrinsic |
| 5741 | </p> |
| 5742 | |
| 5743 | <h5>Arguments:</h5> |
| 5744 | |
| 5745 | <p> |
Tanya Lattner | d2e8442 | 2007-06-18 23:42:37 +0000 | [diff] [blame] | 5746 | The first argument is a pointer to a value, the second is a pointer to a |
| 5747 | global string, the third is a pointer to a global string which is the source |
| 5748 | file name, and the last argument is the line number. |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5749 | </p> |
| 5750 | |
| 5751 | <h5>Semantics:</h5> |
| 5752 | |
| 5753 | <p> |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 5754 | This intrinsic allows annotation of local variables with arbitrary strings. |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5755 | 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] | 5756 | annotations. These have no other defined use, they are ignored by code |
| 5757 | generation and optimization. |
| 5758 | </p> |
Tanya Lattner | 6d806e9 | 2007-06-15 20:50:54 +0000 | [diff] [blame] | 5759 | </div> |
| 5760 | |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5761 | <!-- _______________________________________________________________________ --> |
| 5762 | <div class="doc_subsubsection"> |
Tanya Lattner | e1a8da0 | 2007-09-21 23:57:59 +0000 | [diff] [blame] | 5763 | <a name="int_annotation">'<tt>llvm.annotation.*</tt>' Intrinsic</a> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5764 | </div> |
| 5765 | |
| 5766 | <div class="doc_text"> |
| 5767 | |
| 5768 | <h5>Syntax:</h5> |
Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 5769 | <p>This is an overloaded intrinsic. You can use '<tt>llvm.annotation</tt>' on |
| 5770 | any integer bit width. |
| 5771 | </p> |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5772 | <pre> |
Tanya Lattner | d3989a8 | 2007-09-22 00:03:01 +0000 | [diff] [blame] | 5773 | declare i8 @llvm.annotation.i8(i8 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 5774 | declare i16 @llvm.annotation.i16(i16 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 5775 | declare i32 @llvm.annotation.i32(i32 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 5776 | declare i64 @llvm.annotation.i64(i64 <val>, i8* <str>, i8* <str>, i32 <int> ) |
| 5777 | 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] | 5778 | </pre> |
| 5779 | |
| 5780 | <h5>Overview:</h5> |
Tanya Lattner | 39cfba6 | 2007-09-21 23:56:27 +0000 | [diff] [blame] | 5781 | |
| 5782 | <p> |
| 5783 | The '<tt>llvm.annotation</tt>' intrinsic. |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5784 | </p> |
| 5785 | |
| 5786 | <h5>Arguments:</h5> |
| 5787 | |
| 5788 | <p> |
| 5789 | The first argument is an integer value (result of some expression), |
| 5790 | the second is a pointer to a global string, the third is a pointer to a global |
| 5791 | 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] | 5792 | It returns the value of the first argument. |
Tanya Lattner | b636788 | 2007-09-21 22:59:12 +0000 | [diff] [blame] | 5793 | </p> |
| 5794 | |
| 5795 | <h5>Semantics:</h5> |
| 5796 | |
| 5797 | <p> |
| 5798 | This intrinsic allows annotations to be put on arbitrary expressions |
| 5799 | with arbitrary strings. This can be useful for special purpose optimizations |
| 5800 | that want to look for these annotations. These have no other defined use, they |
| 5801 | are ignored by code generation and optimization. |
| 5802 | </div> |
Jim Laskey | dd4ef1b | 2007-03-14 19:31:19 +0000 | [diff] [blame] | 5803 | |
Anton Korobeynikov | 4cb8618 | 2008-01-15 22:31:34 +0000 | [diff] [blame] | 5804 | <!-- _______________________________________________________________________ --> |
| 5805 | <div class="doc_subsubsection"> |
| 5806 | <a name="int_trap">'<tt>llvm.trap</tt>' Intrinsic</a> |
| 5807 | </div> |
| 5808 | |
| 5809 | <div class="doc_text"> |
| 5810 | |
| 5811 | <h5>Syntax:</h5> |
| 5812 | <pre> |
| 5813 | declare void @llvm.trap() |
| 5814 | </pre> |
| 5815 | |
| 5816 | <h5>Overview:</h5> |
| 5817 | |
| 5818 | <p> |
| 5819 | The '<tt>llvm.trap</tt>' intrinsic |
| 5820 | </p> |
| 5821 | |
| 5822 | <h5>Arguments:</h5> |
| 5823 | |
| 5824 | <p> |
| 5825 | None |
| 5826 | </p> |
| 5827 | |
| 5828 | <h5>Semantics:</h5> |
| 5829 | |
| 5830 | <p> |
| 5831 | This intrinsics is lowered to the target dependent trap instruction. If the |
| 5832 | target does not have a trap instruction, this intrinsic will be lowered to the |
| 5833 | call of the abort() function. |
| 5834 | </p> |
| 5835 | </div> |
| 5836 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 5837 | <!-- *********************************************************************** --> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 5838 | <hr> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 5839 | <address> |
| 5840 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 5841 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 5842 | <a href="http://validator.w3.org/check/referer"><img |
Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 5843 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 5844 | |
| 5845 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 5846 | <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 5847 | Last modified: $Date$ |
| 5848 | </address> |
Chris Lattner | c7d3ab3 | 2008-01-04 04:33:49 +0000 | [diff] [blame] | 5849 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 5850 | </body> |
| 5851 | </html> |