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> |
| 27 | <li><a href="#moduleasm">Module-Level Inline Assembly</a></li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 28 | </ol> |
| 29 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 30 | <li><a href="#typesystem">Type System</a> |
| 31 | <ol> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 32 | <li><a href="#t_primitive">Primitive Types</a> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 33 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 34 | <li><a href="#t_classifications">Type Classifications</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 35 | </ol> |
| 36 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 37 | <li><a href="#t_derived">Derived Types</a> |
| 38 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 39 | <li><a href="#t_array">Array Type</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 40 | <li><a href="#t_function">Function Type</a></li> |
| 41 | <li><a href="#t_pointer">Pointer Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 42 | <li><a href="#t_struct">Structure Type</a></li> |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 43 | <li><a href="#t_packed">Packed Type</a></li> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 44 | <li><a href="#t_opaque">Opaque Type</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 45 | </ol> |
| 46 | </li> |
| 47 | </ol> |
| 48 | </li> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 49 | <li><a href="#constants">Constants</a> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 50 | <ol> |
| 51 | <li><a href="#simpleconstants">Simple Constants</a> |
| 52 | <li><a href="#aggregateconstants">Aggregate Constants</a> |
| 53 | <li><a href="#globalconstants">Global Variable and Function Addresses</a> |
| 54 | <li><a href="#undefvalues">Undefined Values</a> |
| 55 | <li><a href="#constantexprs">Constant Expressions</a> |
| 56 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 57 | </li> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 58 | <li><a href="#othervalues">Other Values</a> |
| 59 | <ol> |
| 60 | <li><a href="#inlineasm">Inline Assembler Expressions</a> |
| 61 | </ol> |
| 62 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 63 | <li><a href="#instref">Instruction Reference</a> |
| 64 | <ol> |
| 65 | <li><a href="#terminators">Terminator Instructions</a> |
| 66 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 67 | <li><a href="#i_ret">'<tt>ret</tt>' Instruction</a></li> |
| 68 | <li><a href="#i_br">'<tt>br</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 69 | <li><a href="#i_switch">'<tt>switch</tt>' Instruction</a></li> |
| 70 | <li><a href="#i_invoke">'<tt>invoke</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 71 | <li><a href="#i_unwind">'<tt>unwind</tt>' Instruction</a></li> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 72 | <li><a href="#i_unreachable">'<tt>unreachable</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 73 | </ol> |
| 74 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 75 | <li><a href="#binaryops">Binary Operations</a> |
| 76 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 77 | <li><a href="#i_add">'<tt>add</tt>' Instruction</a></li> |
| 78 | <li><a href="#i_sub">'<tt>sub</tt>' Instruction</a></li> |
| 79 | <li><a href="#i_mul">'<tt>mul</tt>' Instruction</a></li> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 80 | <li><a href="#i_udiv">'<tt>udiv</tt>' Instruction</a></li> |
| 81 | <li><a href="#i_sdiv">'<tt>sdiv</tt>' Instruction</a></li> |
| 82 | <li><a href="#i_fdiv">'<tt>fdiv</tt>' Instruction</a></li> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 83 | <li><a href="#i_urem">'<tt>urem</tt>' Instruction</a></li> |
| 84 | <li><a href="#i_srem">'<tt>srem</tt>' Instruction</a></li> |
| 85 | <li><a href="#i_frem">'<tt>frem</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 86 | <li><a href="#i_setcc">'<tt>set<i>cc</i></tt>' Instructions</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 87 | </ol> |
| 88 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 89 | <li><a href="#bitwiseops">Bitwise Binary Operations</a> |
| 90 | <ol> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 91 | <li><a href="#i_and">'<tt>and</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 92 | <li><a href="#i_or">'<tt>or</tt>' Instruction</a></li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 93 | <li><a href="#i_xor">'<tt>xor</tt>' Instruction</a></li> |
| 94 | <li><a href="#i_shl">'<tt>shl</tt>' Instruction</a></li> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 95 | <li><a href="#i_lshr">'<tt>lshr</tt>' Instruction</a></li> |
| 96 | <li><a href="#i_ashr">'<tt>ashr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 97 | </ol> |
| 98 | </li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 99 | <li><a href="#vectorops">Vector Operations</a> |
| 100 | <ol> |
| 101 | <li><a href="#i_extractelement">'<tt>extractelement</tt>' Instruction</a></li> |
| 102 | <li><a href="#i_insertelement">'<tt>insertelement</tt>' Instruction</a></li> |
| 103 | <li><a href="#i_shufflevector">'<tt>shufflevector</tt>' Instruction</a></li> |
Tanya Lattner | 0947429 | 2006-04-14 19:24:33 +0000 | [diff] [blame] | 104 | <li><a href="#i_vsetint">'<tt>vsetint</tt>' Instruction</a></li> |
| 105 | <li><a href="#i_vsetfp">'<tt>vsetfp</tt>' Instruction</a></li> |
| 106 | <li><a href="#i_vselect">'<tt>vselect</tt>' Instruction</a></li> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 107 | </ol> |
| 108 | </li> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 109 | <li><a href="#memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 110 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 111 | <li><a href="#i_malloc">'<tt>malloc</tt>' Instruction</a></li> |
| 112 | <li><a href="#i_free">'<tt>free</tt>' Instruction</a></li> |
| 113 | <li><a href="#i_alloca">'<tt>alloca</tt>' Instruction</a></li> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 114 | <li><a href="#i_load">'<tt>load</tt>' Instruction</a></li> |
| 115 | <li><a href="#i_store">'<tt>store</tt>' Instruction</a></li> |
| 116 | <li><a href="#i_getelementptr">'<tt>getelementptr</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 117 | </ol> |
| 118 | </li> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 119 | <li><a href="#convertops">Conversion Operations</a> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 120 | <ol> |
| 121 | <li><a href="#i_trunc">'<tt>trunc .. to</tt>' Instruction</a></li> |
| 122 | <li><a href="#i_zext">'<tt>zext .. to</tt>' Instruction</a></li> |
| 123 | <li><a href="#i_sext">'<tt>sext .. to</tt>' Instruction</a></li> |
| 124 | <li><a href="#i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a></li> |
| 125 | <li><a href="#i_fpext">'<tt>fpext .. to</tt>' Instruction</a></li> |
| 126 | <li><a href="#i_fp2uint">'<tt>fp2uint .. to</tt>' Instruction</a></li> |
| 127 | <li><a href="#i_fp2sint">'<tt>fp2sint .. to</tt>' Instruction</a></li> |
| 128 | <li><a href="#i_uint2fp">'<tt>uint2fp .. to</tt>' Instruction</a></li> |
| 129 | <li><a href="#i_sint2fp">'<tt>sint2fp .. to</tt>' Instruction</a></li> |
| 130 | <li><a href="#i_bitconvert">'<tt>bitconvert .. to</tt>' Instruction</a></li> |
| 131 | </ol> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 132 | <li><a href="#otherops">Other Operations</a> |
| 133 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 134 | <li><a href="#i_phi">'<tt>phi</tt>' Instruction</a></li> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 135 | <li><a href="#i_select">'<tt>select</tt>' Instruction</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 136 | <li><a href="#i_call">'<tt>call</tt>' Instruction</a></li> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 137 | <li><a href="#i_va_arg">'<tt>va_arg</tt>' Instruction</a></li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 138 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 139 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 140 | </ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 141 | </li> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 142 | <li><a href="#intrinsics">Intrinsic Functions</a> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 143 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 144 | <li><a href="#int_varargs">Variable Argument Handling Intrinsics</a> |
| 145 | <ol> |
| 146 | <li><a href="#i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a></li> |
| 147 | <li><a href="#i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a></li> |
| 148 | <li><a href="#i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a></li> |
| 149 | </ol> |
| 150 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 151 | <li><a href="#int_gc">Accurate Garbage Collection Intrinsics</a> |
| 152 | <ol> |
| 153 | <li><a href="#i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a></li> |
| 154 | <li><a href="#i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a></li> |
| 155 | <li><a href="#i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a></li> |
| 156 | </ol> |
| 157 | </li> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 158 | <li><a href="#int_codegen">Code Generator Intrinsics</a> |
| 159 | <ol> |
| 160 | <li><a href="#i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a></li> |
| 161 | <li><a href="#i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a></li> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 162 | <li><a href="#i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a></li> |
| 163 | <li><a href="#i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a></li> |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 164 | <li><a href="#i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a></li> |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 165 | <li><a href="#i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a></li> |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 166 | <li><a href="#i_readcyclecounter"><tt>llvm.readcyclecounter</tt>' Intrinsic</a></li> |
John Criswell | 7123e27 | 2004-04-09 16:43:20 +0000 | [diff] [blame] | 167 | </ol> |
| 168 | </li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 169 | <li><a href="#int_libc">Standard C Library Intrinsics</a> |
| 170 | <ol> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 171 | <li><a href="#i_memcpy">'<tt>llvm.memcpy.*</tt>' Intrinsic</a></li> |
| 172 | <li><a href="#i_memmove">'<tt>llvm.memmove.*</tt>' Intrinsic</a></li> |
| 173 | <li><a href="#i_memset">'<tt>llvm.memset.*</tt>' Intrinsic</a></li> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 174 | <li><a href="#i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a></li> |
| 175 | <li><a href="#i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a></li> |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 176 | <li><a href="#i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a></li> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 177 | </ol> |
| 178 | </li> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 179 | <li><a href="#int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 180 | <ol> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 181 | <li><a href="#i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a></li> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 182 | <li><a href="#int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic </a></li> |
| 183 | <li><a href="#int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic </a></li> |
| 184 | <li><a href="#int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic </a></li> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 185 | </ol> |
| 186 | </li> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 187 | <li><a href="#int_debugger">Debugger intrinsics</a></li> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 188 | </ol> |
| 189 | </li> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 190 | </ol> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 191 | |
| 192 | <div class="doc_author"> |
| 193 | <p>Written by <a href="mailto:sabre@nondot.org">Chris Lattner</a> |
| 194 | and <a href="mailto:vadve@cs.uiuc.edu">Vikram Adve</a></p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 195 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 197 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 198 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 199 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 200 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 201 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 202 | <p>This document is a reference manual for the LLVM assembly language. |
| 203 | LLVM is an SSA based representation that provides type safety, |
| 204 | low-level operations, flexibility, and the capability of representing |
| 205 | 'all' high-level languages cleanly. It is the common code |
| 206 | representation used throughout all phases of the LLVM compilation |
| 207 | strategy.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 208 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 209 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 210 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 211 | <div class="doc_section"> <a name="introduction">Introduction</a> </div> |
| 212 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 213 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 214 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 215 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 216 | <p>The LLVM code representation is designed to be used in three |
| 217 | different forms: as an in-memory compiler IR, as an on-disk bytecode |
| 218 | representation (suitable for fast loading by a Just-In-Time compiler), |
| 219 | and as a human readable assembly language representation. This allows |
| 220 | LLVM to provide a powerful intermediate representation for efficient |
| 221 | compiler transformations and analysis, while providing a natural means |
| 222 | to debug and visualize the transformations. The three different forms |
| 223 | of LLVM are all equivalent. This document describes the human readable |
| 224 | representation and notation.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 225 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 226 | <p>The LLVM representation aims to be light-weight and low-level |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 227 | while being expressive, typed, and extensible at the same time. It |
| 228 | aims to be a "universal IR" of sorts, by being at a low enough level |
| 229 | that high-level ideas may be cleanly mapped to it (similar to how |
| 230 | microprocessors are "universal IR's", allowing many source languages to |
| 231 | be mapped to them). By providing type information, LLVM can be used as |
| 232 | the target of optimizations: for example, through pointer analysis, it |
| 233 | can be proven that a C automatic variable is never accessed outside of |
| 234 | the current function... allowing it to be promoted to a simple SSA |
| 235 | value instead of a memory location.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 236 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 237 | </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 238 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 239 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 240 | <div class="doc_subsubsection"> <a name="wellformed">Well-Formedness</a> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 241 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 242 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 243 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 244 | <p>It is important to note that this document describes 'well formed' |
| 245 | LLVM assembly language. There is a difference between what the parser |
| 246 | accepts and what is considered 'well formed'. For example, the |
| 247 | following instruction is syntactically okay, but not well formed:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 248 | |
| 249 | <pre> |
| 250 | %x = <a href="#i_add">add</a> int 1, %x |
| 251 | </pre> |
| 252 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 253 | <p>...because the definition of <tt>%x</tt> does not dominate all of |
| 254 | its uses. The LLVM infrastructure provides a verification pass that may |
| 255 | 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] | 256 | automatically run by the parser after parsing input assembly and by |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 257 | the optimizer before it outputs bytecode. The violations pointed out |
| 258 | by the verifier pass indicate bugs in transformation passes or input to |
| 259 | the parser.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 260 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 261 | <!-- Describe the typesetting conventions here. --> </div> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 262 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 263 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 264 | <div class="doc_section"> <a name="identifiers">Identifiers</a> </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 265 | <!-- *********************************************************************** --> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 266 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 267 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 268 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 269 | <p>LLVM uses three different forms of identifiers, for different |
| 270 | purposes:</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 271 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 272 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 273 | <li>Named values are represented as a string of characters with a '%' prefix. |
| 274 | For example, %foo, %DivisionByZero, %a.really.long.identifier. The actual |
| 275 | regular expression used is '<tt>%[a-zA-Z$._][a-zA-Z$._0-9]*</tt>'. |
| 276 | Identifiers which require other characters in their names can be surrounded |
| 277 | with quotes. In this way, anything except a <tt>"</tt> character can be used |
| 278 | in a name.</li> |
| 279 | |
| 280 | <li>Unnamed values are represented as an unsigned numeric value with a '%' |
| 281 | prefix. For example, %12, %2, %44.</li> |
| 282 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 283 | <li>Constants, which are described in a <a href="#constants">section about |
| 284 | constants</a>, below.</li> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 285 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 286 | |
| 287 | <p>LLVM requires that values start with a '%' sign for two reasons: Compilers |
| 288 | don't need to worry about name clashes with reserved words, and the set of |
| 289 | reserved words may be expanded in the future without penalty. Additionally, |
| 290 | unnamed identifiers allow a compiler to quickly come up with a temporary |
| 291 | variable without having to avoid symbol table conflicts.</p> |
| 292 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 293 | <p>Reserved words in LLVM are very similar to reserved words in other |
| 294 | languages. There are keywords for different opcodes ('<tt><a |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 295 | href="#i_add">add</a></tt>', '<tt><a href="#i_cast">cast</a></tt>', '<tt><a |
| 296 | href="#i_ret">ret</a></tt>', etc...), for primitive type names ('<tt><a |
| 297 | href="#t_void">void</a></tt>', '<tt><a href="#t_uint">uint</a></tt>', etc...), |
| 298 | and others. These reserved words cannot conflict with variable names, because |
| 299 | none of them start with a '%' character.</p> |
| 300 | |
| 301 | <p>Here is an example of LLVM code to multiply the integer variable |
| 302 | '<tt>%X</tt>' by 8:</p> |
| 303 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 304 | <p>The easy way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 305 | |
| 306 | <pre> |
| 307 | %result = <a href="#i_mul">mul</a> uint %X, 8 |
| 308 | </pre> |
| 309 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 310 | <p>After strength reduction:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 311 | |
| 312 | <pre> |
| 313 | %result = <a href="#i_shl">shl</a> uint %X, ubyte 3 |
| 314 | </pre> |
| 315 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 316 | <p>And the hard way:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 317 | |
| 318 | <pre> |
| 319 | <a href="#i_add">add</a> uint %X, %X <i>; yields {uint}:%0</i> |
| 320 | <a href="#i_add">add</a> uint %0, %0 <i>; yields {uint}:%1</i> |
| 321 | %result = <a href="#i_add">add</a> uint %1, %1 |
| 322 | </pre> |
| 323 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 324 | <p>This last way of multiplying <tt>%X</tt> by 8 illustrates several |
| 325 | important lexical features of LLVM:</p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 326 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 327 | <ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 328 | |
| 329 | <li>Comments are delimited with a '<tt>;</tt>' and go until the end of |
| 330 | line.</li> |
| 331 | |
| 332 | <li>Unnamed temporaries are created when the result of a computation is not |
| 333 | assigned to a named value.</li> |
| 334 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 335 | <li>Unnamed temporaries are numbered sequentially</li> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 336 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 337 | </ol> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 338 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 339 | <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] | 340 | demonstrating instructions, we will follow an instruction with a comment that |
| 341 | defines the type and name of value produced. Comments are shown in italic |
| 342 | text.</p> |
| 343 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 344 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 345 | |
| 346 | <!-- *********************************************************************** --> |
| 347 | <div class="doc_section"> <a name="highlevel">High Level Structure</a> </div> |
| 348 | <!-- *********************************************************************** --> |
| 349 | |
| 350 | <!-- ======================================================================= --> |
| 351 | <div class="doc_subsection"> <a name="modulestructure">Module Structure</a> |
| 352 | </div> |
| 353 | |
| 354 | <div class="doc_text"> |
| 355 | |
| 356 | <p>LLVM programs are composed of "Module"s, each of which is a |
| 357 | translation unit of the input programs. Each module consists of |
| 358 | functions, global variables, and symbol table entries. Modules may be |
| 359 | combined together with the LLVM linker, which merges function (and |
| 360 | global variable) definitions, resolves forward declarations, and merges |
| 361 | symbol table entries. Here is an example of the "hello world" module:</p> |
| 362 | |
| 363 | <pre><i>; Declare the string constant as a global constant...</i> |
| 364 | <a href="#identifiers">%.LC0</a> = <a href="#linkage_internal">internal</a> <a |
| 365 | href="#globalvars">constant</a> <a href="#t_array">[13 x sbyte]</a> c"hello world\0A\00" <i>; [13 x sbyte]*</i> |
| 366 | |
| 367 | <i>; External declaration of the puts function</i> |
| 368 | <a href="#functionstructure">declare</a> int %puts(sbyte*) <i>; int(sbyte*)* </i> |
| 369 | |
Chris Lattner | 81c01f0 | 2006-06-13 03:05:47 +0000 | [diff] [blame] | 370 | <i>; Global variable / Function body section separator</i> |
| 371 | implementation |
| 372 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 373 | <i>; Definition of main function</i> |
| 374 | int %main() { <i>; int()* </i> |
| 375 | <i>; Convert [13x sbyte]* to sbyte *...</i> |
| 376 | %cast210 = <a |
| 377 | href="#i_getelementptr">getelementptr</a> [13 x sbyte]* %.LC0, long 0, long 0 <i>; sbyte*</i> |
| 378 | |
| 379 | <i>; Call puts function to write out the string to stdout...</i> |
| 380 | <a |
| 381 | href="#i_call">call</a> int %puts(sbyte* %cast210) <i>; int</i> |
| 382 | <a |
| 383 | href="#i_ret">ret</a> int 0<br>}<br></pre> |
| 384 | |
| 385 | <p>This example is made up of a <a href="#globalvars">global variable</a> |
| 386 | named "<tt>.LC0</tt>", an external declaration of the "<tt>puts</tt>" |
| 387 | function, and a <a href="#functionstructure">function definition</a> |
| 388 | for "<tt>main</tt>".</p> |
| 389 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 390 | <p>In general, a module is made up of a list of global values, |
| 391 | where both functions and global variables are global values. Global values are |
| 392 | represented by a pointer to a memory location (in this case, a pointer to an |
| 393 | array of char, and a pointer to a function), and have one of the following <a |
| 394 | href="#linkage">linkage types</a>.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 395 | |
Chris Lattner | 81c01f0 | 2006-06-13 03:05:47 +0000 | [diff] [blame] | 396 | <p>Due to a limitation in the current LLVM assembly parser (it is limited by |
| 397 | one-token lookahead), modules are split into two pieces by the "implementation" |
| 398 | keyword. Global variable prototypes and definitions must occur before the |
| 399 | keyword, and function definitions must occur after it. Function prototypes may |
| 400 | occur either before or after it. In the future, the implementation keyword may |
| 401 | become a noop, if the parser gets smarter.</p> |
| 402 | |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 403 | </div> |
| 404 | |
| 405 | <!-- ======================================================================= --> |
| 406 | <div class="doc_subsection"> |
| 407 | <a name="linkage">Linkage Types</a> |
| 408 | </div> |
| 409 | |
| 410 | <div class="doc_text"> |
| 411 | |
| 412 | <p> |
| 413 | All Global Variables and Functions have one of the following types of linkage: |
| 414 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 415 | |
| 416 | <dl> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 417 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 418 | <dt><tt><b><a name="linkage_internal">internal</a></b></tt> </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 419 | |
| 420 | <dd>Global values with internal linkage are only directly accessible by |
| 421 | objects in the current module. In particular, linking code into a module with |
| 422 | an internal global value may cause the internal to be renamed as necessary to |
| 423 | avoid collisions. Because the symbol is internal to the module, all |
| 424 | references can be updated. This corresponds to the notion of the |
| 425 | '<tt>static</tt>' keyword in C, or the idea of "anonymous namespaces" in C++. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 426 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 427 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 428 | <dt><tt><b><a name="linkage_linkonce">linkonce</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 429 | |
| 430 | <dd>"<tt>linkonce</tt>" linkage is similar to <tt>internal</tt> linkage, with |
| 431 | the twist that linking together two modules defining the same |
| 432 | <tt>linkonce</tt> globals will cause one of the globals to be discarded. This |
| 433 | is typically used to implement inline functions. Unreferenced |
| 434 | <tt>linkonce</tt> globals are allowed to be discarded. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 435 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 436 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 437 | <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 438 | |
| 439 | <dd>"<tt>weak</tt>" linkage is exactly the same as <tt>linkonce</tt> linkage, |
| 440 | except that unreferenced <tt>weak</tt> globals may not be discarded. This is |
| 441 | used to implement constructs in C such as "<tt>int X;</tt>" at global scope. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 442 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 443 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 444 | <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 445 | |
| 446 | <dd>"<tt>appending</tt>" linkage may only be applied to global variables of |
| 447 | pointer to array type. When two global variables with appending linkage are |
| 448 | linked together, the two global arrays are appended together. This is the |
| 449 | LLVM, typesafe, equivalent of having the system linker append together |
| 450 | "sections" with identical names when .o files are linked. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 451 | </dd> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 452 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 453 | <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] | 454 | |
| 455 | <dd>If none of the above identifiers are used, the global is externally |
| 456 | visible, meaning that it participates in linkage and can be used to resolve |
| 457 | external symbol references. |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 458 | </dd> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 459 | |
| 460 | <dt><tt><b><a name="linkage_externweak">extern_weak</a></b></tt>: </dt> |
| 461 | |
| 462 | <dd>"<tt>extern_weak</tt>" TBD |
| 463 | </dd> |
| 464 | |
| 465 | <p> |
| 466 | The next two types of linkage are targeted for Microsoft Windows platform |
| 467 | only. They are designed to support importing (exporting) symbols from (to) |
| 468 | DLLs. |
| 469 | </p> |
| 470 | |
| 471 | <dt><tt><b><a name="linkage_dllimport">dllimport</a></b></tt>: </dt> |
| 472 | |
| 473 | <dd>"<tt>dllimport</tt>" linkage causes the compiler to reference a function |
| 474 | or variable via a global pointer to a pointer that is set up by the DLL |
| 475 | exporting the symbol. On Microsoft Windows targets, the pointer name is |
| 476 | formed by combining <code>_imp__</code> and the function or variable name. |
| 477 | </dd> |
| 478 | |
| 479 | <dt><tt><b><a name="linkage_dllexport">dllexport</a></b></tt>: </dt> |
| 480 | |
| 481 | <dd>"<tt>dllexport</tt>" linkage causes the compiler to provide a global |
| 482 | pointer to a pointer in a DLL, so that it can be referenced with the |
| 483 | <tt>dllimport</tt> attribute. On Microsoft Windows targets, the pointer |
| 484 | name is formed by combining <code>_imp__</code> and the function or variable |
| 485 | name. |
| 486 | </dd> |
| 487 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 488 | </dl> |
| 489 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 490 | <p><a name="linkage_external">For example, since the "<tt>.LC0</tt>" |
| 491 | variable is defined to be internal, if another module defined a "<tt>.LC0</tt>" |
| 492 | variable and was linked with this one, one of the two would be renamed, |
| 493 | preventing a collision. Since "<tt>main</tt>" and "<tt>puts</tt>" are |
| 494 | external (i.e., lacking any linkage declarations), they are accessible |
| 495 | outside of the current module. It is illegal for a function <i>declaration</i> |
| 496 | to have any linkage type other than "externally visible".</a></p> |
Chris Lattner | e5d947b | 2004-12-09 16:36:40 +0000 | [diff] [blame] | 497 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 498 | </div> |
| 499 | |
| 500 | <!-- ======================================================================= --> |
| 501 | <div class="doc_subsection"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 502 | <a name="callingconv">Calling Conventions</a> |
| 503 | </div> |
| 504 | |
| 505 | <div class="doc_text"> |
| 506 | |
| 507 | <p>LLVM <a href="#functionstructure">functions</a>, <a href="#i_call">calls</a> |
| 508 | and <a href="#i_invoke">invokes</a> can all have an optional calling convention |
| 509 | specified for the call. The calling convention of any pair of dynamic |
| 510 | caller/callee must match, or the behavior of the program is undefined. The |
| 511 | following calling conventions are supported by LLVM, and more may be added in |
| 512 | the future:</p> |
| 513 | |
| 514 | <dl> |
| 515 | <dt><b>"<tt>ccc</tt>" - The C calling convention</b>:</dt> |
| 516 | |
| 517 | <dd>This calling convention (the default if no other calling convention is |
| 518 | specified) matches the target C calling conventions. This calling convention |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 519 | supports varargs function calls and tolerates some mismatch in the declared |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 520 | prototype and implemented declaration of the function (as does normal C). |
| 521 | </dd> |
| 522 | |
Chris Lattner | 5710ce9 | 2006-05-19 21:15:36 +0000 | [diff] [blame] | 523 | <dt><b>"<tt>csretcc</tt>" - The C struct return calling convention</b>:</dt> |
| 524 | |
| 525 | <dd>This calling convention matches the target C calling conventions, except |
| 526 | that functions with this convention are required to take a pointer as their |
| 527 | first argument, and the return type of the function must be void. This is |
| 528 | used for C functions that return aggregates by-value. In this case, the |
| 529 | function has been transformed to take a pointer to the struct as the first |
| 530 | argument to the function. For targets where the ABI specifies specific |
| 531 | behavior for structure-return calls, the calling convention can be used to |
| 532 | distinguish between struct return functions and other functions that take a |
| 533 | pointer to a struct as the first argument. |
| 534 | </dd> |
| 535 | |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 536 | <dt><b>"<tt>fastcc</tt>" - The fast calling convention</b>:</dt> |
| 537 | |
| 538 | <dd>This calling convention attempts to make calls as fast as possible |
| 539 | (e.g. by passing things in registers). This calling convention allows the |
| 540 | 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] | 541 | without having to conform to an externally specified ABI. Implementations of |
| 542 | this convention should allow arbitrary tail call optimization to be supported. |
| 543 | This calling convention does not support varargs and requires the prototype of |
| 544 | all callees to exactly match the prototype of the function definition. |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 545 | </dd> |
| 546 | |
| 547 | <dt><b>"<tt>coldcc</tt>" - The cold calling convention</b>:</dt> |
| 548 | |
| 549 | <dd>This calling convention attempts to make code in the caller as efficient |
| 550 | as possible under the assumption that the call is not commonly executed. As |
| 551 | such, these calls often preserve all registers so that the call does not break |
| 552 | any live ranges in the caller side. This calling convention does not support |
| 553 | varargs and requires the prototype of all callees to exactly match the |
| 554 | prototype of the function definition. |
| 555 | </dd> |
| 556 | |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 557 | <dt><b>"<tt>cc <<em>n</em>></tt>" - Numbered convention</b>:</dt> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 558 | |
| 559 | <dd>Any calling convention may be specified by number, allowing |
| 560 | target-specific calling conventions to be used. Target specific calling |
| 561 | conventions start at 64. |
| 562 | </dd> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 563 | </dl> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 564 | |
| 565 | <p>More calling conventions can be added/defined on an as-needed basis, to |
| 566 | support pascal conventions or any other well-known target-independent |
| 567 | convention.</p> |
| 568 | |
| 569 | </div> |
| 570 | |
| 571 | <!-- ======================================================================= --> |
| 572 | <div class="doc_subsection"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 573 | <a name="globalvars">Global Variables</a> |
| 574 | </div> |
| 575 | |
| 576 | <div class="doc_text"> |
| 577 | |
Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 578 | <p>Global variables define regions of memory allocated at compilation time |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 579 | instead of run-time. Global variables may optionally be initialized, may have |
| 580 | an explicit section to be placed in, and may |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 581 | have an optional explicit alignment specified. A |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 582 | variable may be defined as a global "constant," which indicates that the |
Chris Lattner | 3689a34 | 2005-02-12 19:30:21 +0000 | [diff] [blame] | 583 | contents of the variable will <b>never</b> be modified (enabling better |
| 584 | optimization, allowing the global data to be placed in the read-only section of |
| 585 | an executable, etc). Note that variables that need runtime initialization |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 586 | 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] | 587 | |
| 588 | <p> |
| 589 | LLVM explicitly allows <em>declarations</em> of global variables to be marked |
| 590 | constant, even if the final definition of the global is not. This capability |
| 591 | can be used to enable slightly better optimization of the program, but requires |
| 592 | the language definition to guarantee that optimizations based on the |
| 593 | 'constantness' are valid for the translation units that do not include the |
| 594 | definition. |
| 595 | </p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 596 | |
| 597 | <p>As SSA values, global variables define pointer values that are in |
| 598 | scope (i.e. they dominate) all basic blocks in the program. Global |
| 599 | variables always define a pointer to their "content" type because they |
| 600 | describe a region of memory, and all memory objects in LLVM are |
| 601 | accessed through pointers.</p> |
| 602 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 603 | <p>LLVM allows an explicit section to be specified for globals. If the target |
| 604 | supports it, it will emit globals to the section specified.</p> |
| 605 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 606 | <p>An explicit alignment may be specified for a global. If not present, or if |
| 607 | the alignment is set to zero, the alignment of the global is set by the target |
| 608 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 609 | global is forced to have at least that much alignment. All alignments must be |
| 610 | a power of 2.</p> |
| 611 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 612 | </div> |
| 613 | |
| 614 | |
| 615 | <!-- ======================================================================= --> |
| 616 | <div class="doc_subsection"> |
| 617 | <a name="functionstructure">Functions</a> |
| 618 | </div> |
| 619 | |
| 620 | <div class="doc_text"> |
| 621 | |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 622 | <p>LLVM function definitions consist of an optional <a href="#linkage">linkage |
| 623 | type</a>, an optional <a href="#callingconv">calling convention</a>, a return |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 624 | type, a function name, a (possibly empty) argument list, an optional section, |
| 625 | an optional alignment, an opening curly brace, |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 626 | a list of basic blocks, and a closing curly brace. LLVM function declarations |
| 627 | are defined with the "<tt>declare</tt>" keyword, an optional <a |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 628 | href="#callingconv">calling convention</a>, a return type, a function name, |
| 629 | a possibly empty list of arguments, and an optional alignment.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 630 | |
| 631 | <p>A function definition contains a list of basic blocks, forming the CFG for |
| 632 | the function. Each basic block may optionally start with a label (giving the |
| 633 | basic block a symbol table entry), contains a list of instructions, and ends |
| 634 | with a <a href="#terminators">terminator</a> instruction (such as a branch or |
| 635 | function return).</p> |
| 636 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 637 | <p>The first basic block in a program is special in two ways: it is immediately |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 638 | executed on entrance to the function, and it is not allowed to have predecessor |
| 639 | basic blocks (i.e. there can not be any branches to the entry block of a |
| 640 | function). Because the block can have no predecessors, it also cannot have any |
| 641 | <a href="#i_phi">PHI nodes</a>.</p> |
| 642 | |
| 643 | <p>LLVM functions are identified by their name and type signature. Hence, two |
| 644 | functions with the same name but different parameter lists or return values are |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 645 | considered different functions, and LLVM will resolve references to each |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 646 | appropriately.</p> |
| 647 | |
Chris Lattner | 88f6c46 | 2005-11-12 00:45:07 +0000 | [diff] [blame] | 648 | <p>LLVM allows an explicit section to be specified for functions. If the target |
| 649 | supports it, it will emit functions to the section specified.</p> |
| 650 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 651 | <p>An explicit alignment may be specified for a function. If not present, or if |
| 652 | the alignment is set to zero, the alignment of the function is set by the target |
| 653 | to whatever it feels convenient. If an explicit alignment is specified, the |
| 654 | function is forced to have at least that much alignment. All alignments must be |
| 655 | a power of 2.</p> |
| 656 | |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 657 | </div> |
| 658 | |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 659 | <!-- ======================================================================= --> |
| 660 | <div class="doc_subsection"> |
Chris Lattner | 1eeeb0c | 2006-04-08 04:40:53 +0000 | [diff] [blame] | 661 | <a name="moduleasm">Module-Level Inline Assembly</a> |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 662 | </div> |
| 663 | |
| 664 | <div class="doc_text"> |
| 665 | <p> |
| 666 | Modules may contain "module-level inline asm" blocks, which corresponds to the |
| 667 | GCC "file scope inline asm" blocks. These blocks are internally concatenated by |
| 668 | LLVM and treated as a single unit, but may be separated in the .ll file if |
| 669 | desired. The syntax is very simple: |
| 670 | </p> |
| 671 | |
| 672 | <div class="doc_code"><pre> |
Chris Lattner | 52599e1 | 2006-01-24 00:37:20 +0000 | [diff] [blame] | 673 | module asm "inline asm code goes here" |
| 674 | module asm "more can go here" |
Chris Lattner | 4e9aba7 | 2006-01-23 23:23:47 +0000 | [diff] [blame] | 675 | </pre></div> |
| 676 | |
| 677 | <p>The strings can contain any character by escaping non-printable characters. |
| 678 | The escape sequence used is simply "\xx" where "xx" is the two digit hex code |
| 679 | for the number. |
| 680 | </p> |
| 681 | |
| 682 | <p> |
| 683 | The inline asm code is simply printed to the machine code .s file when |
| 684 | assembly code is generated. |
| 685 | </p> |
| 686 | </div> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 687 | |
| 688 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 689 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 690 | <div class="doc_section"> <a name="typesystem">Type System</a> </div> |
| 691 | <!-- *********************************************************************** --> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 692 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 693 | <div class="doc_text"> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 694 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 695 | <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] | 696 | intermediate representation. Being typed enables a number of |
| 697 | optimizations to be performed on the IR directly, without having to do |
| 698 | extra analyses on the side before the transformation. A strong type |
| 699 | system makes it easier to read the generated code and enables novel |
| 700 | analyses and transformations that are not feasible to perform on normal |
| 701 | three address code representations.</p> |
Chris Lattner | fa73021 | 2004-12-09 16:11:40 +0000 | [diff] [blame] | 702 | |
| 703 | </div> |
| 704 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 705 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 706 | <div class="doc_subsection"> <a name="t_primitive">Primitive Types</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 707 | <div class="doc_text"> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 708 | <p>The primitive types are the fundamental building blocks of the LLVM |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 709 | system. The current set of primitive types is as follows:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 710 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 711 | <table class="layout"> |
| 712 | <tr class="layout"> |
| 713 | <td class="left"> |
| 714 | <table> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 715 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 716 | <tr><th>Type</th><th>Description</th></tr> |
| 717 | <tr><td><tt>void</tt></td><td>No value</td></tr> |
Misha Brukman | cfa87bc | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 718 | <tr><td><tt>ubyte</tt></td><td>Unsigned 8-bit value</td></tr> |
| 719 | <tr><td><tt>ushort</tt></td><td>Unsigned 16-bit value</td></tr> |
| 720 | <tr><td><tt>uint</tt></td><td>Unsigned 32-bit value</td></tr> |
| 721 | <tr><td><tt>ulong</tt></td><td>Unsigned 64-bit value</td></tr> |
| 722 | <tr><td><tt>float</tt></td><td>32-bit floating point value</td></tr> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 723 | <tr><td><tt>label</tt></td><td>Branch destination</td></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 724 | </tbody> |
| 725 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 726 | </td> |
| 727 | <td class="right"> |
| 728 | <table> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 729 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 730 | <tr><th>Type</th><th>Description</th></tr> |
| 731 | <tr><td><tt>bool</tt></td><td>True or False value</td></tr> |
Misha Brukman | cfa87bc | 2005-04-22 18:02:52 +0000 | [diff] [blame] | 732 | <tr><td><tt>sbyte</tt></td><td>Signed 8-bit value</td></tr> |
| 733 | <tr><td><tt>short</tt></td><td>Signed 16-bit value</td></tr> |
| 734 | <tr><td><tt>int</tt></td><td>Signed 32-bit value</td></tr> |
| 735 | <tr><td><tt>long</tt></td><td>Signed 64-bit value</td></tr> |
| 736 | <tr><td><tt>double</tt></td><td>64-bit floating point value</td></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 737 | </tbody> |
| 738 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 739 | </td> |
| 740 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 741 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 742 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 743 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 744 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 745 | <div class="doc_subsubsection"> <a name="t_classifications">Type |
| 746 | Classifications</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 747 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 748 | <p>These different primitive types fall into a few useful |
| 749 | classifications:</p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 750 | |
| 751 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 752 | <tbody> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 753 | <tr><th>Classification</th><th>Types</th></tr> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 754 | <tr> |
| 755 | <td><a name="t_signed">signed</a></td> |
| 756 | <td><tt>sbyte, short, int, long, float, double</tt></td> |
| 757 | </tr> |
| 758 | <tr> |
| 759 | <td><a name="t_unsigned">unsigned</a></td> |
| 760 | <td><tt>ubyte, ushort, uint, ulong</tt></td> |
| 761 | </tr> |
| 762 | <tr> |
| 763 | <td><a name="t_integer">integer</a></td> |
| 764 | <td><tt>ubyte, sbyte, ushort, short, uint, int, ulong, long</tt></td> |
| 765 | </tr> |
| 766 | <tr> |
| 767 | <td><a name="t_integral">integral</a></td> |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 768 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long</tt> |
| 769 | </td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 770 | </tr> |
| 771 | <tr> |
| 772 | <td><a name="t_floating">floating point</a></td> |
| 773 | <td><tt>float, double</tt></td> |
| 774 | </tr> |
| 775 | <tr> |
| 776 | <td><a name="t_firstclass">first class</a></td> |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 777 | <td><tt>bool, ubyte, sbyte, ushort, short, uint, int, ulong, long,<br> |
| 778 | float, double, <a href="#t_pointer">pointer</a>, |
| 779 | <a href="#t_packed">packed</a></tt></td> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 780 | </tr> |
| 781 | </tbody> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 782 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 783 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 784 | <p>The <a href="#t_firstclass">first class</a> types are perhaps the |
| 785 | most important. Values of these types are the only ones which can be |
| 786 | produced by instructions, passed as arguments, or used as operands to |
| 787 | instructions. This means that all structures and arrays must be |
| 788 | manipulated either by pointer or by component.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 789 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 790 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 791 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 792 | <div class="doc_subsection"> <a name="t_derived">Derived Types</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 793 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 794 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 795 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 796 | <p>The real power in LLVM comes from the derived types in the system. |
| 797 | This is what allows a programmer to represent arrays, functions, |
| 798 | pointers, and other useful types. Note that these derived types may be |
| 799 | 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] | 800 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 801 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 802 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 803 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 804 | <div class="doc_subsubsection"> <a name="t_array">Array Type</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 805 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 806 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 807 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 808 | <h5>Overview:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 809 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 810 | <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] | 811 | sequentially in memory. The array type requires a size (number of |
| 812 | elements) and an underlying data type.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 813 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 814 | <h5>Syntax:</h5> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 815 | |
| 816 | <pre> |
| 817 | [<# elements> x <elementtype>] |
| 818 | </pre> |
| 819 | |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 820 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 821 | be any type with a size.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 822 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 823 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 824 | <table class="layout"> |
| 825 | <tr class="layout"> |
| 826 | <td class="left"> |
| 827 | <tt>[40 x int ]</tt><br/> |
| 828 | <tt>[41 x int ]</tt><br/> |
| 829 | <tt>[40 x uint]</tt><br/> |
| 830 | </td> |
| 831 | <td class="left"> |
| 832 | Array of 40 integer values.<br/> |
| 833 | Array of 41 integer values.<br/> |
| 834 | Array of 40 unsigned integer values.<br/> |
| 835 | </td> |
| 836 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 837 | </table> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 838 | <p>Here are some examples of multidimensional arrays:</p> |
| 839 | <table class="layout"> |
| 840 | <tr class="layout"> |
| 841 | <td class="left"> |
| 842 | <tt>[3 x [4 x int]]</tt><br/> |
| 843 | <tt>[12 x [10 x float]]</tt><br/> |
| 844 | <tt>[2 x [3 x [4 x uint]]]</tt><br/> |
| 845 | </td> |
| 846 | <td class="left"> |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 847 | 3x4 array of integer values.<br/> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 848 | 12x10 array of single precision floating point values.<br/> |
| 849 | 2x3x4 array of unsigned integer values.<br/> |
| 850 | </td> |
| 851 | </tr> |
| 852 | </table> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 853 | |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 854 | <p>Note that 'variable sized arrays' can be implemented in LLVM with a zero |
| 855 | 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] | 856 | LLVM (e.g. it is illegal to access the 5th element of a 3 element array). |
| 857 | As a special case, however, zero length arrays are recognized to be variable |
| 858 | length. This allows implementation of 'pascal style arrays' with the LLVM |
| 859 | type "{ int, [0 x float]}", for example.</p> |
| 860 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 861 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 862 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 863 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 864 | <div class="doc_subsubsection"> <a name="t_function">Function Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 865 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 866 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 867 | <p>The function type can be thought of as a function signature. It |
| 868 | consists of a return type and a list of formal parameter types. |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 869 | Function types are usually used to build virtual function tables |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 870 | (which are structures of pointers to functions), for indirect function |
| 871 | calls, and when defining a function.</p> |
John Criswell | 009900b | 2003-11-25 21:45:46 +0000 | [diff] [blame] | 872 | <p> |
| 873 | The return type of a function type cannot be an aggregate type. |
| 874 | </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 875 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 876 | <pre> <returntype> (<parameter list>)<br></pre> |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 877 | <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] | 878 | specifiers. Optionally, the parameter list may include a type <tt>...</tt>, |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 879 | which indicates that the function takes a variable number of arguments. |
| 880 | Variable argument functions can access their arguments with the <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 881 | href="#int_varargs">variable argument handling intrinsic</a> functions.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 882 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 883 | <table class="layout"> |
| 884 | <tr class="layout"> |
| 885 | <td class="left"> |
| 886 | <tt>int (int)</tt> <br/> |
| 887 | <tt>float (int, int *) *</tt><br/> |
| 888 | <tt>int (sbyte *, ...)</tt><br/> |
| 889 | </td> |
| 890 | <td class="left"> |
| 891 | function taking an <tt>int</tt>, returning an <tt>int</tt><br/> |
| 892 | <a href="#t_pointer">Pointer</a> to a function that takes an |
Misha Brukman | c24b758 | 2004-08-12 20:16:08 +0000 | [diff] [blame] | 893 | <tt>int</tt> and a <a href="#t_pointer">pointer</a> to <tt>int</tt>, |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 894 | returning <tt>float</tt>.<br/> |
| 895 | A vararg function that takes at least one <a href="#t_pointer">pointer</a> |
| 896 | to <tt>sbyte</tt> (signed char in C), which returns an integer. This is |
| 897 | the signature for <tt>printf</tt> in LLVM.<br/> |
| 898 | </td> |
| 899 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 900 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 901 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 902 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 903 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 904 | <div class="doc_subsubsection"> <a name="t_struct">Structure Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 905 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 906 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 907 | <p>The structure type is used to represent a collection of data members |
| 908 | together in memory. The packing of the field types is defined to match |
| 909 | the ABI of the underlying processor. The elements of a structure may |
| 910 | be any type that has a size.</p> |
| 911 | <p>Structures are accessed using '<tt><a href="#i_load">load</a></tt> |
| 912 | and '<tt><a href="#i_store">store</a></tt>' by getting a pointer to a |
| 913 | field with the '<tt><a href="#i_getelementptr">getelementptr</a></tt>' |
| 914 | instruction.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 915 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 916 | <pre> { <type list> }<br></pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 917 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 918 | <table class="layout"> |
| 919 | <tr class="layout"> |
| 920 | <td class="left"> |
| 921 | <tt>{ int, int, int }</tt><br/> |
| 922 | <tt>{ float, int (int) * }</tt><br/> |
| 923 | </td> |
| 924 | <td class="left"> |
| 925 | a triple of three <tt>int</tt> values<br/> |
| 926 | A pair, where the first element is a <tt>float</tt> and the second element |
| 927 | is a <a href="#t_pointer">pointer</a> to a <a href="#t_function">function</a> |
| 928 | that takes an <tt>int</tt>, returning an <tt>int</tt>.<br/> |
| 929 | </td> |
| 930 | </tr> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 931 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 932 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 933 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 934 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 935 | <div class="doc_subsubsection"> <a name="t_pointer">Pointer Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 936 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 937 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 938 | <p>As in many languages, the pointer type represents a pointer or |
| 939 | reference to another object, which must live in memory.</p> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 940 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 941 | <pre> <type> *<br></pre> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 942 | <h5>Examples:</h5> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 943 | <table class="layout"> |
| 944 | <tr class="layout"> |
| 945 | <td class="left"> |
| 946 | <tt>[4x int]*</tt><br/> |
| 947 | <tt>int (int *) *</tt><br/> |
| 948 | </td> |
| 949 | <td class="left"> |
| 950 | A <a href="#t_pointer">pointer</a> to <a href="#t_array">array</a> of |
| 951 | four <tt>int</tt> values<br/> |
| 952 | A <a href="#t_pointer">pointer</a> to a <a |
Chris Lattner | a977c48 | 2005-02-19 02:22:14 +0000 | [diff] [blame] | 953 | href="#t_function">function</a> that takes an <tt>int*</tt>, returning an |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 954 | <tt>int</tt>.<br/> |
| 955 | </td> |
| 956 | </tr> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 957 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 958 | </div> |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 959 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 960 | <!-- _______________________________________________________________________ --> |
| 961 | <div class="doc_subsubsection"> <a name="t_packed">Packed Type</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 962 | <div class="doc_text"> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 963 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 964 | <h5>Overview:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 965 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 966 | <p>A packed type is a simple derived type that represents a vector |
| 967 | of elements. Packed types are used when multiple primitive data |
| 968 | are operated in parallel using a single instruction (SIMD). |
| 969 | A packed type requires a size (number of |
Chris Lattner | b8d172f | 2005-11-10 01:44:22 +0000 | [diff] [blame] | 970 | elements) and an underlying primitive data type. Vectors must have a power |
| 971 | of two length (1, 2, 4, 8, 16 ...). Packed types are |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 972 | considered <a href="#t_firstclass">first class</a>.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 973 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 974 | <h5>Syntax:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 975 | |
| 976 | <pre> |
| 977 | < <# elements> x <elementtype> > |
| 978 | </pre> |
| 979 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 980 | <p>The number of elements is a constant integer value; elementtype may |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 981 | be any integral or floating point type.</p> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 982 | |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 983 | <h5>Examples:</h5> |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 984 | |
Reid Spencer | d3f876c | 2004-11-01 08:19:36 +0000 | [diff] [blame] | 985 | <table class="layout"> |
| 986 | <tr class="layout"> |
| 987 | <td class="left"> |
| 988 | <tt><4 x int></tt><br/> |
| 989 | <tt><8 x float></tt><br/> |
| 990 | <tt><2 x uint></tt><br/> |
| 991 | </td> |
| 992 | <td class="left"> |
| 993 | Packed vector of 4 integer values.<br/> |
| 994 | Packed vector of 8 floating-point values.<br/> |
| 995 | Packed vector of 2 unsigned integer values.<br/> |
| 996 | </td> |
| 997 | </tr> |
| 998 | </table> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 999 | </div> |
| 1000 | |
Chris Lattner | 69c11bb | 2005-04-25 17:34:15 +0000 | [diff] [blame] | 1001 | <!-- _______________________________________________________________________ --> |
| 1002 | <div class="doc_subsubsection"> <a name="t_opaque">Opaque Type</a> </div> |
| 1003 | <div class="doc_text"> |
| 1004 | |
| 1005 | <h5>Overview:</h5> |
| 1006 | |
| 1007 | <p>Opaque types are used to represent unknown types in the system. This |
| 1008 | corresponds (for example) to the C notion of a foward declared structure type. |
| 1009 | In LLVM, opaque types can eventually be resolved to any type (not just a |
| 1010 | structure type).</p> |
| 1011 | |
| 1012 | <h5>Syntax:</h5> |
| 1013 | |
| 1014 | <pre> |
| 1015 | opaque |
| 1016 | </pre> |
| 1017 | |
| 1018 | <h5>Examples:</h5> |
| 1019 | |
| 1020 | <table class="layout"> |
| 1021 | <tr class="layout"> |
| 1022 | <td class="left"> |
| 1023 | <tt>opaque</tt> |
| 1024 | </td> |
| 1025 | <td class="left"> |
| 1026 | An opaque type.<br/> |
| 1027 | </td> |
| 1028 | </tr> |
| 1029 | </table> |
| 1030 | </div> |
| 1031 | |
| 1032 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1033 | <!-- *********************************************************************** --> |
| 1034 | <div class="doc_section"> <a name="constants">Constants</a> </div> |
| 1035 | <!-- *********************************************************************** --> |
| 1036 | |
| 1037 | <div class="doc_text"> |
| 1038 | |
| 1039 | <p>LLVM has several different basic types of constants. This section describes |
| 1040 | them all and their syntax.</p> |
| 1041 | |
| 1042 | </div> |
| 1043 | |
| 1044 | <!-- ======================================================================= --> |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1045 | <div class="doc_subsection"><a name="simpleconstants">Simple Constants</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1046 | |
| 1047 | <div class="doc_text"> |
| 1048 | |
| 1049 | <dl> |
| 1050 | <dt><b>Boolean constants</b></dt> |
| 1051 | |
| 1052 | <dd>The two strings '<tt>true</tt>' and '<tt>false</tt>' are both valid |
| 1053 | constants of the <tt><a href="#t_primitive">bool</a></tt> type. |
| 1054 | </dd> |
| 1055 | |
| 1056 | <dt><b>Integer constants</b></dt> |
| 1057 | |
Reid Spencer | cc16dc3 | 2004-12-09 18:02:53 +0000 | [diff] [blame] | 1058 | <dd>Standard integers (such as '4') are constants of the <a |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1059 | href="#t_integer">integer</a> type. Negative numbers may be used with signed |
| 1060 | integer types. |
| 1061 | </dd> |
| 1062 | |
| 1063 | <dt><b>Floating point constants</b></dt> |
| 1064 | |
| 1065 | <dd>Floating point constants use standard decimal notation (e.g. 123.421), |
| 1066 | exponential notation (e.g. 1.23421e+2), or a more precise hexadecimal |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1067 | notation (see below). Floating point constants must have a <a |
| 1068 | href="#t_floating">floating point</a> type. </dd> |
| 1069 | |
| 1070 | <dt><b>Null pointer constants</b></dt> |
| 1071 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1072 | <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] | 1073 | and must be of <a href="#t_pointer">pointer type</a>.</dd> |
| 1074 | |
| 1075 | </dl> |
| 1076 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1077 | <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] | 1078 | of floating point constants. For example, the form '<tt>double |
| 1079 | 0x432ff973cafa8000</tt>' is equivalent to (but harder to read than) '<tt>double |
| 1080 | 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] | 1081 | (and the only time that they are generated by the disassembler) is when a |
| 1082 | floating point constant must be emitted but it cannot be represented as a |
| 1083 | decimal floating point number. For example, NaN's, infinities, and other |
| 1084 | special values are represented in their IEEE hexadecimal format so that |
| 1085 | 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] | 1086 | |
| 1087 | </div> |
| 1088 | |
| 1089 | <!-- ======================================================================= --> |
| 1090 | <div class="doc_subsection"><a name="aggregateconstants">Aggregate Constants</a> |
| 1091 | </div> |
| 1092 | |
| 1093 | <div class="doc_text"> |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1094 | <p>Aggregate constants arise from aggregation of simple constants |
| 1095 | and smaller aggregate constants.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1096 | |
| 1097 | <dl> |
| 1098 | <dt><b>Structure constants</b></dt> |
| 1099 | |
| 1100 | <dd>Structure constants are represented with notation similar to structure |
| 1101 | type definitions (a comma separated list of elements, surrounded by braces |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 1102 | (<tt>{}</tt>)). For example: "<tt>{ int 4, float 17.0, int* %G }</tt>", |
| 1103 | where "<tt>%G</tt>" is declared as "<tt>%G = external global int</tt>". Structure constants |
| 1104 | 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] | 1105 | types of elements must match those specified by the type. |
| 1106 | </dd> |
| 1107 | |
| 1108 | <dt><b>Array constants</b></dt> |
| 1109 | |
| 1110 | <dd>Array constants are represented with notation similar to array type |
| 1111 | definitions (a comma separated list of elements, surrounded by square brackets |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1112 | (<tt>[]</tt>)). For example: "<tt>[ int 42, int 11, int 74 ]</tt>". Array |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1113 | constants must have <a href="#t_array">array type</a>, and the number and |
| 1114 | types of elements must match those specified by the type. |
| 1115 | </dd> |
| 1116 | |
| 1117 | <dt><b>Packed constants</b></dt> |
| 1118 | |
| 1119 | <dd>Packed constants are represented with notation similar to packed type |
| 1120 | definitions (a comma separated list of elements, surrounded by |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1121 | less-than/greater-than's (<tt><></tt>)). For example: "<tt>< int 42, |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1122 | int 11, int 74, int 100 ></tt>". Packed constants must have <a |
| 1123 | href="#t_packed">packed type</a>, and the number and types of elements must |
| 1124 | match those specified by the type. |
| 1125 | </dd> |
| 1126 | |
| 1127 | <dt><b>Zero initialization</b></dt> |
| 1128 | |
| 1129 | <dd>The string '<tt>zeroinitializer</tt>' can be used to zero initialize a |
| 1130 | value to zero of <em>any</em> type, including scalar and aggregate types. |
| 1131 | 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] | 1132 | large arrays) and is always exactly equivalent to using explicit zero |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1133 | initializers. |
| 1134 | </dd> |
| 1135 | </dl> |
| 1136 | |
| 1137 | </div> |
| 1138 | |
| 1139 | <!-- ======================================================================= --> |
| 1140 | <div class="doc_subsection"> |
| 1141 | <a name="globalconstants">Global Variable and Function Addresses</a> |
| 1142 | </div> |
| 1143 | |
| 1144 | <div class="doc_text"> |
| 1145 | |
| 1146 | <p>The addresses of <a href="#globalvars">global variables</a> and <a |
| 1147 | href="#functionstructure">functions</a> are always implicitly valid (link-time) |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1148 | constants. These constants are explicitly referenced when the <a |
| 1149 | 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] | 1150 | href="#t_pointer">pointer</a> type. For example, the following is a legal LLVM |
| 1151 | file:</p> |
| 1152 | |
| 1153 | <pre> |
| 1154 | %X = global int 17 |
| 1155 | %Y = global int 42 |
| 1156 | %Z = global [2 x int*] [ int* %X, int* %Y ] |
| 1157 | </pre> |
| 1158 | |
| 1159 | </div> |
| 1160 | |
| 1161 | <!-- ======================================================================= --> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1162 | <div class="doc_subsection"><a name="undefvalues">Undefined Values</a></div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1163 | <div class="doc_text"> |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1164 | <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] | 1165 | 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] | 1166 | a constant is permitted.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1167 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1168 | <p>Undefined values indicate to the compiler that the program is well defined |
| 1169 | no matter what value is used, giving the compiler more freedom to optimize. |
| 1170 | </p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1171 | </div> |
| 1172 | |
| 1173 | <!-- ======================================================================= --> |
| 1174 | <div class="doc_subsection"><a name="constantexprs">Constant Expressions</a> |
| 1175 | </div> |
| 1176 | |
| 1177 | <div class="doc_text"> |
| 1178 | |
| 1179 | <p>Constant expressions are used to allow expressions involving other constants |
| 1180 | to be used as constants. Constant expressions may be of any <a |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1181 | 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] | 1182 | that does not have side effects (e.g. load and call are not supported). The |
| 1183 | following is the syntax for constant expressions:</p> |
| 1184 | |
| 1185 | <dl> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1186 | <dt><b><tt>trunc ( CST to TYPE )</tt></b></dt> |
| 1187 | <dd>Truncate a constant to another type. The bit size of CST must be larger |
| 1188 | than the bit size of TYPE. Both types must be integral.</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1189 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1190 | <dt><b><tt>zext ( CST to TYPE )</tt></b></dt> |
| 1191 | <dd>Zero extend a constant to another type. The bit size of CST must be |
| 1192 | smaller or equal to the bit size of TYPE. Both types must be integral.</dd> |
| 1193 | |
| 1194 | <dt><b><tt>sext ( CST to TYPE )</tt></b></dt> |
| 1195 | <dd>Sign extend a constant to another type. The bit size of CST must be |
| 1196 | smaller or equal to the bit size of TYPE. Both types must be integral.</dd> |
| 1197 | |
| 1198 | <dt><b><tt>fptrunc ( CST to TYPE )</tt></b></dt> |
| 1199 | <dd>Truncate a floating point constant to another floating point type. The |
| 1200 | size of CST must be larger than the size of TYPE. Both types must be |
| 1201 | floating point.</dd> |
| 1202 | |
| 1203 | <dt><b><tt>fpext ( CST to TYPE )</tt></b></dt> |
| 1204 | <dd>Floating point extend a constant to another type. The size of CST must be |
| 1205 | smaller or equal to the size of TYPE. Both types must be floating point.</dd> |
| 1206 | |
| 1207 | <dt><b><tt>fp2uint ( CST to TYPE )</tt></b></dt> |
| 1208 | <dd>Convert a floating point constant to the corresponding unsigned integer |
| 1209 | constant. TYPE must be an integer type. CST must be floating point. If the |
| 1210 | value won't fit in the integer type, the results are undefined.</dd> |
| 1211 | |
| 1212 | <dt><b><tt>fp2sint ( CST to TYPE )</tt></b></dt> |
| 1213 | <dd>Convert a floating point constant to the corresponding signed integer |
| 1214 | constant. TYPE must be an integer type. CST must be floating point. If the |
| 1215 | value won't fit in the integer type, the results are undefined.</dd> |
| 1216 | |
| 1217 | <dt><b><tt>uint2fp ( CST to TYPE )</tt></b></dt> |
| 1218 | <dd>Convert an unsigned integer constant to the corresponding floating point |
| 1219 | constant. TYPE must be floating point. CST must be of integer type. If the |
| 1220 | value won't fit in the floating point type, the results are undefined.</dd> |
| 1221 | |
| 1222 | <dt><b><tt>sint2fp ( CST to TYPE )</tt></b></dt> |
| 1223 | <dd>Convert a signed integer constant to the corresponding floating point |
| 1224 | constant. TYPE must be floating point. CST must be of integer type. If the |
| 1225 | value won't fit in the floating point type, the results are undefined.</dd> |
| 1226 | |
| 1227 | <dt><b><tt>bitconvert ( CST to TYPE )</tt></b></dt> |
| 1228 | <dd>Convert a constant, CST, to another TYPE. The size of CST and TYPE must be |
| 1229 | identical (same number of bits). The conversion is done as if the CST value |
| 1230 | was stored to memory and read back as TYPE. In other words, no bits change |
| 1231 | with this operator, just the type. This can be used for conversion of pointer |
| 1232 | and packed types to any other type, as long as they have the same bit width. |
| 1233 | </dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1234 | |
| 1235 | <dt><b><tt>getelementptr ( CSTPTR, IDX0, IDX1, ... )</tt></b></dt> |
| 1236 | |
| 1237 | <dd>Perform the <a href="#i_getelementptr">getelementptr operation</a> on |
| 1238 | constants. As with the <a href="#i_getelementptr">getelementptr</a> |
| 1239 | instruction, the index list may have zero or more indexes, which are required |
| 1240 | to make sense for the type of "CSTPTR".</dd> |
| 1241 | |
Robert Bocchino | 9fbe145 | 2006-01-10 19:31:34 +0000 | [diff] [blame] | 1242 | <dt><b><tt>select ( COND, VAL1, VAL2 )</tt></b></dt> |
| 1243 | |
| 1244 | <dd>Perform the <a href="#i_select">select operation</a> on |
| 1245 | constants. |
| 1246 | |
| 1247 | <dt><b><tt>extractelement ( VAL, IDX )</tt></b></dt> |
| 1248 | |
| 1249 | <dd>Perform the <a href="#i_extractelement">extractelement |
| 1250 | operation</a> on constants. |
| 1251 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 1252 | <dt><b><tt>insertelement ( VAL, ELT, IDX )</tt></b></dt> |
| 1253 | |
| 1254 | <dd>Perform the <a href="#i_insertelement">insertelement |
| 1255 | operation</a> on constants. |
| 1256 | |
Chris Lattner | c198954 | 2006-04-08 00:13:41 +0000 | [diff] [blame] | 1257 | |
| 1258 | <dt><b><tt>shufflevector ( VEC1, VEC2, IDXMASK )</tt></b></dt> |
| 1259 | |
| 1260 | <dd>Perform the <a href="#i_shufflevector">shufflevector |
| 1261 | operation</a> on constants. |
| 1262 | |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1263 | <dt><b><tt>OPCODE ( LHS, RHS )</tt></b></dt> |
| 1264 | |
Reid Spencer | 2dc45b8 | 2004-12-09 18:13:12 +0000 | [diff] [blame] | 1265 | <dd>Perform the specified operation of the LHS and RHS constants. OPCODE may |
| 1266 | 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] | 1267 | binary</a> operations. The constraints on operands are the same as those for |
| 1268 | the corresponding instruction (e.g. no bitwise operations on floating point |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1269 | values are allowed).</dd> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1270 | </dl> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1271 | </div> |
Chris Lattner | 9ee5d22 | 2004-03-08 16:49:10 +0000 | [diff] [blame] | 1272 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1273 | <!-- *********************************************************************** --> |
Chris Lattner | e87d653 | 2006-01-25 23:47:57 +0000 | [diff] [blame] | 1274 | <div class="doc_section"> <a name="othervalues">Other Values</a> </div> |
| 1275 | <!-- *********************************************************************** --> |
| 1276 | |
| 1277 | <!-- ======================================================================= --> |
| 1278 | <div class="doc_subsection"> |
| 1279 | <a name="inlineasm">Inline Assembler Expressions</a> |
| 1280 | </div> |
| 1281 | |
| 1282 | <div class="doc_text"> |
| 1283 | |
| 1284 | <p> |
| 1285 | LLVM supports inline assembler expressions (as opposed to <a href="#moduleasm"> |
| 1286 | Module-Level Inline Assembly</a>) through the use of a special value. This |
| 1287 | value represents the inline assembler as a string (containing the instructions |
| 1288 | to emit), a list of operand constraints (stored as a string), and a flag that |
| 1289 | indicates whether or not the inline asm expression has side effects. An example |
| 1290 | inline assembler expression is: |
| 1291 | </p> |
| 1292 | |
| 1293 | <pre> |
| 1294 | int(int) asm "bswap $0", "=r,r" |
| 1295 | </pre> |
| 1296 | |
| 1297 | <p> |
| 1298 | Inline assembler expressions may <b>only</b> be used as the callee operand of |
| 1299 | a <a href="#i_call"><tt>call</tt> instruction</a>. Thus, typically we have: |
| 1300 | </p> |
| 1301 | |
| 1302 | <pre> |
| 1303 | %X = call int asm "<a href="#i_bswap">bswap</a> $0", "=r,r"(int %Y) |
| 1304 | </pre> |
| 1305 | |
| 1306 | <p> |
| 1307 | Inline asms with side effects not visible in the constraint list must be marked |
| 1308 | as having side effects. This is done through the use of the |
| 1309 | '<tt>sideeffect</tt>' keyword, like so: |
| 1310 | </p> |
| 1311 | |
| 1312 | <pre> |
| 1313 | call void asm sideeffect "eieio", ""() |
| 1314 | </pre> |
| 1315 | |
| 1316 | <p>TODO: The format of the asm and constraints string still need to be |
| 1317 | documented here. Constraints on what can be done (e.g. duplication, moving, etc |
| 1318 | need to be documented). |
| 1319 | </p> |
| 1320 | |
| 1321 | </div> |
| 1322 | |
| 1323 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1324 | <div class="doc_section"> <a name="instref">Instruction Reference</a> </div> |
| 1325 | <!-- *********************************************************************** --> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1326 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1327 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1328 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1329 | <p>The LLVM instruction set consists of several different |
| 1330 | classifications of instructions: <a href="#terminators">terminator |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1331 | instructions</a>, <a href="#binaryops">binary instructions</a>, |
| 1332 | <a href="#bitwiseops">bitwise binary instructions</a>, <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1333 | href="#memoryops">memory instructions</a>, and <a href="#otherops">other |
| 1334 | instructions</a>.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1335 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1336 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1337 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1338 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1339 | <div class="doc_subsection"> <a name="terminators">Terminator |
| 1340 | Instructions</a> </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1341 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1342 | <div class="doc_text"> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1343 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1344 | <p>As mentioned <a href="#functionstructure">previously</a>, every |
| 1345 | basic block in a program ends with a "Terminator" instruction, which |
| 1346 | indicates which block should be executed after the current block is |
| 1347 | finished. These terminator instructions typically yield a '<tt>void</tt>' |
| 1348 | value: they produce control flow, not values (the one exception being |
| 1349 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction).</p> |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1350 | <p>There are six different terminator instructions: the '<a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1351 | href="#i_ret"><tt>ret</tt></a>' instruction, the '<a href="#i_br"><tt>br</tt></a>' |
| 1352 | instruction, the '<a href="#i_switch"><tt>switch</tt></a>' instruction, |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1353 | the '<a href="#i_invoke"><tt>invoke</tt></a>' instruction, the '<a |
| 1354 | href="#i_unwind"><tt>unwind</tt></a>' instruction, and the '<a |
| 1355 | href="#i_unreachable"><tt>unreachable</tt></a>' instruction.</p> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1356 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1357 | </div> |
Chris Lattner | c3f5976 | 2004-12-09 17:30:23 +0000 | [diff] [blame] | 1358 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1359 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1360 | <div class="doc_subsubsection"> <a name="i_ret">'<tt>ret</tt>' |
| 1361 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1362 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1363 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1364 | <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] | 1365 | ret void <i>; Return from void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1366 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1367 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1368 | <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] | 1369 | value) from a function back to the caller.</p> |
John Criswell | 4457dc9 | 2004-04-09 16:48:45 +0000 | [diff] [blame] | 1370 | <p>There are two forms of the '<tt>ret</tt>' instruction: one that |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1371 | returns a value and then causes control flow, and one that just causes |
| 1372 | control flow to occur.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1373 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1374 | <p>The '<tt>ret</tt>' instruction may return any '<a |
| 1375 | href="#t_firstclass">first class</a>' type. Notice that a function is |
| 1376 | not <a href="#wellformed">well formed</a> if there exists a '<tt>ret</tt>' |
| 1377 | instruction inside of the function that returns a value that does not |
| 1378 | match the return type of the function.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1379 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1380 | <p>When the '<tt>ret</tt>' instruction is executed, control flow |
| 1381 | 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] | 1382 | href="#i_call"><tt>call</tt></a>" instruction, execution continues at |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1383 | the instruction after the call. If the caller was an "<a |
| 1384 | href="#i_invoke"><tt>invoke</tt></a>" instruction, execution continues |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1385 | at the beginning of the "normal" destination block. If the instruction |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1386 | returns a value, that value shall set the call or invoke instruction's |
| 1387 | return value.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1388 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1389 | <pre> ret int 5 <i>; Return an integer value of 5</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 1390 | ret void <i>; Return from a void function</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1391 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1392 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1393 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1394 | <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] | 1395 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1396 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1397 | <pre> br bool <cond>, label <iftrue>, label <iffalse><br> br label <dest> <i>; Unconditional branch</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1398 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1399 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1400 | <p>The '<tt>br</tt>' instruction is used to cause control flow to |
| 1401 | transfer to a different basic block in the current function. There are |
| 1402 | two forms of this instruction, corresponding to a conditional branch |
| 1403 | and an unconditional branch.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1404 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1405 | <p>The conditional branch form of the '<tt>br</tt>' instruction takes a |
| 1406 | single '<tt>bool</tt>' value and two '<tt>label</tt>' values. The |
| 1407 | unconditional form of the '<tt>br</tt>' instruction takes a single '<tt>label</tt>' |
| 1408 | value as a target.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1409 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1410 | <p>Upon execution of a conditional '<tt>br</tt>' instruction, the '<tt>bool</tt>' |
| 1411 | argument is evaluated. If the value is <tt>true</tt>, control flows |
| 1412 | to the '<tt>iftrue</tt>' <tt>label</tt> argument. If "cond" is <tt>false</tt>, |
| 1413 | control flows to the '<tt>iffalse</tt>' <tt>label</tt> argument.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1414 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1415 | <pre>Test:<br> %cond = <a href="#i_setcc">seteq</a> int %a, %b<br> br bool %cond, label %IfEqual, label %IfUnequal<br>IfEqual:<br> <a |
| 1416 | href="#i_ret">ret</a> int 1<br>IfUnequal:<br> <a href="#i_ret">ret</a> int 0<br></pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1417 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1418 | <!-- _______________________________________________________________________ --> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1419 | <div class="doc_subsubsection"> |
| 1420 | <a name="i_switch">'<tt>switch</tt>' Instruction</a> |
| 1421 | </div> |
| 1422 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1423 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1424 | <h5>Syntax:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1425 | |
| 1426 | <pre> |
| 1427 | switch <intty> <value>, label <defaultdest> [ <intty> <val>, label <dest> ... ] |
| 1428 | </pre> |
| 1429 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1430 | <h5>Overview:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1431 | |
| 1432 | <p>The '<tt>switch</tt>' instruction is used to transfer control flow to one of |
| 1433 | several different places. It is a generalization of the '<tt>br</tt>' |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1434 | instruction, allowing a branch to occur to one of many possible |
| 1435 | destinations.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1436 | |
| 1437 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1438 | <h5>Arguments:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1439 | |
| 1440 | <p>The '<tt>switch</tt>' instruction uses three parameters: an integer |
| 1441 | comparison value '<tt>value</tt>', a default '<tt>label</tt>' destination, and |
| 1442 | an array of pairs of comparison value constants and '<tt>label</tt>'s. The |
| 1443 | table is not allowed to contain duplicate constant entries.</p> |
| 1444 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1445 | <h5>Semantics:</h5> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1446 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1447 | <p>The <tt>switch</tt> instruction specifies a table of values and |
| 1448 | destinations. When the '<tt>switch</tt>' instruction is executed, this |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1449 | table is searched for the given value. If the value is found, control flow is |
| 1450 | transfered to the corresponding destination; otherwise, control flow is |
| 1451 | transfered to the default destination.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1452 | |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1453 | <h5>Implementation:</h5> |
| 1454 | |
| 1455 | <p>Depending on properties of the target machine and the particular |
| 1456 | <tt>switch</tt> instruction, this instruction may be code generated in different |
John Criswell | 8411475 | 2004-06-25 16:05:06 +0000 | [diff] [blame] | 1457 | ways. For example, it could be generated as a series of chained conditional |
| 1458 | branches or with a lookup table.</p> |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1459 | |
| 1460 | <h5>Example:</h5> |
| 1461 | |
| 1462 | <pre> |
| 1463 | <i>; Emulate a conditional br instruction</i> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 1464 | %Val = <a href="#i_zext">zext</a> bool %value to int |
Chris Lattner | c88c17b | 2004-02-24 04:54:45 +0000 | [diff] [blame] | 1465 | switch int %Val, label %truedest [int 0, label %falsedest ] |
| 1466 | |
| 1467 | <i>; Emulate an unconditional br instruction</i> |
| 1468 | switch uint 0, label %dest [ ] |
| 1469 | |
| 1470 | <i>; Implement a jump table:</i> |
| 1471 | switch uint %val, label %otherwise [ uint 0, label %onzero |
| 1472 | uint 1, label %onone |
| 1473 | uint 2, label %ontwo ] |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1474 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1475 | </div> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1476 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1477 | <!-- _______________________________________________________________________ --> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1478 | <div class="doc_subsubsection"> |
| 1479 | <a name="i_invoke">'<tt>invoke</tt>' Instruction</a> |
| 1480 | </div> |
| 1481 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1482 | <div class="doc_text"> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1483 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1484 | <h5>Syntax:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1485 | |
| 1486 | <pre> |
| 1487 | <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] | 1488 | to label <normal label> unwind label <exception label> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1489 | </pre> |
| 1490 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 1491 | <h5>Overview:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1492 | |
| 1493 | <p>The '<tt>invoke</tt>' instruction causes control to transfer to a specified |
| 1494 | function, with the possibility of control flow transfer to either the |
John Criswell | e4c57cc | 2005-05-12 16:52:32 +0000 | [diff] [blame] | 1495 | '<tt>normal</tt>' label or the |
| 1496 | '<tt>exception</tt>' label. If the callee function returns with the |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1497 | "<tt><a href="#i_ret">ret</a></tt>" instruction, control flow will return to the |
| 1498 | "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] | 1499 | href="#i_unwind"><tt>unwind</tt></a>" instruction, control is interrupted and |
| 1500 | continued at the dynamically nearest "exception" label.</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1501 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1502 | <h5>Arguments:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1503 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1504 | <p>This instruction requires several arguments:</p> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1505 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1506 | <ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1507 | <li> |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 1508 | The optional "cconv" marker indicates which <a href="callingconv">calling |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1509 | convention</a> the call should use. If none is specified, the call defaults |
| 1510 | to using C calling conventions. |
| 1511 | </li> |
| 1512 | <li>'<tt>ptr to function ty</tt>': shall be the signature of the pointer to |
| 1513 | function value being invoked. In most cases, this is a direct function |
| 1514 | invocation, but indirect <tt>invoke</tt>s are just as possible, branching off |
| 1515 | an arbitrary pointer to function value. |
| 1516 | </li> |
| 1517 | |
| 1518 | <li>'<tt>function ptr val</tt>': An LLVM value containing a pointer to a |
| 1519 | function to be invoked. </li> |
| 1520 | |
| 1521 | <li>'<tt>function args</tt>': argument list whose types match the function |
| 1522 | signature argument types. If the function signature indicates the function |
| 1523 | accepts a variable number of arguments, the extra arguments can be |
| 1524 | specified. </li> |
| 1525 | |
| 1526 | <li>'<tt>normal label</tt>': the label reached when the called function |
| 1527 | executes a '<tt><a href="#i_ret">ret</a></tt>' instruction. </li> |
| 1528 | |
| 1529 | <li>'<tt>exception label</tt>': the label reached when a callee returns with |
| 1530 | the <a href="#i_unwind"><tt>unwind</tt></a> instruction. </li> |
| 1531 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1532 | </ol> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1533 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1534 | <h5>Semantics:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1535 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1536 | <p>This instruction is designed to operate as a standard '<tt><a |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1537 | href="#i_call">call</a></tt>' instruction in most regards. The primary |
| 1538 | difference is that it establishes an association with a label, which is used by |
| 1539 | the runtime library to unwind the stack.</p> |
| 1540 | |
| 1541 | <p>This instruction is used in languages with destructors to ensure that proper |
| 1542 | cleanup is performed in the case of either a <tt>longjmp</tt> or a thrown |
| 1543 | exception. Additionally, this is important for implementation of |
| 1544 | '<tt>catch</tt>' clauses in high-level languages that support them.</p> |
| 1545 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1546 | <h5>Example:</h5> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1547 | <pre> |
| 1548 | %retval = invoke int %Test(int 15) to label %Continue |
Chris Lattner | 76b8a33 | 2006-05-14 18:23:06 +0000 | [diff] [blame] | 1549 | unwind label %TestCleanup <i>; {int}:retval set</i> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1550 | %retval = invoke <a href="#callingconv">coldcc</a> int %Test(int 15) to label %Continue |
Chris Lattner | 76b8a33 | 2006-05-14 18:23:06 +0000 | [diff] [blame] | 1551 | unwind label %TestCleanup <i>; {int}:retval set</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1552 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1553 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1554 | |
| 1555 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1556 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1557 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1558 | <div class="doc_subsubsection"> <a name="i_unwind">'<tt>unwind</tt>' |
| 1559 | Instruction</a> </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1560 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1561 | <div class="doc_text"> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1562 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1563 | <h5>Syntax:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1564 | <pre> |
| 1565 | unwind |
| 1566 | </pre> |
| 1567 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1568 | <h5>Overview:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1569 | |
| 1570 | <p>The '<tt>unwind</tt>' instruction unwinds the stack, continuing control flow |
| 1571 | at the first callee in the dynamic call stack which used an <a |
| 1572 | href="#i_invoke"><tt>invoke</tt></a> instruction to perform the call. This is |
| 1573 | primarily used to implement exception handling.</p> |
| 1574 | |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 1575 | <h5>Semantics:</h5> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1576 | |
| 1577 | <p>The '<tt>unwind</tt>' intrinsic causes execution of the current function to |
| 1578 | immediately halt. The dynamic call stack is then searched for the first <a |
| 1579 | href="#i_invoke"><tt>invoke</tt></a> instruction on the call stack. Once found, |
| 1580 | execution continues at the "exceptional" destination block specified by the |
| 1581 | <tt>invoke</tt> instruction. If there is no <tt>invoke</tt> instruction in the |
| 1582 | dynamic call chain, undefined behavior results.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1583 | </div> |
Chris Lattner | 35eca58 | 2004-10-16 18:04:13 +0000 | [diff] [blame] | 1584 | |
| 1585 | <!-- _______________________________________________________________________ --> |
| 1586 | |
| 1587 | <div class="doc_subsubsection"> <a name="i_unreachable">'<tt>unreachable</tt>' |
| 1588 | Instruction</a> </div> |
| 1589 | |
| 1590 | <div class="doc_text"> |
| 1591 | |
| 1592 | <h5>Syntax:</h5> |
| 1593 | <pre> |
| 1594 | unreachable |
| 1595 | </pre> |
| 1596 | |
| 1597 | <h5>Overview:</h5> |
| 1598 | |
| 1599 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics. This |
| 1600 | instruction is used to inform the optimizer that a particular portion of the |
| 1601 | code is not reachable. This can be used to indicate that the code after a |
| 1602 | no-return function cannot be reached, and other facts.</p> |
| 1603 | |
| 1604 | <h5>Semantics:</h5> |
| 1605 | |
| 1606 | <p>The '<tt>unreachable</tt>' instruction has no defined semantics.</p> |
| 1607 | </div> |
| 1608 | |
| 1609 | |
| 1610 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1611 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1612 | <div class="doc_subsection"> <a name="binaryops">Binary Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1613 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1614 | <p>Binary operators are used to do most of the computation in a |
| 1615 | program. They require two operands, execute an operation on them, and |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1616 | produce a single value. The operands might represent |
Chris Lattner | a58561b | 2004-08-12 19:12:28 +0000 | [diff] [blame] | 1617 | multiple data, as is the case with the <a href="#t_packed">packed</a> data type. |
| 1618 | The result value of a binary operator is not |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1619 | necessarily the same type as its operands.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1620 | <p>There are several different binary operators:</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1621 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1622 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1623 | <div class="doc_subsubsection"> <a name="i_add">'<tt>add</tt>' |
| 1624 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1625 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1626 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1627 | <pre> <result> = add <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1628 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1629 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1630 | <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] | 1631 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1632 | <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] | 1633 | href="#t_integer">integer</a> or <a href="#t_floating">floating point</a> values. |
| 1634 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1635 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1636 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1637 | <p>The value produced is the integer or floating point sum of the two |
| 1638 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1639 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1640 | <pre> <result> = add int 4, %var <i>; yields {int}:result = 4 + %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1641 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1642 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1643 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1644 | <div class="doc_subsubsection"> <a name="i_sub">'<tt>sub</tt>' |
| 1645 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1646 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1647 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1648 | <pre> <result> = sub <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1649 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1650 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1651 | <p>The '<tt>sub</tt>' instruction returns the difference of its two |
| 1652 | operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1653 | <p>Note that the '<tt>sub</tt>' instruction is used to represent the '<tt>neg</tt>' |
| 1654 | instruction present in most other intermediate representations.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1655 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1656 | <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] | 1657 | 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] | 1658 | values. |
| 1659 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1660 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1661 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1662 | <p>The value produced is the integer or floating point difference of |
| 1663 | the two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1664 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1665 | <pre> <result> = sub int 4, %var <i>; yields {int}:result = 4 - %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1666 | <result> = sub int 0, %val <i>; yields {int}:result = -%var</i> |
| 1667 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1668 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1669 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1670 | <div class="doc_subsubsection"> <a name="i_mul">'<tt>mul</tt>' |
| 1671 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1672 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1673 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1674 | <pre> <result> = mul <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1675 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1676 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1677 | <p>The '<tt>mul</tt>' instruction returns the product of its two |
| 1678 | operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1679 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1680 | <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] | 1681 | 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] | 1682 | values. |
| 1683 | This instruction can also take <a href="#t_packed">packed</a> versions of the values. |
| 1684 | Both arguments must have identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1685 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1686 | <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] | 1687 | two operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1688 | <p>There is no signed vs unsigned multiplication. The appropriate |
| 1689 | action is taken based on the type of the operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1690 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1691 | <pre> <result> = mul int 4, %var <i>; yields {int}:result = 4 * %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1692 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1693 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1694 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1695 | <div class="doc_subsubsection"> <a name="i_udiv">'<tt>udiv</tt>' Instruction |
| 1696 | </a></div> |
| 1697 | <div class="doc_text"> |
| 1698 | <h5>Syntax:</h5> |
| 1699 | <pre> <result> = udiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1700 | </pre> |
| 1701 | <h5>Overview:</h5> |
| 1702 | <p>The '<tt>udiv</tt>' instruction returns the quotient of its two |
| 1703 | operands.</p> |
| 1704 | <h5>Arguments:</h5> |
| 1705 | <p>The two arguments to the '<tt>udiv</tt>' instruction must be |
| 1706 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
| 1707 | types. This instruction can also take <a href="#t_packed">packed</a> versions |
| 1708 | of the values in which case the elements must be integers.</p> |
| 1709 | <h5>Semantics:</h5> |
| 1710 | <p>The value produced is the unsigned integer quotient of the two operands. This |
| 1711 | instruction always performs an unsigned division operation, regardless of |
| 1712 | whether the arguments are unsigned or not.</p> |
| 1713 | <h5>Example:</h5> |
| 1714 | <pre> <result> = udiv uint 4, %var <i>; yields {uint}:result = 4 / %var</i> |
| 1715 | </pre> |
| 1716 | </div> |
| 1717 | <!-- _______________________________________________________________________ --> |
| 1718 | <div class="doc_subsubsection"> <a name="i_sdiv">'<tt>sdiv</tt>' Instruction |
| 1719 | </a> </div> |
| 1720 | <div class="doc_text"> |
| 1721 | <h5>Syntax:</h5> |
| 1722 | <pre> <result> = sdiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1723 | </pre> |
| 1724 | <h5>Overview:</h5> |
| 1725 | <p>The '<tt>sdiv</tt>' instruction returns the quotient of its two |
| 1726 | operands.</p> |
| 1727 | <h5>Arguments:</h5> |
| 1728 | <p>The two arguments to the '<tt>sdiv</tt>' instruction must be |
| 1729 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
| 1730 | types. This instruction can also take <a href="#t_packed">packed</a> versions |
| 1731 | of the values in which case the elements must be integers.</p> |
| 1732 | <h5>Semantics:</h5> |
| 1733 | <p>The value produced is the signed integer quotient of the two operands. This |
| 1734 | instruction always performs a signed division operation, regardless of whether |
| 1735 | the arguments are signed or not.</p> |
| 1736 | <h5>Example:</h5> |
| 1737 | <pre> <result> = sdiv int 4, %var <i>; yields {int}:result = 4 / %var</i> |
| 1738 | </pre> |
| 1739 | </div> |
| 1740 | <!-- _______________________________________________________________________ --> |
| 1741 | <div class="doc_subsubsection"> <a name="i_fdiv">'<tt>fdiv</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1742 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1743 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1744 | <h5>Syntax:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1745 | <pre> <result> = fdiv <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1746 | </pre> |
| 1747 | <h5>Overview:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1748 | <p>The '<tt>fdiv</tt>' instruction returns the quotient of its two |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1749 | operands.</p> |
| 1750 | <h5>Arguments:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1751 | <p>The two arguments to the '<tt>div</tt>' instruction must be |
| 1752 | <a href="#t_floating">floating point</a> values. Both arguments must have |
| 1753 | identical types. This instruction can also take <a href="#t_packed">packed</a> |
| 1754 | versions of the values in which case the elements must be floating point.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1755 | <h5>Semantics:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1756 | <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] | 1757 | <h5>Example:</h5> |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 1758 | <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] | 1759 | </pre> |
| 1760 | </div> |
| 1761 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1762 | <div class="doc_subsubsection"> <a name="i_urem">'<tt>urem</tt>' Instruction</a> |
| 1763 | </div> |
| 1764 | <div class="doc_text"> |
| 1765 | <h5>Syntax:</h5> |
| 1766 | <pre> <result> = urem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1767 | </pre> |
| 1768 | <h5>Overview:</h5> |
| 1769 | <p>The '<tt>urem</tt>' instruction returns the remainder from the |
| 1770 | unsigned division of its two arguments.</p> |
| 1771 | <h5>Arguments:</h5> |
| 1772 | <p>The two arguments to the '<tt>urem</tt>' instruction must be |
| 1773 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
| 1774 | types.</p> |
| 1775 | <h5>Semantics:</h5> |
| 1776 | <p>This instruction returns the unsigned integer <i>remainder</i> of a division. |
| 1777 | This instruction always performs an unsigned division to get the remainder, |
| 1778 | regardless of whether the arguments are unsigned or not.</p> |
| 1779 | <h5>Example:</h5> |
| 1780 | <pre> <result> = urem uint 4, %var <i>; yields {uint}:result = 4 % %var</i> |
| 1781 | </pre> |
| 1782 | |
| 1783 | </div> |
| 1784 | <!-- _______________________________________________________________________ --> |
| 1785 | <div class="doc_subsubsection"> <a name="i_srem">'<tt>srem</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1786 | Instruction</a> </div> |
| 1787 | <div class="doc_text"> |
| 1788 | <h5>Syntax:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1789 | <pre> <result> = srem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1790 | </pre> |
| 1791 | <h5>Overview:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1792 | <p>The '<tt>srem</tt>' instruction returns the remainder from the |
| 1793 | signed division of its two operands.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1794 | <h5>Arguments:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1795 | <p>The two arguments to the '<tt>srem</tt>' instruction must be |
| 1796 | <a href="#t_integer">integer</a> values. Both arguments must have identical |
| 1797 | types.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1798 | <h5>Semantics:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1799 | <p>This instruction returns the <i>remainder</i> of a division (where the result |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1800 | has the same sign as the divisor), not the <i>modulus</i> (where the |
| 1801 | result has the same sign as the dividend) of a value. For more |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 1802 | information about the difference, see <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1803 | href="http://mathforum.org/dr.math/problems/anne.4.28.99.html">The |
| 1804 | Math Forum</a>.</p> |
| 1805 | <h5>Example:</h5> |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 1806 | <pre> <result> = srem int 4, %var <i>; yields {int}:result = 4 % %var</i> |
| 1807 | </pre> |
| 1808 | |
| 1809 | </div> |
| 1810 | <!-- _______________________________________________________________________ --> |
| 1811 | <div class="doc_subsubsection"> <a name="i_frem">'<tt>frem</tt>' |
| 1812 | Instruction</a> </div> |
| 1813 | <div class="doc_text"> |
| 1814 | <h5>Syntax:</h5> |
| 1815 | <pre> <result> = frem <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
| 1816 | </pre> |
| 1817 | <h5>Overview:</h5> |
| 1818 | <p>The '<tt>frem</tt>' instruction returns the remainder from the |
| 1819 | division of its two operands.</p> |
| 1820 | <h5>Arguments:</h5> |
| 1821 | <p>The two arguments to the '<tt>frem</tt>' instruction must be |
| 1822 | <a href="#t_floating">floating point</a> values. Both arguments must have |
| 1823 | identical types.</p> |
| 1824 | <h5>Semantics:</h5> |
| 1825 | <p>This instruction returns the <i>remainder</i> of a division.</p> |
| 1826 | <h5>Example:</h5> |
| 1827 | <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] | 1828 | </pre> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 1829 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1830 | </div> |
| 1831 | <!-- _______________________________________________________________________ --> |
| 1832 | <div class="doc_subsubsection"> <a name="i_setcc">'<tt>set<i>cc</i></tt>' |
| 1833 | Instructions</a> </div> |
| 1834 | <div class="doc_text"> |
| 1835 | <h5>Syntax:</h5> |
| 1836 | <pre> <result> = seteq <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1837 | <result> = setne <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1838 | <result> = setlt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1839 | <result> = setgt <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1840 | <result> = setle <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1841 | <result> = setge <ty> <var1>, <var2> <i>; yields {bool}:result</i> |
| 1842 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1843 | <h5>Overview:</h5> |
| 1844 | <p>The '<tt>set<i>cc</i></tt>' family of instructions returns a boolean |
| 1845 | value based on a comparison of their two operands.</p> |
| 1846 | <h5>Arguments:</h5> |
| 1847 | <p>The two arguments to the '<tt>set<i>cc</i></tt>' instructions must |
| 1848 | be of <a href="#t_firstclass">first class</a> type (it is not possible |
| 1849 | to compare '<tt>label</tt>'s, '<tt>array</tt>'s, '<tt>structure</tt>' |
| 1850 | or '<tt>void</tt>' values, etc...). Both arguments must have identical |
| 1851 | types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1852 | <h5>Semantics:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1853 | <p>The '<tt>seteq</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1854 | value if both operands are equal.<br> |
| 1855 | The '<tt>setne</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1856 | value if both operands are unequal.<br> |
| 1857 | The '<tt>setlt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1858 | value if the first operand is less than the second operand.<br> |
| 1859 | The '<tt>setgt</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1860 | value if the first operand is greater than the second operand.<br> |
| 1861 | The '<tt>setle</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1862 | value if the first operand is less than or equal to the second operand.<br> |
| 1863 | The '<tt>setge</tt>' instruction yields a <tt>true</tt> '<tt>bool</tt>' |
| 1864 | value if the first operand is greater than or equal to the second |
| 1865 | operand.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1866 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1867 | <pre> <result> = seteq int 4, 5 <i>; yields {bool}:result = false</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1868 | <result> = setne float 4, 5 <i>; yields {bool}:result = true</i> |
| 1869 | <result> = setlt uint 4, 5 <i>; yields {bool}:result = true</i> |
| 1870 | <result> = setgt sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1871 | <result> = setle sbyte 4, 5 <i>; yields {bool}:result = true</i> |
| 1872 | <result> = setge sbyte 4, 5 <i>; yields {bool}:result = false</i> |
| 1873 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1874 | </div> |
Robert Bocchino | 7b81c75 | 2006-02-17 21:18:08 +0000 | [diff] [blame] | 1875 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1876 | <!-- ======================================================================= --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1877 | <div class="doc_subsection"> <a name="bitwiseops">Bitwise Binary |
| 1878 | Operations</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1879 | <div class="doc_text"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1880 | <p>Bitwise binary operators are used to do various forms of |
| 1881 | bit-twiddling in a program. They are generally very efficient |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 1882 | instructions and can commonly be strength reduced from other |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1883 | instructions. They require two operands, execute an operation on them, |
| 1884 | and produce a single value. The resulting value of the bitwise binary |
| 1885 | operators is always the same type as its first operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1886 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1887 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1888 | <div class="doc_subsubsection"> <a name="i_and">'<tt>and</tt>' |
| 1889 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1890 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1891 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1892 | <pre> <result> = and <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1893 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1894 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1895 | <p>The '<tt>and</tt>' instruction returns the bitwise logical and of |
| 1896 | its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1897 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1898 | <p>The two arguments to the '<tt>and</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1899 | href="#t_integral">integral</a> values. Both arguments must have |
| 1900 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1901 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1902 | <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] | 1903 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1904 | <div style="align: center"> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1905 | <table border="1" cellspacing="0" cellpadding="4"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1906 | <tbody> |
| 1907 | <tr> |
| 1908 | <td>In0</td> |
| 1909 | <td>In1</td> |
| 1910 | <td>Out</td> |
| 1911 | </tr> |
| 1912 | <tr> |
| 1913 | <td>0</td> |
| 1914 | <td>0</td> |
| 1915 | <td>0</td> |
| 1916 | </tr> |
| 1917 | <tr> |
| 1918 | <td>0</td> |
| 1919 | <td>1</td> |
| 1920 | <td>0</td> |
| 1921 | </tr> |
| 1922 | <tr> |
| 1923 | <td>1</td> |
| 1924 | <td>0</td> |
| 1925 | <td>0</td> |
| 1926 | </tr> |
| 1927 | <tr> |
| 1928 | <td>1</td> |
| 1929 | <td>1</td> |
| 1930 | <td>1</td> |
| 1931 | </tr> |
| 1932 | </tbody> |
| 1933 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1934 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1935 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1936 | <pre> <result> = and int 4, %var <i>; yields {int}:result = 4 & %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1937 | <result> = and int 15, 40 <i>; yields {int}:result = 8</i> |
| 1938 | <result> = and int 4, 8 <i>; yields {int}:result = 0</i> |
| 1939 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1940 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1941 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1942 | <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] | 1943 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1944 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1945 | <pre> <result> = or <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1946 | </pre> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1947 | <h5>Overview:</h5> |
| 1948 | <p>The '<tt>or</tt>' instruction returns the bitwise logical inclusive |
| 1949 | or of its two operands.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1950 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1951 | <p>The two arguments to the '<tt>or</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1952 | href="#t_integral">integral</a> values. Both arguments must have |
| 1953 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1954 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1955 | <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] | 1956 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1957 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1958 | <table border="1" cellspacing="0" cellpadding="4"> |
| 1959 | <tbody> |
| 1960 | <tr> |
| 1961 | <td>In0</td> |
| 1962 | <td>In1</td> |
| 1963 | <td>Out</td> |
| 1964 | </tr> |
| 1965 | <tr> |
| 1966 | <td>0</td> |
| 1967 | <td>0</td> |
| 1968 | <td>0</td> |
| 1969 | </tr> |
| 1970 | <tr> |
| 1971 | <td>0</td> |
| 1972 | <td>1</td> |
| 1973 | <td>1</td> |
| 1974 | </tr> |
| 1975 | <tr> |
| 1976 | <td>1</td> |
| 1977 | <td>0</td> |
| 1978 | <td>1</td> |
| 1979 | </tr> |
| 1980 | <tr> |
| 1981 | <td>1</td> |
| 1982 | <td>1</td> |
| 1983 | <td>1</td> |
| 1984 | </tr> |
| 1985 | </tbody> |
| 1986 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 1987 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1988 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1989 | <pre> <result> = or int 4, %var <i>; yields {int}:result = 4 | %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1990 | <result> = or int 15, 40 <i>; yields {int}:result = 47</i> |
| 1991 | <result> = or int 4, 8 <i>; yields {int}:result = 12</i> |
| 1992 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1993 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1994 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1995 | <div class="doc_subsubsection"> <a name="i_xor">'<tt>xor</tt>' |
| 1996 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 1997 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1998 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 1999 | <pre> <result> = xor <ty> <var1>, <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2000 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2001 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2002 | <p>The '<tt>xor</tt>' instruction returns the bitwise logical exclusive |
| 2003 | or of its two operands. The <tt>xor</tt> is used to implement the |
| 2004 | "one's complement" operation, which is the "~" operator in C.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2005 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2006 | <p>The two arguments to the '<tt>xor</tt>' instruction must be <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2007 | href="#t_integral">integral</a> values. Both arguments must have |
| 2008 | identical types.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2009 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2010 | <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] | 2011 | <p> </p> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2012 | <div style="align: center"> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2013 | <table border="1" cellspacing="0" cellpadding="4"> |
| 2014 | <tbody> |
| 2015 | <tr> |
| 2016 | <td>In0</td> |
| 2017 | <td>In1</td> |
| 2018 | <td>Out</td> |
| 2019 | </tr> |
| 2020 | <tr> |
| 2021 | <td>0</td> |
| 2022 | <td>0</td> |
| 2023 | <td>0</td> |
| 2024 | </tr> |
| 2025 | <tr> |
| 2026 | <td>0</td> |
| 2027 | <td>1</td> |
| 2028 | <td>1</td> |
| 2029 | </tr> |
| 2030 | <tr> |
| 2031 | <td>1</td> |
| 2032 | <td>0</td> |
| 2033 | <td>1</td> |
| 2034 | </tr> |
| 2035 | <tr> |
| 2036 | <td>1</td> |
| 2037 | <td>1</td> |
| 2038 | <td>0</td> |
| 2039 | </tr> |
| 2040 | </tbody> |
| 2041 | </table> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 2042 | </div> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2043 | <p> </p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2044 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2045 | <pre> <result> = xor int 4, %var <i>; yields {int}:result = 4 ^ %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2046 | <result> = xor int 15, 40 <i>; yields {int}:result = 39</i> |
| 2047 | <result> = xor int 4, 8 <i>; yields {int}:result = 12</i> |
Chris Lattner | 27f71f2 | 2003-09-03 00:41:47 +0000 | [diff] [blame] | 2048 | <result> = xor int %V, -1 <i>; yields {int}:result = ~%V</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2049 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2050 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2051 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2052 | <div class="doc_subsubsection"> <a name="i_shl">'<tt>shl</tt>' |
| 2053 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2054 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2055 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2056 | <pre> <result> = shl <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2057 | </pre> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2058 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2059 | <p>The '<tt>shl</tt>' instruction returns the first operand shifted to |
| 2060 | the left a specified number of bits.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2061 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2062 | <p>The first argument to the '<tt>shl</tt>' instruction must be an <a |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2063 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' |
| 2064 | type.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2065 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2066 | <p>The value produced is <tt>var1</tt> * 2<sup><tt>var2</tt></sup>.</p> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2067 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2068 | <pre> <result> = shl int 4, ubyte %var <i>; yields {int}:result = 4 << %var</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2069 | <result> = shl int 4, ubyte 2 <i>; yields {int}:result = 16</i> |
| 2070 | <result> = shl int 1, ubyte 10 <i>; yields {int}:result = 1024</i> |
| 2071 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2072 | </div> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2073 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2074 | <div class="doc_subsubsection"> <a name="i_lshr">'<tt>lshr</tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2075 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2076 | <div class="doc_text"> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2077 | <h5>Syntax:</h5> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2078 | <pre> <result> = lshr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2079 | </pre> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2080 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2081 | <h5>Overview:</h5> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2082 | <p>The '<tt>lshr</tt>' instruction (logical shift right) returns the first |
| 2083 | operand shifted to the right a specified number of bits.</p> |
| 2084 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2085 | <h5>Arguments:</h5> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2086 | <p>The first argument to the '<tt>lshr</tt>' instruction must be an <a |
| 2087 | href="#t_integer">integer</a> type. The second argument must be an '<tt>ubyte</tt>' type.</p> |
| 2088 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2089 | <h5>Semantics:</h5> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2090 | <p>This instruction always performs a logical shift right operation, regardless |
| 2091 | of whether the arguments are unsigned or not. The <tt>var2</tt> most significant |
| 2092 | bits will be filled with zero bits after the shift.</p> |
| 2093 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2094 | <h5>Example:</h5> |
Reid Spencer | 3822ff5 | 2006-11-08 06:47:33 +0000 | [diff] [blame] | 2095 | <pre> |
| 2096 | <result> = lshr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i> |
| 2097 | <result> = lshr int 4, ubyte 2 <i>; yields {uint}:result = 1</i> |
| 2098 | <result> = lshr sbyte 4, ubyte 3 <i>; yields {sbyte}:result = 0</i> |
| 2099 | <result> = lshr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = 0x7FFFFFFF </i> |
| 2100 | </pre> |
| 2101 | </div> |
| 2102 | |
| 2103 | <!-- ======================================================================= --> |
| 2104 | <div class="doc_subsubsection"> <a name="i_ashr">'<tt>ashr</tt>' |
| 2105 | Instruction</a> </div> |
| 2106 | <div class="doc_text"> |
| 2107 | |
| 2108 | <h5>Syntax:</h5> |
| 2109 | <pre> <result> = ashr <ty> <var1>, ubyte <var2> <i>; yields {ty}:result</i> |
| 2110 | </pre> |
| 2111 | |
| 2112 | <h5>Overview:</h5> |
| 2113 | <p>The '<tt>ashr</tt>' instruction (arithmetic shift right) returns the first |
| 2114 | operand shifted to the right a specified number of bits.</p> |
| 2115 | |
| 2116 | <h5>Arguments:</h5> |
| 2117 | <p>The first argument to the '<tt>ashr</tt>' instruction must be an |
| 2118 | <a href="#t_integer">integer</a> type. The second argument must be an |
| 2119 | '<tt>ubyte</tt>' type.</p> |
| 2120 | |
| 2121 | <h5>Semantics:</h5> |
| 2122 | <p>This instruction always performs an arithmetic shift right operation, |
| 2123 | regardless of whether the arguments are signed or not. The <tt>var2</tt> most |
| 2124 | significant bits will be filled with the sign bit of <tt>var1</tt>.</p> |
| 2125 | |
| 2126 | <h5>Example:</h5> |
| 2127 | <pre> |
| 2128 | <result> = ashr uint 4, ubyte 1 <i>; yields {uint}:result = 2</i> |
| 2129 | <result> = ashr int 4, ubyte 2 <i>; yields {int}:result = 1</i> |
| 2130 | <result> = ashr ubyte 4, ubyte 3 <i>; yields {ubyte}:result = 0</i> |
| 2131 | <result> = ashr sbyte -2, ubyte 1 <i>; yields {sbyte}:result = -1</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2132 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2133 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2134 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2135 | <!-- ======================================================================= --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2136 | <div class="doc_subsection"> |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2137 | <a name="vectorops">Vector Operations</a> |
| 2138 | </div> |
| 2139 | |
| 2140 | <div class="doc_text"> |
| 2141 | |
| 2142 | <p>LLVM supports several instructions to represent vector operations in a |
| 2143 | target-independent manner. This instructions cover the element-access and |
| 2144 | vector-specific operations needed to process vectors effectively. While LLVM |
| 2145 | does directly support these vector operations, many sophisticated algorithms |
| 2146 | will want to use target-specific intrinsics to take full advantage of a specific |
| 2147 | target.</p> |
| 2148 | |
| 2149 | </div> |
| 2150 | |
| 2151 | <!-- _______________________________________________________________________ --> |
| 2152 | <div class="doc_subsubsection"> |
| 2153 | <a name="i_extractelement">'<tt>extractelement</tt>' Instruction</a> |
| 2154 | </div> |
| 2155 | |
| 2156 | <div class="doc_text"> |
| 2157 | |
| 2158 | <h5>Syntax:</h5> |
| 2159 | |
| 2160 | <pre> |
| 2161 | <result> = extractelement <n x <ty>> <val>, uint <idx> <i>; yields <ty></i> |
| 2162 | </pre> |
| 2163 | |
| 2164 | <h5>Overview:</h5> |
| 2165 | |
| 2166 | <p> |
| 2167 | The '<tt>extractelement</tt>' instruction extracts a single scalar |
| 2168 | element from a packed vector at a specified index. |
| 2169 | </p> |
| 2170 | |
| 2171 | |
| 2172 | <h5>Arguments:</h5> |
| 2173 | |
| 2174 | <p> |
| 2175 | The first operand of an '<tt>extractelement</tt>' instruction is a |
| 2176 | value of <a href="#t_packed">packed</a> type. The second operand is |
| 2177 | an index indicating the position from which to extract the element. |
| 2178 | The index may be a variable.</p> |
| 2179 | |
| 2180 | <h5>Semantics:</h5> |
| 2181 | |
| 2182 | <p> |
| 2183 | The result is a scalar of the same type as the element type of |
| 2184 | <tt>val</tt>. Its value is the value at position <tt>idx</tt> of |
| 2185 | <tt>val</tt>. If <tt>idx</tt> exceeds the length of <tt>val</tt>, the |
| 2186 | results are undefined. |
| 2187 | </p> |
| 2188 | |
| 2189 | <h5>Example:</h5> |
| 2190 | |
| 2191 | <pre> |
| 2192 | %result = extractelement <4 x int> %vec, uint 0 <i>; yields int</i> |
| 2193 | </pre> |
| 2194 | </div> |
| 2195 | |
| 2196 | |
| 2197 | <!-- _______________________________________________________________________ --> |
| 2198 | <div class="doc_subsubsection"> |
| 2199 | <a name="i_insertelement">'<tt>insertelement</tt>' Instruction</a> |
| 2200 | </div> |
| 2201 | |
| 2202 | <div class="doc_text"> |
| 2203 | |
| 2204 | <h5>Syntax:</h5> |
| 2205 | |
| 2206 | <pre> |
| 2207 | <result> = insertelement <n x <ty>> <val>, <ty> <elt>, uint <idx> <i>; yields <n x <ty>></i> |
| 2208 | </pre> |
| 2209 | |
| 2210 | <h5>Overview:</h5> |
| 2211 | |
| 2212 | <p> |
| 2213 | The '<tt>insertelement</tt>' instruction inserts a scalar |
| 2214 | element into a packed vector at a specified index. |
| 2215 | </p> |
| 2216 | |
| 2217 | |
| 2218 | <h5>Arguments:</h5> |
| 2219 | |
| 2220 | <p> |
| 2221 | The first operand of an '<tt>insertelement</tt>' instruction is a |
| 2222 | value of <a href="#t_packed">packed</a> type. The second operand is a |
| 2223 | scalar value whose type must equal the element type of the first |
| 2224 | operand. The third operand is an index indicating the position at |
| 2225 | which to insert the value. The index may be a variable.</p> |
| 2226 | |
| 2227 | <h5>Semantics:</h5> |
| 2228 | |
| 2229 | <p> |
| 2230 | The result is a packed vector of the same type as <tt>val</tt>. Its |
| 2231 | element values are those of <tt>val</tt> except at position |
| 2232 | <tt>idx</tt>, where it gets the value <tt>elt</tt>. If <tt>idx</tt> |
| 2233 | exceeds the length of <tt>val</tt>, the results are undefined. |
| 2234 | </p> |
| 2235 | |
| 2236 | <h5>Example:</h5> |
| 2237 | |
| 2238 | <pre> |
| 2239 | %result = insertelement <4 x int> %vec, int 1, uint 0 <i>; yields <4 x int></i> |
| 2240 | </pre> |
| 2241 | </div> |
| 2242 | |
| 2243 | <!-- _______________________________________________________________________ --> |
| 2244 | <div class="doc_subsubsection"> |
| 2245 | <a name="i_shufflevector">'<tt>shufflevector</tt>' Instruction</a> |
| 2246 | </div> |
| 2247 | |
| 2248 | <div class="doc_text"> |
| 2249 | |
| 2250 | <h5>Syntax:</h5> |
| 2251 | |
| 2252 | <pre> |
| 2253 | <result> = shufflevector <n x <ty>> <v1>, <n x <ty>> <v2>, <n x uint> <mask> <i>; yields <n x <ty>></i> |
| 2254 | </pre> |
| 2255 | |
| 2256 | <h5>Overview:</h5> |
| 2257 | |
| 2258 | <p> |
| 2259 | The '<tt>shufflevector</tt>' instruction constructs a permutation of elements |
| 2260 | from two input vectors, returning a vector of the same type. |
| 2261 | </p> |
| 2262 | |
| 2263 | <h5>Arguments:</h5> |
| 2264 | |
| 2265 | <p> |
| 2266 | The first two operands of a '<tt>shufflevector</tt>' instruction are vectors |
| 2267 | with types that match each other and types that match the result of the |
| 2268 | instruction. The third argument is a shuffle mask, which has the same number |
| 2269 | of elements as the other vector type, but whose element type is always 'uint'. |
| 2270 | </p> |
| 2271 | |
| 2272 | <p> |
| 2273 | The shuffle mask operand is required to be a constant vector with either |
| 2274 | constant integer or undef values. |
| 2275 | </p> |
| 2276 | |
| 2277 | <h5>Semantics:</h5> |
| 2278 | |
| 2279 | <p> |
| 2280 | The elements of the two input vectors are numbered from left to right across |
| 2281 | both of the vectors. The shuffle mask operand specifies, for each element of |
| 2282 | the result vector, which element of the two input registers the result element |
| 2283 | gets. The element selector may be undef (meaning "don't care") and the second |
| 2284 | operand may be undef if performing a shuffle from only one vector. |
| 2285 | </p> |
| 2286 | |
| 2287 | <h5>Example:</h5> |
| 2288 | |
| 2289 | <pre> |
| 2290 | %result = shufflevector <4 x int> %v1, <4 x int> %v2, |
| 2291 | <4 x uint> <uint 0, uint 4, uint 1, uint 5> <i>; yields <4 x int></i> |
| 2292 | %result = shufflevector <4 x int> %v1, <4 x int> undef, |
| 2293 | <4 x uint> <uint 0, uint 1, uint 2, uint 3> <i>; yields <4 x int></i> - Identity shuffle. |
| 2294 | </pre> |
| 2295 | </div> |
| 2296 | |
Tanya Lattner | 0947429 | 2006-04-14 19:24:33 +0000 | [diff] [blame] | 2297 | |
| 2298 | <!-- _______________________________________________________________________ --> |
| 2299 | <div class="doc_subsubsection"> <a name="i_vsetint">'<tt>vsetint</tt>' |
| 2300 | Instruction</a> </div> |
| 2301 | <div class="doc_text"> |
| 2302 | <h5>Syntax:</h5> |
| 2303 | <pre><result> = vsetint <op>, <n x <ty>> <var1>, <var2> <i>; yields <n x bool></i> |
| 2304 | </pre> |
| 2305 | |
| 2306 | <h5>Overview:</h5> |
| 2307 | |
| 2308 | <p>The '<tt>vsetint</tt>' instruction takes two integer vectors and |
| 2309 | returns a vector of boolean values representing, at each position, the |
| 2310 | result of the comparison between the values at that position in the |
| 2311 | two operands.</p> |
| 2312 | |
| 2313 | <h5>Arguments:</h5> |
| 2314 | |
| 2315 | <p>The arguments to a '<tt>vsetint</tt>' instruction are a comparison |
| 2316 | operation and two value arguments. The value arguments must be of <a |
| 2317 | href="#t_integral">integral</a> <a href="#t_packed">packed</a> type, |
| 2318 | and they must have identical types. The operation argument must be |
| 2319 | one of <tt>eq</tt>, <tt>ne</tt>, <tt>slt</tt>, <tt>sgt</tt>, |
| 2320 | <tt>sle</tt>, <tt>sge</tt>, <tt>ult</tt>, <tt>ugt</tt>, <tt>ule</tt>, |
| 2321 | <tt>uge</tt>, <tt>true</tt>, and <tt>false</tt>. The result is a |
| 2322 | packed <tt>bool</tt> value with the same length as each operand.</p> |
| 2323 | |
| 2324 | <h5>Semantics:</h5> |
| 2325 | |
| 2326 | <p>The following table shows the semantics of '<tt>vsetint</tt>'. For |
| 2327 | each position of the result, the comparison is done on the |
| 2328 | corresponding positions of the two value arguments. Note that the |
| 2329 | signedness of the comparison depends on the comparison opcode and |
| 2330 | <i>not</i> on the signedness of the value operands. E.g., <tt>vsetint |
| 2331 | slt <4 x unsigned> %x, %y</tt> does an elementwise <i>signed</i> |
| 2332 | comparison of <tt>%x</tt> and <tt>%y</tt>.</p> |
| 2333 | |
| 2334 | <table border="1" cellspacing="0" cellpadding="4"> |
| 2335 | <tbody> |
| 2336 | <tr><th>Operation</th><th>Result is true iff</th><th>Comparison is</th></tr> |
| 2337 | <tr><td><tt>eq</tt></td><td>var1 == var2</td><td>--</td></tr> |
| 2338 | <tr><td><tt>ne</tt></td><td>var1 != var2</td><td>--</td></tr> |
| 2339 | <tr><td><tt>slt</tt></td><td>var1 < var2</td><td>signed</td></tr> |
| 2340 | <tr><td><tt>sgt</tt></td><td>var1 > var2</td><td>signed</td></tr> |
| 2341 | <tr><td><tt>sle</tt></td><td>var1 <= var2</td><td>signed</td></tr> |
| 2342 | <tr><td><tt>sge</tt></td><td>var1 >= var2</td><td>signed</td></tr> |
| 2343 | <tr><td><tt>ult</tt></td><td>var1 < var2</td><td>unsigned</td></tr> |
| 2344 | <tr><td><tt>ugt</tt></td><td>var1 > var2</td><td>unsigned</td></tr> |
| 2345 | <tr><td><tt>ule</tt></td><td>var1 <= var2</td><td>unsigned</td></tr> |
| 2346 | <tr><td><tt>uge</tt></td><td>var1 >= var2</td><td>unsigned</td></tr> |
| 2347 | <tr><td><tt>true</tt></td><td>always</td><td>--</td></tr> |
| 2348 | <tr><td><tt>false</tt></td><td>never</td><td>--</td></tr> |
| 2349 | </tbody> |
| 2350 | </table> |
| 2351 | |
| 2352 | <h5>Example:</h5> |
| 2353 | <pre> <result> = vsetint eq <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = false, false</i> |
| 2354 | <result> = vsetint ne <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = true, true</i> |
| 2355 | <result> = vsetint slt <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = true, false</i> |
| 2356 | <result> = vsetint sgt <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = false, true</i> |
| 2357 | <result> = vsetint sle <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = true, false</i> |
| 2358 | <result> = vsetint sge <2 x int> <int 0, int 1>, <int 1, int 0> <i>; yields {<2 x bool>}:result = false, true</i> |
| 2359 | </pre> |
| 2360 | </div> |
| 2361 | |
| 2362 | <!-- _______________________________________________________________________ --> |
| 2363 | <div class="doc_subsubsection"> <a name="i_vsetfp">'<tt>vsetfp</tt>' |
| 2364 | Instruction</a> </div> |
| 2365 | <div class="doc_text"> |
| 2366 | <h5>Syntax:</h5> |
| 2367 | <pre><result> = vsetfp <op>, <n x <ty>> <var1>, <var2> <i>; yields <n x bool></i> |
| 2368 | </pre> |
| 2369 | |
| 2370 | <h5>Overview:</h5> |
| 2371 | |
| 2372 | <p>The '<tt>vsetfp</tt>' instruction takes two floating point vector |
| 2373 | arguments and returns a vector of boolean values representing, at each |
| 2374 | position, the result of the comparison between the values at that |
| 2375 | position in the two operands.</p> |
| 2376 | |
| 2377 | <h5>Arguments:</h5> |
| 2378 | |
| 2379 | <p>The arguments to a '<tt>vsetfp</tt>' instruction are a comparison |
| 2380 | operation and two value arguments. The value arguments must be of <a |
| 2381 | href="t_floating">floating point</a> <a href="#t_packed">packed</a> |
| 2382 | type, and they must have identical types. The operation argument must |
| 2383 | be one of <tt>eq</tt>, <tt>ne</tt>, <tt>lt</tt>, <tt>gt</tt>, |
| 2384 | <tt>le</tt>, <tt>ge</tt>, <tt>oeq</tt>, <tt>one</tt>, <tt>olt</tt>, |
| 2385 | <tt>ogt</tt>, <tt>ole</tt>, <tt>oge</tt>, <tt>ueq</tt>, <tt>une</tt>, |
| 2386 | <tt>ult</tt>, <tt>ugt</tt>, <tt>ule</tt>, <tt>uge</tt>, <tt>o</tt>, |
| 2387 | <tt>u</tt>, <tt>true</tt>, and <tt>false</tt>. The result is a packed |
| 2388 | <tt>bool</tt> value with the same length as each operand.</p> |
| 2389 | |
| 2390 | <h5>Semantics:</h5> |
| 2391 | |
| 2392 | <p>The following table shows the semantics of '<tt>vsetfp</tt>' for |
| 2393 | floating point types. If either operand is a floating point Not a |
| 2394 | Number (NaN) value, the operation is unordered, and the value in the |
| 2395 | first column below is produced at that position. Otherwise, the |
| 2396 | operation is ordered, and the value in the second column is |
| 2397 | produced.</p> |
| 2398 | |
| 2399 | <table border="1" cellspacing="0" cellpadding="4"> |
| 2400 | <tbody> |
| 2401 | <tr><th>Operation</th><th>If unordered<th>Otherwise true iff</th></tr> |
| 2402 | <tr><td><tt>eq</tt></td><td>undefined</td><td>var1 == var2</td></tr> |
| 2403 | <tr><td><tt>ne</tt></td><td>undefined</td><td>var1 != var2</td></tr> |
| 2404 | <tr><td><tt>lt</tt></td><td>undefined</td><td>var1 < var2</td></tr> |
| 2405 | <tr><td><tt>gt</tt></td><td>undefined</td><td>var1 > var2</td></tr> |
| 2406 | <tr><td><tt>le</tt></td><td>undefined</td><td>var1 <= var2</td></tr> |
| 2407 | <tr><td><tt>ge</tt></td><td>undefined</td><td>var1 >= var2</td></tr> |
| 2408 | <tr><td><tt>oeq</tt></td><td>false</td><td>var1 == var2</td></tr> |
| 2409 | <tr><td><tt>one</tt></td><td>false</td><td>var1 != var2</td></tr> |
| 2410 | <tr><td><tt>olt</tt></td><td>false</td><td>var1 < var2</td></tr> |
| 2411 | <tr><td><tt>ogt</tt></td><td>false</td><td>var1 > var2</td></tr> |
| 2412 | <tr><td><tt>ole</tt></td><td>false</td><td>var1 <= var2</td></tr> |
| 2413 | <tr><td><tt>oge</tt></td><td>false</td><td>var1 >= var2</td></tr> |
| 2414 | <tr><td><tt>ueq</tt></td><td>true</td><td>var1 == var2</td></tr> |
| 2415 | <tr><td><tt>une</tt></td><td>true</td><td>var1 != var2</td></tr> |
| 2416 | <tr><td><tt>ult</tt></td><td>true</td><td>var1 < var2</td></tr> |
| 2417 | <tr><td><tt>ugt</tt></td><td>true</td><td>var1 > var2</td></tr> |
| 2418 | <tr><td><tt>ule</tt></td><td>true</td><td>var1 <= var2</td></tr> |
| 2419 | <tr><td><tt>uge</tt></td><td>true</td><td>var1 >= var2</td></tr> |
| 2420 | <tr><td><tt>o</tt></td><td>false</td><td>always</td></tr> |
| 2421 | <tr><td><tt>u</tt></td><td>true</td><td>never</td></tr> |
| 2422 | <tr><td><tt>true</tt></td><td>true</td><td>always</td></tr> |
| 2423 | <tr><td><tt>false</tt></td><td>false</td><td>never</td></tr> |
| 2424 | </tbody> |
| 2425 | </table> |
| 2426 | |
| 2427 | <h5>Example:</h5> |
| 2428 | <pre> <result> = vsetfp eq <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = false, false</i> |
| 2429 | <result> = vsetfp ne <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = true, true</i> |
| 2430 | <result> = vsetfp lt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = true, false</i> |
| 2431 | <result> = vsetfp gt <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = false, true</i> |
| 2432 | <result> = vsetfp le <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = true, false</i> |
| 2433 | <result> = vsetfp ge <2 x float> <float 0.0, float 1.0>, <float 1.0, float 0.0> <i>; yields {<2 x bool>}:result = false, true</i> |
| 2434 | </pre> |
| 2435 | </div> |
| 2436 | |
| 2437 | <!-- _______________________________________________________________________ --> |
| 2438 | <div class="doc_subsubsection"> |
| 2439 | <a name="i_vselect">'<tt>vselect</tt>' Instruction</a> |
| 2440 | </div> |
| 2441 | |
| 2442 | <div class="doc_text"> |
| 2443 | |
| 2444 | <h5>Syntax:</h5> |
| 2445 | |
| 2446 | <pre> |
| 2447 | <result> = vselect <n x bool> <cond>, <n x <ty>> <val1>, <n x <ty>> <val2> <i>; yields <n x <ty>></i> |
| 2448 | </pre> |
| 2449 | |
| 2450 | <h5>Overview:</h5> |
| 2451 | |
| 2452 | <p> |
| 2453 | The '<tt>vselect</tt>' instruction chooses one value at each position |
| 2454 | of a vector based on a condition. |
| 2455 | </p> |
| 2456 | |
| 2457 | |
| 2458 | <h5>Arguments:</h5> |
| 2459 | |
| 2460 | <p> |
| 2461 | The '<tt>vselect</tt>' instruction requires a <a |
| 2462 | href="#t_packed">packed</a> <tt>bool</tt> value indicating the |
| 2463 | condition at each vector position, and two values of the same packed |
| 2464 | type. All three operands must have the same length. The type of the |
| 2465 | result is the same as the type of the two value operands.</p> |
| 2466 | |
| 2467 | <h5>Semantics:</h5> |
| 2468 | |
| 2469 | <p> |
| 2470 | At each position where the <tt>bool</tt> vector is true, that position |
| 2471 | of the result gets its value from the first value argument; otherwise, |
| 2472 | it gets its value from the second value argument. |
| 2473 | </p> |
| 2474 | |
| 2475 | <h5>Example:</h5> |
| 2476 | |
| 2477 | <pre> |
| 2478 | %X = vselect bool <2 x bool> <bool true, bool false>, <2 x ubyte> <ubyte 17, ubyte 17>, |
| 2479 | <2 x ubyte> <ubyte 42, ubyte 42> <i>; yields <2 x ubyte>:17, 42</i> |
| 2480 | </pre> |
| 2481 | </div> |
| 2482 | |
| 2483 | |
| 2484 | |
Chris Lattner | 3df241e | 2006-04-08 23:07:04 +0000 | [diff] [blame] | 2485 | <!-- ======================================================================= --> |
| 2486 | <div class="doc_subsection"> |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 2487 | <a name="memoryops">Memory Access and Addressing Operations</a> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2488 | </div> |
| 2489 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2490 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2491 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2492 | <p>A key design point of an SSA-based representation is how it |
| 2493 | represents memory. In LLVM, no memory locations are in SSA form, which |
| 2494 | makes things very simple. This section describes how to read, write, |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2495 | allocate, and free memory in LLVM.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2496 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2497 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2498 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2499 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2500 | <div class="doc_subsubsection"> |
| 2501 | <a name="i_malloc">'<tt>malloc</tt>' Instruction</a> |
| 2502 | </div> |
| 2503 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2504 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2505 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2506 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2507 | |
| 2508 | <pre> |
| 2509 | <result> = malloc <type>[, uint <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2510 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2511 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2512 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2513 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2514 | <p>The '<tt>malloc</tt>' instruction allocates memory from the system |
| 2515 | heap and returns a pointer to it.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2516 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2517 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2518 | |
| 2519 | <p>The '<tt>malloc</tt>' instruction allocates |
| 2520 | <tt>sizeof(<type>)*NumElements</tt> |
John Criswell | 6e4ca61 | 2004-02-24 16:13:56 +0000 | [diff] [blame] | 2521 | 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] | 2522 | appropriate type to the program. If "NumElements" is specified, it is the |
| 2523 | number of elements allocated. If an alignment is specified, the value result |
| 2524 | of the allocation is guaranteed to be aligned to at least that boundary. If |
| 2525 | not specified, or if zero, the target can choose to align the allocation on any |
| 2526 | convenient boundary.</p> |
| 2527 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2528 | <p>'<tt>type</tt>' must be a sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2529 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2530 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2531 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2532 | <p>Memory is allocated using the system "<tt>malloc</tt>" function, and |
| 2533 | a pointer is returned.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2534 | |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2535 | <h5>Example:</h5> |
| 2536 | |
| 2537 | <pre> |
| 2538 | %array = malloc [4 x ubyte ] <i>; yields {[%4 x ubyte]*}:array</i> |
| 2539 | |
| 2540 | %size = <a href="#i_add">add</a> uint 2, 2 <i>; yields {uint}:size = uint 4</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2541 | %array1 = malloc ubyte, uint 4 <i>; yields {ubyte*}:array1</i> |
| 2542 | %array2 = malloc [12 x ubyte], uint %size <i>; yields {[12 x ubyte]*}:array2</i> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2543 | %array3 = malloc int, uint 4, align 1024 <i>; yields {int*}:array3</i> |
| 2544 | %array4 = malloc int, align 1024 <i>; yields {int*}:array4</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2545 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2546 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2547 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2548 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2549 | <div class="doc_subsubsection"> |
| 2550 | <a name="i_free">'<tt>free</tt>' Instruction</a> |
| 2551 | </div> |
| 2552 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2553 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2554 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2555 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2556 | |
| 2557 | <pre> |
| 2558 | free <type> <value> <i>; yields {void}</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2559 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2560 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2561 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2562 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2563 | <p>The '<tt>free</tt>' instruction returns memory back to the unused |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2564 | memory heap to be reallocated in the future.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2565 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2566 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2567 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2568 | <p>'<tt>value</tt>' shall be a pointer value that points to a value |
| 2569 | that was allocated with the '<tt><a href="#i_malloc">malloc</a></tt>' |
| 2570 | instruction.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2571 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2572 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2573 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2574 | <p>Access to the memory pointed to by the pointer is no longer defined |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2575 | after this instruction executes.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2576 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2577 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2578 | |
| 2579 | <pre> |
| 2580 | %array = <a href="#i_malloc">malloc</a> [4 x ubyte] <i>; yields {[4 x ubyte]*}:array</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2581 | free [4 x ubyte]* %array |
| 2582 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2583 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2584 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2585 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2586 | <div class="doc_subsubsection"> |
| 2587 | <a name="i_alloca">'<tt>alloca</tt>' Instruction</a> |
| 2588 | </div> |
| 2589 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2590 | <div class="doc_text"> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2591 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2592 | <h5>Syntax:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2593 | |
| 2594 | <pre> |
| 2595 | <result> = alloca <type>[, uint <NumElements>][, align <alignment>] <i>; yields {type*}:result</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2596 | </pre> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2597 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2598 | <h5>Overview:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2599 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2600 | <p>The '<tt>alloca</tt>' instruction allocates memory on the current |
| 2601 | stack frame of the procedure that is live until the current function |
| 2602 | returns to its caller.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2603 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2604 | <h5>Arguments:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2605 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 2606 | <p>The '<tt>alloca</tt>' instruction allocates <tt>sizeof(<type>)*NumElements</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2607 | bytes of memory on the runtime stack, returning a pointer of the |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2608 | appropriate type to the program. If "NumElements" is specified, it is the |
| 2609 | number of elements allocated. If an alignment is specified, the value result |
| 2610 | of the allocation is guaranteed to be aligned to at least that boundary. If |
| 2611 | not specified, or if zero, the target can choose to align the allocation on any |
| 2612 | convenient boundary.</p> |
| 2613 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2614 | <p>'<tt>type</tt>' may be any sized type.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2615 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2616 | <h5>Semantics:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2617 | |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2618 | <p>Memory is allocated; a pointer is returned. '<tt>alloca</tt>'d |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2619 | memory is automatically released when the function returns. The '<tt>alloca</tt>' |
| 2620 | instruction is commonly used to represent automatic variables that must |
| 2621 | 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] | 2622 | href="#i_ret">ret</a></tt> or <tt><a href="#i_unwind">unwind</a></tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2623 | instructions), the memory is reclaimed.</p> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2624 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2625 | <h5>Example:</h5> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2626 | |
| 2627 | <pre> |
| 2628 | %ptr = alloca int <i>; yields {int*}:ptr</i> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2629 | %ptr = alloca int, uint 4 <i>; yields {int*}:ptr</i> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2630 | %ptr = alloca int, uint 4, align 1024 <i>; yields {int*}:ptr</i> |
| 2631 | %ptr = alloca int, align 1024 <i>; yields {int*}:ptr</i> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2632 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2633 | </div> |
Chris Lattner | 2cbdc45 | 2005-11-06 08:02:57 +0000 | [diff] [blame] | 2634 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2635 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2636 | <div class="doc_subsubsection"> <a name="i_load">'<tt>load</tt>' |
| 2637 | Instruction</a> </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2638 | <div class="doc_text"> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2639 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2640 | <pre> <result> = load <ty>* <pointer><br> <result> = volatile load <ty>* <pointer><br></pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2641 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2642 | <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] | 2643 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2644 | <p>The argument to the '<tt>load</tt>' instruction specifies the memory |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 2645 | address from which to load. The pointer must point to a <a |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 2646 | 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] | 2647 | 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] | 2648 | the number or order of execution of this <tt>load</tt> with other |
| 2649 | volatile <tt>load</tt> and <tt><a href="#i_store">store</a></tt> |
| 2650 | instructions. </p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2651 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2652 | <p>The location of memory pointed to is loaded.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2653 | <h5>Examples:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2654 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 2655 | <a |
| 2656 | href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2657 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 2658 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2659 | </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2660 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2661 | <div class="doc_subsubsection"> <a name="i_store">'<tt>store</tt>' |
| 2662 | Instruction</a> </div> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2663 | <h5>Syntax:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2664 | <pre> store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | f065107 | 2003-09-08 18:27:49 +0000 | [diff] [blame] | 2665 | volatile store <ty> <value>, <ty>* <pointer> <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2666 | </pre> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2667 | <h5>Overview:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2668 | <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] | 2669 | <h5>Arguments:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2670 | <p>There are two arguments to the '<tt>store</tt>' instruction: a value |
John Criswell | 0ec250c | 2005-10-24 16:17:18 +0000 | [diff] [blame] | 2671 | to store and an address in which to store it. The type of the '<tt><pointer></tt>' |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2672 | operand must be a pointer to the type of the '<tt><value></tt>' |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2673 | 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] | 2674 | optimizer is not allowed to modify the number or order of execution of |
| 2675 | this <tt>store</tt> with other volatile <tt>load</tt> and <tt><a |
| 2676 | href="#i_store">store</a></tt> instructions.</p> |
| 2677 | <h5>Semantics:</h5> |
| 2678 | <p>The contents of memory are updated to contain '<tt><value></tt>' |
| 2679 | at the location specified by the '<tt><pointer></tt>' operand.</p> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2680 | <h5>Example:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2681 | <pre> %ptr = <a href="#i_alloca">alloca</a> int <i>; yields {int*}:ptr</i> |
| 2682 | <a |
| 2683 | href="#i_store">store</a> int 3, int* %ptr <i>; yields {void}</i> |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2684 | %val = load int* %ptr <i>; yields {int}:val = int 3</i> |
| 2685 | </pre> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame^] | 2686 | </div> |
| 2687 | |
Chris Lattner | 2b7d320 | 2002-05-06 03:03:22 +0000 | [diff] [blame] | 2688 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2689 | <div class="doc_subsubsection"> |
| 2690 | <a name="i_getelementptr">'<tt>getelementptr</tt>' Instruction</a> |
| 2691 | </div> |
| 2692 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2693 | <div class="doc_text"> |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2694 | <h5>Syntax:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2695 | <pre> |
| 2696 | <result> = getelementptr <ty>* <ptrval>{, <ty> <idx>}* |
| 2697 | </pre> |
| 2698 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2699 | <h5>Overview:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2700 | |
| 2701 | <p> |
| 2702 | The '<tt>getelementptr</tt>' instruction is used to get the address of a |
| 2703 | subelement of an aggregate data structure.</p> |
| 2704 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2705 | <h5>Arguments:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2706 | |
| 2707 | <p>This instruction takes a list of integer constants that indicate what |
| 2708 | elements of the aggregate object to index to. The actual types of the arguments |
| 2709 | provided depend on the type of the first pointer argument. The |
| 2710 | '<tt>getelementptr</tt>' instruction is used to index down through the type |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 2711 | levels of a structure or to a specific index in an array. When indexing into a |
| 2712 | structure, only <tt>uint</tt> |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2713 | integer constants are allowed. When indexing into an array or pointer, |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2714 | <tt>int</tt> and <tt>long</tt> indexes are allowed of any sign.</p> |
| 2715 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2716 | <p>For example, let's consider a C code fragment and how it gets |
| 2717 | compiled to LLVM:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2718 | |
| 2719 | <pre> |
| 2720 | struct RT { |
| 2721 | char A; |
| 2722 | int B[10][20]; |
| 2723 | char C; |
| 2724 | }; |
| 2725 | struct ST { |
| 2726 | int X; |
| 2727 | double Y; |
| 2728 | struct RT Z; |
| 2729 | }; |
| 2730 | |
| 2731 | int *foo(struct ST *s) { |
| 2732 | return &s[1].Z.B[5][13]; |
| 2733 | } |
| 2734 | </pre> |
| 2735 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2736 | <p>The LLVM code generated by the GCC frontend is:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2737 | |
| 2738 | <pre> |
| 2739 | %RT = type { sbyte, [10 x [20 x int]], sbyte } |
| 2740 | %ST = type { int, double, %RT } |
| 2741 | |
Brian Gaeke | 7283e7c | 2004-07-02 21:08:14 +0000 | [diff] [blame] | 2742 | implementation |
| 2743 | |
| 2744 | int* %foo(%ST* %s) { |
| 2745 | entry: |
| 2746 | %reg = getelementptr %ST* %s, int 1, uint 2, uint 1, int 5, int 13 |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2747 | ret int* %reg |
| 2748 | } |
| 2749 | </pre> |
| 2750 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2751 | <h5>Semantics:</h5> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2752 | |
| 2753 | <p>The index types specified for the '<tt>getelementptr</tt>' instruction depend |
John Criswell | c1f786c | 2005-05-13 22:25:59 +0000 | [diff] [blame] | 2754 | on the pointer type that is being indexed into. <a href="#t_pointer">Pointer</a> |
Chris Lattner | e53e508 | 2004-06-03 22:57:15 +0000 | [diff] [blame] | 2755 | and <a href="#t_array">array</a> types require <tt>uint</tt>, <tt>int</tt>, |
| 2756 | <tt>ulong</tt>, or <tt>long</tt> values, and <a href="#t_struct">structure</a> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2757 | types require <tt>uint</tt> <b>constants</b>.</p> |
| 2758 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2759 | <p>In the example above, the first index is indexing into the '<tt>%ST*</tt>' |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2760 | type, which is a pointer, yielding a '<tt>%ST</tt>' = '<tt>{ int, double, %RT |
| 2761 | }</tt>' type, a structure. The second index indexes into the third element of |
| 2762 | the structure, yielding a '<tt>%RT</tt>' = '<tt>{ sbyte, [10 x [20 x int]], |
| 2763 | sbyte }</tt>' type, another structure. The third index indexes into the second |
| 2764 | element of the structure, yielding a '<tt>[10 x [20 x int]]</tt>' type, an |
| 2765 | array. The two dimensions of the array are subscripted into, yielding an |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 2766 | '<tt>int</tt>' type. The '<tt>getelementptr</tt>' instruction returns a pointer |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2767 | to this element, thus computing a value of '<tt>int*</tt>' type.</p> |
| 2768 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 2769 | <p>Note that it is perfectly legal to index partially through a |
| 2770 | structure, returning a pointer to an inner element. Because of this, |
| 2771 | the LLVM code for the given testcase is equivalent to:</p> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2772 | |
| 2773 | <pre> |
Chris Lattner | d4f6b17 | 2005-03-07 22:13:59 +0000 | [diff] [blame] | 2774 | int* %foo(%ST* %s) { |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2775 | %t1 = getelementptr %ST* %s, int 1 <i>; yields %ST*:%t1</i> |
| 2776 | %t2 = getelementptr %ST* %t1, int 0, uint 2 <i>; yields %RT*:%t2</i> |
| 2777 | %t3 = getelementptr %RT* %t2, int 0, uint 1 <i>; yields [10 x [20 x int]]*:%t3</i> |
| 2778 | %t4 = getelementptr [10 x [20 x int]]* %t3, int 0, int 5 <i>; yields [20 x int]*:%t4</i> |
| 2779 | %t5 = getelementptr [20 x int]* %t4, int 0, int 13 <i>; yields int*:%t5</i> |
| 2780 | ret int* %t5 |
| 2781 | } |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2782 | </pre> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 2783 | |
| 2784 | <p>Note that it is undefined to access an array out of bounds: array and |
| 2785 | pointer indexes must always be within the defined bounds of the array type. |
| 2786 | The one exception for this rules is zero length arrays. These arrays are |
| 2787 | defined to be accessible as variable length arrays, which requires access |
| 2788 | beyond the zero'th element.</p> |
| 2789 | |
Chris Lattner | 884a970 | 2006-08-15 00:45:58 +0000 | [diff] [blame] | 2790 | <p>The getelementptr instruction is often confusing. For some more insight |
| 2791 | into how it works, see <a href="GetElementPtr.html">the getelementptr |
| 2792 | FAQ</a>.</p> |
| 2793 | |
Chris Lattner | 7faa883 | 2002-04-14 06:13:44 +0000 | [diff] [blame] | 2794 | <h5>Example:</h5> |
Chris Lattner | e67a951 | 2005-06-24 17:22:57 +0000 | [diff] [blame] | 2795 | |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2796 | <pre> |
| 2797 | <i>; yields [12 x ubyte]*:aptr</i> |
| 2798 | %aptr = getelementptr {int, [12 x ubyte]}* %sptr, long 0, uint 1 |
| 2799 | </pre> |
Chris Lattner | f74d5c7 | 2004-04-05 01:30:49 +0000 | [diff] [blame] | 2800 | </div> |
Reid Spencer | 47ce179 | 2006-11-09 21:15:49 +0000 | [diff] [blame^] | 2801 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 2802 | <!-- ======================================================================= --> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 2803 | <div class="doc_subsection"> <a name="convertops">Conversion Operations</a> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2804 | </div> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2805 | <div class="doc_text"> |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 2806 | <p>The instructions in this category are the conversion instructions (casting) |
| 2807 | which all take a single operand and a type. They perform various bit conversions |
| 2808 | on the operand.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2809 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2810 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2811 | <!-- _______________________________________________________________________ --> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2812 | <div class="doc_subsubsection"> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2813 | <a name="i_trunc">'<tt>trunc .. to</tt>' Instruction</a> |
| 2814 | </div> |
| 2815 | <div class="doc_text"> |
| 2816 | |
| 2817 | <h5>Syntax:</h5> |
| 2818 | <pre> |
| 2819 | <result> = trunc <ty> <value> to <ty2> <i>; yields ty2</i> |
| 2820 | </pre> |
| 2821 | |
| 2822 | <h5>Overview:</h5> |
| 2823 | <p> |
| 2824 | The '<tt>trunc</tt>' instruction truncates its operand to the type <tt>ty2</tt>. |
| 2825 | </p> |
| 2826 | |
| 2827 | <h5>Arguments:</h5> |
| 2828 | <p> |
| 2829 | The '<tt>trunc</tt>' instruction takes a <tt>value</tt> to trunc, which must |
| 2830 | be an <a href="#t_integer">integer</a> type, and a type that specifies the size |
| 2831 | and type of the result, which must be an <a href="#t_integral">integral</a> |
| 2832 | type.</p> |
| 2833 | |
| 2834 | <h5>Semantics:</h5> |
| 2835 | <p> |
| 2836 | The '<tt>trunc</tt>' instruction truncates the high order bits in <tt>value</tt> |
| 2837 | and converts the reamining bits to <tt>ty2</tt>. The bit size of <tt>value</tt> |
| 2838 | must be larger than the bit size of <tt>ty2</tt>. Equal sized types are not |
| 2839 | allowed. This implies that a <tt>trunc</tt> cannot be a <i>no-op cast</i>. It |
| 2840 | will always truncate bits.</p> |
| 2841 | |
| 2842 | <p>When truncating to bool, the truncation is done as a comparison against |
| 2843 | zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>. |
| 2844 | If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p> |
| 2845 | |
| 2846 | <h5>Example:</h5> |
| 2847 | <pre> |
| 2848 | %X = trunc int 257 to ubyte <i>; yields ubyte:1</i> |
| 2849 | %Y = trunc int 123 to bool <i>; yields bool:true</i> |
| 2850 | </pre> |
| 2851 | </div> |
| 2852 | |
| 2853 | <!-- _______________________________________________________________________ --> |
| 2854 | <div class="doc_subsubsection"> |
| 2855 | <a name="i_zext">'<tt>zext .. to</tt>' Instruction</a> |
| 2856 | </div> |
| 2857 | <div class="doc_text"> |
| 2858 | |
| 2859 | <h5>Syntax:</h5> |
| 2860 | <pre> |
| 2861 | <result> = zext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 2862 | </pre> |
| 2863 | |
| 2864 | <h5>Overview:</h5> |
| 2865 | <p>The '<tt>zext</tt>' instruction zero extends its operand to type |
| 2866 | <tt>ty2</tt>.</p> |
| 2867 | |
| 2868 | |
| 2869 | <h5>Arguments:</h5> |
| 2870 | <p>The '<tt>zext</tt>' instruction takes a value to cast, which must be of |
| 2871 | <a href="#t_integral">integral</a> type, and a type to cast it to, which must |
| 2872 | also be of <a href="#t_integral">integral</a> type. The bit size of the |
| 2873 | <tt>value</tt> must be smaller than or equal to the bit size of the |
| 2874 | destination type, <tt>ty2</tt>.</p> |
| 2875 | |
| 2876 | <h5>Semantics:</h5> |
| 2877 | <p>The <tt>zext</tt> fills the high order bits of the <tt>value</tt> with zero |
| 2878 | bits until it reaches the size of the destination type, <tt>ty2</tt>. When the |
| 2879 | the operand and the type are the same size, no bit filling is done and the |
| 2880 | cast is considered a <i>no-op cast</i> because no bits change (only the type |
| 2881 | changes).</p> |
| 2882 | |
| 2883 | <p>When zero extending to bool, the extension is done as a comparison against |
| 2884 | zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>. |
| 2885 | If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p> |
| 2886 | |
| 2887 | <h5>Example:</h5> |
| 2888 | <pre> |
| 2889 | %X = zext int 257 to ulong <i>; yields ulong:257</i> |
| 2890 | %Y = zext bool true to int <i>; yields int:1</i> |
| 2891 | </pre> |
| 2892 | </div> |
| 2893 | |
| 2894 | <!-- _______________________________________________________________________ --> |
| 2895 | <div class="doc_subsubsection"> |
| 2896 | <a name="i_sext">'<tt>sext .. to</tt>' Instruction</a> |
| 2897 | </div> |
| 2898 | <div class="doc_text"> |
| 2899 | |
| 2900 | <h5>Syntax:</h5> |
| 2901 | <pre> |
| 2902 | <result> = sext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 2903 | </pre> |
| 2904 | |
| 2905 | <h5>Overview:</h5> |
| 2906 | <p>The '<tt>sext</tt>' sign extends <tt>value</tt> to the type <tt>ty2</tt>.</p> |
| 2907 | |
| 2908 | <h5>Arguments:</h5> |
| 2909 | <p> |
| 2910 | The '<tt>sext</tt>' instruction takes a value to cast, which must be of |
| 2911 | <a href="#t_integral">integral</a> type, and a type to cast it to, which must |
| 2912 | also be of <a href="#t_integral">integral</a> type.</p> |
| 2913 | |
| 2914 | <h5>Semantics:</h5> |
| 2915 | <p> |
| 2916 | The '<tt>sext</tt>' instruction performs a sign extension by copying the sign |
| 2917 | bit (highest order bit) of the <tt>value</tt> until it reaches the bit size of |
| 2918 | the type <tt>ty2</tt>. When the the operand and the type are the same size, |
| 2919 | no bit filling is done and the cast is considered a <i>no-op cast</i> because |
| 2920 | no bits change (only the type changes).</p> |
| 2921 | |
| 2922 | <p>When sign extending to bool, the extension is done as a comparison against |
| 2923 | zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>. |
| 2924 | If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p> |
| 2925 | |
| 2926 | <h5>Example:</h5> |
| 2927 | |
| 2928 | <pre> |
| 2929 | %X = sext sbyte -1 to ushort <i>; yields ushort:65535</i> |
| 2930 | %Y = sext bool true to int <i>; yields int:-1</i> |
| 2931 | </pre> |
| 2932 | </div> |
| 2933 | |
| 2934 | <!-- _______________________________________________________________________ --> |
| 2935 | <div class="doc_subsubsection"> |
| 2936 | <a name="i_fpext">'<tt>fpext .. to</tt>' Instruction</a> |
| 2937 | </div> |
| 2938 | <div class="doc_text"> |
| 2939 | |
| 2940 | <h5>Syntax:</h5> |
| 2941 | <pre> |
| 2942 | <result> = fpext <ty> <value> to <ty2> <i>; yields ty2</i> |
| 2943 | </pre> |
| 2944 | |
| 2945 | <h5>Overview:</h5> |
| 2946 | <p>The '<tt>fpext</tt>' extends a floating point <tt>value</tt> to a larger |
| 2947 | floating point value.</p> |
| 2948 | |
| 2949 | <h5>Arguments:</h5> |
| 2950 | <p>The '<tt>fpext</tt>' instruction takes a |
| 2951 | <a href="#t_floating">floating point</a> <tt>value</tt> to cast, |
| 2952 | and a <a href="#t_floating">floating point</a> type to cast it to.</p> |
| 2953 | |
| 2954 | <h5>Semantics:</h5> |
| 2955 | <p>The '<tt>fpext</tt>' instruction extends the <tt>value</tt> from one floating |
| 2956 | point type to another. If the type of the <tt>value</tt> and <tt>ty2</tt> are |
| 2957 | the same, the instruction is considered a <i>no-op cast</i> because no bits |
| 2958 | change.</p> |
| 2959 | |
| 2960 | <h5>Example:</h5> |
| 2961 | <pre> |
| 2962 | %X = fpext float 3.1415 to double <i>; yields double:3.1415</i> |
| 2963 | %Y = fpext float 1.0 to float <i>; yields float:1.0 (no-op)</i> |
| 2964 | </pre> |
| 2965 | </div> |
| 2966 | |
| 2967 | <!-- _______________________________________________________________________ --> |
| 2968 | <div class="doc_subsubsection"> |
| 2969 | <a name="i_fptrunc">'<tt>fptrunc .. to</tt>' Instruction</a> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2970 | </div> |
| 2971 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 2972 | <div class="doc_text"> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2973 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2974 | <h5>Syntax:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2975 | |
| 2976 | <pre> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2977 | <result> = fptrunc <ty> <value> to <ty2> <i>; yields ty2</i> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2978 | </pre> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2979 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 2980 | <h5>Overview:</h5> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2981 | <p>The '<tt>fptrunc</tt>' instruction truncates <tt>value</tt> to type |
| 2982 | <tt>ty2</tt>.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 2983 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 2984 | |
| 2985 | <h5>Arguments:</h5> |
| 2986 | <p>The '<tt>fptrunc</tt>' instruction takes a <a href="#t_floating">floating |
| 2987 | point</a> value to cast and a <a href="#t_floating">floating point</a> type to |
| 2988 | cast it to. The size of <tt>value</tt> must be larger than the size of |
| 2989 | <tt>ty2</a>. This implies that <tt>fptrunc</tt> cannot be used to make a |
| 2990 | <i>no-op cast</i>.</p> |
| 2991 | |
| 2992 | <h5>Semantics:</h5> |
| 2993 | <p> The '<tt>fptrunc</tt>' instruction converts a |
| 2994 | <a href="#t_floating">floating point</a> value from a larger type to a smaller |
| 2995 | type. If the value cannot fit within the destination type, <tt>ty2</tt>, then |
| 2996 | the results are undefined.</p> |
| 2997 | |
| 2998 | <h5>Example:</h5> |
| 2999 | <pre> |
| 3000 | %X = fptrunc double 123.0 to float <i>; yields float:123.0</i> |
| 3001 | %Y = fptrunc double 1.0E+300 to float <i>; yields undefined</i> |
| 3002 | </pre> |
| 3003 | </div> |
| 3004 | |
| 3005 | <!-- _______________________________________________________________________ --> |
| 3006 | <div class="doc_subsubsection"> |
| 3007 | <a name="i_fp2uint">'<tt>fp2uint .. to</tt>' Instruction</a> |
| 3008 | </div> |
| 3009 | <div class="doc_text"> |
| 3010 | |
| 3011 | <h5>Syntax:</h5> |
| 3012 | <pre> |
| 3013 | <result> = fp2uint <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3014 | </pre> |
| 3015 | |
| 3016 | <h5>Overview:</h5> |
| 3017 | <p>The '<tt>fp2uint</tt>' converts a floating point <tt>value</tt> to its |
| 3018 | unsigned integer equivalent of type <tt>ty2</tt>. |
| 3019 | </p> |
| 3020 | |
| 3021 | <h5>Arguments:</h5> |
| 3022 | <p>The '<tt>fp2uint</tt>' instruction takes a value to cast, which must be a |
| 3023 | <a href="#t_floating">floating point</a> value, and a type to cast it to, which |
| 3024 | must be an <a href="#t_integral">integral</a> type.</p> |
| 3025 | |
| 3026 | <h5>Semantics:</h5> |
| 3027 | <p> The '<tt>fp2uint</tt>' instruction converts its |
| 3028 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 3029 | towards zero) unsigned integer value. If the value cannot fit in <tt>ty2</tt>, |
| 3030 | the results are undefined.</p> |
| 3031 | |
| 3032 | <p>When converting to bool, the conversion is done as a comparison against |
| 3033 | zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>. |
| 3034 | If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p> |
| 3035 | |
| 3036 | <h5>Example:</h5> |
| 3037 | <pre> |
| 3038 | %X = fp2uint double 123.0 to int <i>; yields int:123</i> |
| 3039 | %Y = fp2uint float 1.0E+300 to bool <i>; yields bool:true</i> |
| 3040 | %X = fp2uint float 1.04E+17 to ubyte <i>; yields undefined:1</i> |
| 3041 | </pre> |
| 3042 | </div> |
| 3043 | |
| 3044 | <!-- _______________________________________________________________________ --> |
| 3045 | <div class="doc_subsubsection"> |
| 3046 | <a name="i_fp2sint">'<tt>fp2sint .. to</tt>' Instruction</a> |
| 3047 | </div> |
| 3048 | <div class="doc_text"> |
| 3049 | |
| 3050 | <h5>Syntax:</h5> |
| 3051 | <pre> |
| 3052 | <result> = fp2sint <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3053 | </pre> |
| 3054 | |
| 3055 | <h5>Overview:</h5> |
| 3056 | <p>The '<tt>fp2sint</tt>' instruction converts |
| 3057 | <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] | 3058 | </p> |
| 3059 | |
| 3060 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3061 | <h5>Arguments:</h5> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3062 | <p> The '<tt>fp2sint</tt>' instruction takes a value to cast, which must be a |
| 3063 | <a href="#t_floating">floating point</a> value, and a type to cast it to, which |
| 3064 | must also be an <a href="#t_integral">integral</a> type.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3065 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3066 | <h5>Semantics:</h5> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3067 | <p>The '<tt>fp2sint</tt>' instruction converts its |
| 3068 | <a href="#t_floating">floating point</a> operand into the nearest (rounding |
| 3069 | towards zero) signed integer value. If the value cannot fit in <tt>ty2</tt>, |
| 3070 | the results are undefined.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3071 | |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3072 | <p>When converting to bool, the conversion is done as a comparison against |
| 3073 | zero. If the <tt>value</tt> was zero, the bool result will be <tt>false</tt>. |
| 3074 | If the <tt>value</tt> was non-zero, the bool result will be <tt>true</tt>.</p> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3075 | |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3076 | <h5>Example:</h5> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3077 | <pre> |
Reid Spencer | 9dee3ac | 2006-11-08 01:11:31 +0000 | [diff] [blame] | 3078 | %X = fp2sint double -123.0 to int <i>; yields int:-123</i> |
| 3079 | %Y = fp2sint float 1.0E-247 to bool <i>; yields bool:true</i> |
| 3080 | %X = fp2sint float 1.04E+17 to sbyte <i>; yields undefined:1</i> |
| 3081 | </pre> |
| 3082 | </div> |
| 3083 | |
| 3084 | <!-- _______________________________________________________________________ --> |
| 3085 | <div class="doc_subsubsection"> |
| 3086 | <a name="i_uint2fp">'<tt>uint2fp .. to</tt>' Instruction</a> |
| 3087 | </div> |
| 3088 | <div class="doc_text"> |
| 3089 | |
| 3090 | <h5>Syntax:</h5> |
| 3091 | <pre> |
| 3092 | <result> = uint2fp <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3093 | </pre> |
| 3094 | |
| 3095 | <h5>Overview:</h5> |
| 3096 | <p>The '<tt>uint2fp</tt>' instruction regards <tt>value</tt> as an unsigned |
| 3097 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 3098 | |
| 3099 | |
| 3100 | <h5>Arguments:</h5> |
| 3101 | <p>The '<tt>uint2fp</tt>' instruction takes a value to cast, which must be an |
| 3102 | <a href="#t_integral">integral</a> value, and a type to cast it to, which must |
| 3103 | be a <a href="#t_floating">floating point</a> type.</p> |
| 3104 | |
| 3105 | <h5>Semantics:</h5> |
| 3106 | <p>The '<tt>uint2fp</tt>' instruction interprets its operand as an unsigned |
| 3107 | integer quantity and converts it to the corresponding floating point value. If |
| 3108 | the value cannot fit in the floating point value, the results are undefined.</p> |
| 3109 | |
| 3110 | |
| 3111 | <h5>Example:</h5> |
| 3112 | <pre> |
| 3113 | %X = uint2fp int 257 to float <i>; yields float:257.0</i> |
| 3114 | %Y = uint2fp sbyte -1 to double <i>; yields double:255.0</i> |
| 3115 | </pre> |
| 3116 | </div> |
| 3117 | |
| 3118 | <!-- _______________________________________________________________________ --> |
| 3119 | <div class="doc_subsubsection"> |
| 3120 | <a name="i_sint2fp">'<tt>sint2fp .. to</tt>' Instruction</a> |
| 3121 | </div> |
| 3122 | <div class="doc_text"> |
| 3123 | |
| 3124 | <h5>Syntax:</h5> |
| 3125 | <pre> |
| 3126 | <result> = sint2fp <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3127 | </pre> |
| 3128 | |
| 3129 | <h5>Overview:</h5> |
| 3130 | <p>The '<tt>sint2fp</tt>' instruction regards <tt>value</tt> as a signed |
| 3131 | integer and converts that value to the <tt>ty2</tt> type.</p> |
| 3132 | |
| 3133 | <h5>Arguments:</h5> |
| 3134 | <p>The '<tt>sint2fp</tt>' instruction takes a value to cast, which must be an |
| 3135 | <a href="#t_integral">integral</a> value, and a type to cast it to, which must be |
| 3136 | a <a href="#t_floating">floating point</a> type.</p> |
| 3137 | |
| 3138 | <h5>Semantics:</h5> |
| 3139 | <p>The '<tt>sint2fp</tt>' instruction interprets its operand as a signed |
| 3140 | integer quantity and converts it to the corresponding floating point value. If |
| 3141 | the value cannot fit in the floating point value, the results are undefined.</p> |
| 3142 | |
| 3143 | <h5>Example:</h5> |
| 3144 | <pre> |
| 3145 | %X = sint2fp int 257 to float <i>; yields float:257.0</i> |
| 3146 | %Y = sint2fp sbyte -1 to double <i>; yields double:-1.0</i> |
| 3147 | </pre> |
| 3148 | </div> |
| 3149 | |
| 3150 | <!-- _______________________________________________________________________ --> |
| 3151 | <div class="doc_subsubsection"> |
| 3152 | <a name="i_bitconvert">'<tt>bitconvert .. to</tt>' Instruction</a> |
| 3153 | </div> |
| 3154 | <div class="doc_text"> |
| 3155 | |
| 3156 | <h5>Syntax:</h5> |
| 3157 | <pre> |
| 3158 | <result> = bitconvert <ty> <value> to <ty2> <i>; yields ty2</i> |
| 3159 | </pre> |
| 3160 | |
| 3161 | <h5>Overview:</h5> |
| 3162 | <p>The '<tt>bitconvert</tt>' instruction converts <tt>value</tt> to type |
| 3163 | <tt>ty2</tt> without changing any bits.</p> |
| 3164 | |
| 3165 | <h5>Arguments:</h5> |
| 3166 | <p>The '<tt>bitconvert</tt>' instruction takes a value to cast, which must be |
| 3167 | a first class value, and a type to cast it to, which must also be a <a |
| 3168 | href="#t_firstclass">first class</a> type. The bit sizes of <tt>value</tt> |
| 3169 | and the destination type, <tt>ty2</tt>, must be identical.</p> |
| 3170 | |
| 3171 | <h5>Semantics:</h5> |
| 3172 | <p>The '<tt>bitconvert</tt>' instruction converts <tt>value</tt> to type |
| 3173 | <tt>ty2</tt> as if the value had been stored to memory and read back as type |
| 3174 | <tt>ty2</tt>. That is, no bits are changed during the conversion. The |
| 3175 | <tt>bitconvert</tt> instruction may be used to construct <i>no-op casts</i> that |
| 3176 | the <tt>zext, sext, and fpext</tt> instructions do not permit.</p> |
| 3177 | |
| 3178 | <h5>Example:</h5> |
| 3179 | <pre> |
| 3180 | %X = bitconvert ubyte 255 to sbyte <i>; yields sbyte:-1</i> |
| 3181 | %Y = bitconvert uint* %x to uint <i>; yields uint:%x</i> |
Chris Lattner | 33ba0d9 | 2001-07-09 00:26:23 +0000 | [diff] [blame] | 3182 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3183 | </div> |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3184 | |
Reid Spencer | 2fd21e6 | 2006-11-08 01:18:52 +0000 | [diff] [blame] | 3185 | <!-- ======================================================================= --> |
| 3186 | <div class="doc_subsection"> <a name="otherops">Other Operations</a> </div> |
| 3187 | <div class="doc_text"> |
| 3188 | <p>The instructions in this category are the "miscellaneous" |
| 3189 | instructions, which defy better classification.</p> |
| 3190 | </div> |
| 3191 | <!-- _______________________________________________________________________ --> |
| 3192 | <div class="doc_subsubsection"> <a name="i_phi">'<tt>phi</tt>' |
| 3193 | Instruction</a> </div> |
| 3194 | <div class="doc_text"> |
| 3195 | <h5>Syntax:</h5> |
| 3196 | <pre> <result> = phi <ty> [ <val0>, <label0>], ...<br></pre> |
| 3197 | <h5>Overview:</h5> |
| 3198 | <p>The '<tt>phi</tt>' instruction is used to implement the φ node in |
| 3199 | the SSA graph representing the function.</p> |
| 3200 | <h5>Arguments:</h5> |
| 3201 | <p>The type of the incoming values are specified with the first type |
| 3202 | field. After this, the '<tt>phi</tt>' instruction takes a list of pairs |
| 3203 | as arguments, with one pair for each predecessor basic block of the |
| 3204 | current block. Only values of <a href="#t_firstclass">first class</a> |
| 3205 | type may be used as the value arguments to the PHI node. Only labels |
| 3206 | may be used as the label arguments.</p> |
| 3207 | <p>There must be no non-phi instructions between the start of a basic |
| 3208 | block and the PHI instructions: i.e. PHI instructions must be first in |
| 3209 | a basic block.</p> |
| 3210 | <h5>Semantics:</h5> |
| 3211 | <p>At runtime, the '<tt>phi</tt>' instruction logically takes on the |
| 3212 | value specified by the parameter, depending on which basic block we |
| 3213 | came from in the last <a href="#terminators">terminator</a> instruction.</p> |
| 3214 | <h5>Example:</h5> |
| 3215 | <pre>Loop: ; Infinite loop that counts from 0 on up...<br> %indvar = phi uint [ 0, %LoopHeader ], [ %nextindvar, %Loop ]<br> %nextindvar = add uint %indvar, 1<br> br label %Loop<br></pre> |
| 3216 | </div> |
| 3217 | |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3218 | <!-- _______________________________________________________________________ --> |
| 3219 | <div class="doc_subsubsection"> |
| 3220 | <a name="i_select">'<tt>select</tt>' Instruction</a> |
| 3221 | </div> |
| 3222 | |
| 3223 | <div class="doc_text"> |
| 3224 | |
| 3225 | <h5>Syntax:</h5> |
| 3226 | |
| 3227 | <pre> |
| 3228 | <result> = select bool <cond>, <ty> <val1>, <ty> <val2> <i>; yields ty</i> |
| 3229 | </pre> |
| 3230 | |
| 3231 | <h5>Overview:</h5> |
| 3232 | |
| 3233 | <p> |
| 3234 | The '<tt>select</tt>' instruction is used to choose one value based on a |
| 3235 | condition, without branching. |
| 3236 | </p> |
| 3237 | |
| 3238 | |
| 3239 | <h5>Arguments:</h5> |
| 3240 | |
| 3241 | <p> |
| 3242 | 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. |
| 3243 | </p> |
| 3244 | |
| 3245 | <h5>Semantics:</h5> |
| 3246 | |
| 3247 | <p> |
| 3248 | If the boolean condition evaluates to true, the instruction returns the first |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3249 | value argument; otherwise, it returns the second value argument. |
Chris Lattner | cc37aae | 2004-03-12 05:50:16 +0000 | [diff] [blame] | 3250 | </p> |
| 3251 | |
| 3252 | <h5>Example:</h5> |
| 3253 | |
| 3254 | <pre> |
| 3255 | %X = select bool true, ubyte 17, ubyte 42 <i>; yields ubyte:17</i> |
| 3256 | </pre> |
| 3257 | </div> |
| 3258 | |
Robert Bocchino | 05ccd70 | 2006-01-15 20:48:27 +0000 | [diff] [blame] | 3259 | |
| 3260 | <!-- _______________________________________________________________________ --> |
| 3261 | <div class="doc_subsubsection"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3262 | <a name="i_call">'<tt>call</tt>' Instruction</a> |
| 3263 | </div> |
| 3264 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3265 | <div class="doc_text"> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3266 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3267 | <h5>Syntax:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3268 | <pre> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3269 | <result> = [tail] call [<a href="#callingconv">cconv</a>] <ty>* <fnptrval>(<param list>) |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3270 | </pre> |
| 3271 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3272 | <h5>Overview:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3273 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3274 | <p>The '<tt>call</tt>' instruction represents a simple function call.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3275 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3276 | <h5>Arguments:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3277 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3278 | <p>This instruction requires several arguments:</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3279 | |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3280 | <ol> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3281 | <li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3282 | <p>The optional "tail" marker indicates whether the callee function accesses |
| 3283 | 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] | 3284 | function call is eligible for tail call optimization. Note that calls may |
| 3285 | be marked "tail" even if they do not occur before a <a |
| 3286 | href="#i_ret"><tt>ret</tt></a> instruction. |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3287 | </li> |
| 3288 | <li> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3289 | <p>The optional "cconv" marker indicates which <a href="callingconv">calling |
| 3290 | convention</a> the call should use. If none is specified, the call defaults |
| 3291 | to using C calling conventions. |
| 3292 | </li> |
| 3293 | <li> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3294 | <p>'<tt>ty</tt>': shall be the signature of the pointer to function value |
| 3295 | being invoked. The argument types must match the types implied by this |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3296 | signature. This type can be omitted if the function is not varargs and |
| 3297 | 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] | 3298 | </li> |
| 3299 | <li> |
| 3300 | <p>'<tt>fnptrval</tt>': An LLVM value containing a pointer to a function to |
| 3301 | be invoked. In most cases, this is a direct function invocation, but |
| 3302 | 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] | 3303 | to function value.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3304 | </li> |
| 3305 | <li> |
| 3306 | <p>'<tt>function args</tt>': argument list whose types match the |
Reid Spencer | a7e302a | 2005-05-01 22:22:57 +0000 | [diff] [blame] | 3307 | function signature argument types. All arguments must be of |
| 3308 | <a href="#t_firstclass">first class</a> type. If the function signature |
| 3309 | indicates the function accepts a variable number of arguments, the extra |
| 3310 | arguments can be specified.</p> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3311 | </li> |
Chris Lattner | 6536cfe | 2002-05-06 22:08:29 +0000 | [diff] [blame] | 3312 | </ol> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3313 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3314 | <h5>Semantics:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3315 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3316 | <p>The '<tt>call</tt>' instruction is used to cause control flow to |
| 3317 | transfer to a specified function, with its incoming arguments bound to |
| 3318 | the specified values. Upon a '<tt><a href="#i_ret">ret</a></tt>' |
| 3319 | instruction in the called function, control flow continues with the |
| 3320 | instruction after the function call, and the return value of the |
| 3321 | function is bound to the result argument. This is a simpler case of |
| 3322 | the <a href="#i_invoke">invoke</a> instruction.</p> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3323 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 3324 | <h5>Example:</h5> |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3325 | |
| 3326 | <pre> |
| 3327 | %retval = call int %test(int %argc) |
| 3328 | call int(sbyte*, ...) *%printf(sbyte* %msg, int 12, sbyte 42); |
| 3329 | %X = tail call int %foo() |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 3330 | %Y = tail call <a href="#callingconv">fastcc</a> int %foo() |
Chris Lattner | 2bff524 | 2005-05-06 05:47:36 +0000 | [diff] [blame] | 3331 | </pre> |
| 3332 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3333 | </div> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3334 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3335 | <!-- _______________________________________________________________________ --> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3336 | <div class="doc_subsubsection"> |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 3337 | <a name="i_va_arg">'<tt>va_arg</tt>' Instruction</a> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3338 | </div> |
| 3339 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3340 | <div class="doc_text"> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3341 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3342 | <h5>Syntax:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3343 | |
| 3344 | <pre> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3345 | <resultval> = va_arg <va_list*> <arglist>, <argty> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3346 | </pre> |
| 3347 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3348 | <h5>Overview:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3349 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3350 | <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] | 3351 | the "variable argument" area of a function call. It is used to implement the |
| 3352 | <tt>va_arg</tt> macro in C.</p> |
| 3353 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3354 | <h5>Arguments:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3355 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3356 | <p>This instruction takes a <tt>va_list*</tt> value and the type of |
| 3357 | the argument. It returns a value of the specified argument type and |
Jeff Cohen | 25d4f7e | 2005-11-11 02:15:27 +0000 | [diff] [blame] | 3358 | increments the <tt>va_list</tt> to point to the next argument. Again, the |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3359 | actual type of <tt>va_list</tt> is target specific.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3360 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3361 | <h5>Semantics:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3362 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3363 | <p>The '<tt>va_arg</tt>' instruction loads an argument of the specified |
| 3364 | type from the specified <tt>va_list</tt> and causes the |
| 3365 | <tt>va_list</tt> to point to the next argument. For more information, |
| 3366 | see the variable argument handling <a href="#int_varargs">Intrinsic |
| 3367 | Functions</a>.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3368 | |
| 3369 | <p>It is legal for this instruction to be called in a function which does not |
| 3370 | take a variable number of arguments, for example, the <tt>vfprintf</tt> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3371 | function.</p> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3372 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3373 | <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] | 3374 | href="#intrinsics">intrinsic function</a> because it takes a type as an |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3375 | argument.</p> |
| 3376 | |
Chris Lattner | 8d1a81d | 2003-10-18 05:51:36 +0000 | [diff] [blame] | 3377 | <h5>Example:</h5> |
Chris Lattner | e19d7a7 | 2004-09-27 21:51:25 +0000 | [diff] [blame] | 3378 | |
| 3379 | <p>See the <a href="#int_varargs">variable argument processing</a> section.</p> |
| 3380 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3381 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3382 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3383 | <!-- *********************************************************************** --> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3384 | <div class="doc_section"> <a name="intrinsics">Intrinsic Functions</a> </div> |
| 3385 | <!-- *********************************************************************** --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3386 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3387 | <div class="doc_text"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3388 | |
| 3389 | <p>LLVM supports the notion of an "intrinsic function". These functions have |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3390 | well known names and semantics and are required to follow certain |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3391 | restrictions. Overall, these instructions represent an extension mechanism for |
| 3392 | the LLVM language that does not require changing all of the transformations in |
| 3393 | LLVM to add to the language (or the bytecode reader/writer, the parser, |
| 3394 | etc...).</p> |
| 3395 | |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3396 | <p>Intrinsic function names must all start with an "<tt>llvm.</tt>" prefix. This |
| 3397 | prefix is reserved in LLVM for intrinsic names; thus, functions may not be named |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3398 | this. Intrinsic functions must always be external functions: you cannot define |
| 3399 | the body of intrinsic functions. Intrinsic functions may only be used in call |
| 3400 | or invoke instructions: it is illegal to take the address of an intrinsic |
| 3401 | function. Additionally, because intrinsic functions are part of the LLVM |
| 3402 | language, it is required that they all be documented here if any are added.</p> |
| 3403 | |
| 3404 | |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3405 | <p>To learn how to add an intrinsic function, please see the <a |
Chris Lattner | 590cff3 | 2005-05-11 03:35:57 +0000 | [diff] [blame] | 3406 | href="ExtendingLLVM.html">Extending LLVM Guide</a>. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3407 | </p> |
| 3408 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3409 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3410 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3411 | <!-- ======================================================================= --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3412 | <div class="doc_subsection"> |
| 3413 | <a name="int_varargs">Variable Argument Handling Intrinsics</a> |
| 3414 | </div> |
| 3415 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3416 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3417 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3418 | <p>Variable argument support is defined in LLVM with the <a |
Chris Lattner | fb6977d | 2006-01-13 23:26:01 +0000 | [diff] [blame] | 3419 | 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] | 3420 | intrinsic functions. These functions are related to the similarly |
| 3421 | named macros defined in the <tt><stdarg.h></tt> header file.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3422 | |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3423 | <p>All of these functions operate on arguments that use a |
| 3424 | target-specific value type "<tt>va_list</tt>". The LLVM assembly |
| 3425 | language reference manual does not define what this type is, so all |
| 3426 | transformations should be prepared to handle intrinsics with any type |
| 3427 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3428 | |
Chris Lattner | 374ab30 | 2006-05-15 17:26:46 +0000 | [diff] [blame] | 3429 | <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] | 3430 | instruction and the variable argument handling intrinsic functions are |
| 3431 | used.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3432 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3433 | <pre> |
| 3434 | int %test(int %X, ...) { |
| 3435 | ; Initialize variable argument processing |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3436 | %ap = alloca sbyte* |
| 3437 | call void %<a href="#i_va_start">llvm.va_start</a>(sbyte** %ap) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3438 | |
| 3439 | ; Read a single integer argument |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3440 | %tmp = va_arg sbyte** %ap, int |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3441 | |
| 3442 | ; Demonstrate usage of llvm.va_copy and llvm.va_end |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3443 | %aq = alloca sbyte* |
Andrew Lenharth | d0a4c62 | 2005-06-22 20:38:11 +0000 | [diff] [blame] | 3444 | call void %<a href="#i_va_copy">llvm.va_copy</a>(sbyte** %aq, sbyte** %ap) |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3445 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %aq) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3446 | |
| 3447 | ; Stop processing of arguments. |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3448 | call void %<a href="#i_va_end">llvm.va_end</a>(sbyte** %ap) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3449 | ret int %tmp |
| 3450 | } |
| 3451 | </pre> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3452 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3453 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3454 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3455 | <div class="doc_subsubsection"> |
| 3456 | <a name="i_va_start">'<tt>llvm.va_start</tt>' Intrinsic</a> |
| 3457 | </div> |
| 3458 | |
| 3459 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3460 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3461 | <h5>Syntax:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3462 | <pre> declare void %llvm.va_start(<va_list>* <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3463 | <h5>Overview:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3464 | <P>The '<tt>llvm.va_start</tt>' intrinsic initializes |
| 3465 | <tt>*<arglist></tt> for subsequent use by <tt><a |
| 3466 | href="#i_va_arg">va_arg</a></tt>.</p> |
| 3467 | |
| 3468 | <h5>Arguments:</h5> |
| 3469 | |
| 3470 | <P>The argument is a pointer to a <tt>va_list</tt> element to initialize.</p> |
| 3471 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3472 | <h5>Semantics:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3473 | |
| 3474 | <P>The '<tt>llvm.va_start</tt>' intrinsic works just like the <tt>va_start</tt> |
| 3475 | macro available in C. In a target-dependent way, it initializes the |
| 3476 | <tt>va_list</tt> element the argument points to, so that the next call to |
| 3477 | <tt>va_arg</tt> will produce the first variable argument passed to the function. |
| 3478 | Unlike the C <tt>va_start</tt> macro, this intrinsic does not need to know the |
| 3479 | last argument of the function, the compiler can figure that out.</p> |
| 3480 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3481 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3482 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3483 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3484 | <div class="doc_subsubsection"> |
| 3485 | <a name="i_va_end">'<tt>llvm.va_end</tt>' Intrinsic</a> |
| 3486 | </div> |
| 3487 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3488 | <div class="doc_text"> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3489 | <h5>Syntax:</h5> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3490 | <pre> declare void %llvm.va_end(<va_list*> <arglist>)<br></pre> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3491 | <h5>Overview:</h5> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3492 | <p>The '<tt>llvm.va_end</tt>' intrinsic destroys <tt><arglist></tt> |
| 3493 | which has been initialized previously with <tt><a href="#i_va_start">llvm.va_start</a></tt> |
| 3494 | or <tt><a href="#i_va_copy">llvm.va_copy</a></tt>.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3495 | <h5>Arguments:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3496 | <p>The argument is a <tt>va_list</tt> to destroy.</p> |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3497 | <h5>Semantics:</h5> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3498 | <p>The '<tt>llvm.va_end</tt>' intrinsic works just like the <tt>va_end</tt> |
Chris Lattner | 261efe9 | 2003-11-25 01:02:51 +0000 | [diff] [blame] | 3499 | macro available in C. In a target-dependent way, it destroys the <tt>va_list</tt>. |
| 3500 | Calls to <a href="#i_va_start"><tt>llvm.va_start</tt></a> and <a |
| 3501 | href="#i_va_copy"><tt>llvm.va_copy</tt></a> must be matched exactly |
| 3502 | with calls to <tt>llvm.va_end</tt>.</p> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3503 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3504 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3505 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3506 | <div class="doc_subsubsection"> |
| 3507 | <a name="i_va_copy">'<tt>llvm.va_copy</tt>' Intrinsic</a> |
| 3508 | </div> |
| 3509 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3510 | <div class="doc_text"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3511 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3512 | <h5>Syntax:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3513 | |
| 3514 | <pre> |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3515 | declare void %llvm.va_copy(<va_list>* <destarglist>, |
Andrew Lenharth | d0a4c62 | 2005-06-22 20:38:11 +0000 | [diff] [blame] | 3516 | <va_list>* <srcarglist>) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3517 | </pre> |
| 3518 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3519 | <h5>Overview:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3520 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3521 | <p>The '<tt>llvm.va_copy</tt>' intrinsic copies the current argument position from |
| 3522 | the source argument list to the destination argument list.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3523 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3524 | <h5>Arguments:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3525 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3526 | <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] | 3527 | 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] | 3528 | |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3529 | |
Chris Lattner | d9ad5b3 | 2003-05-08 04:57:36 +0000 | [diff] [blame] | 3530 | <h5>Semantics:</h5> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3531 | |
Andrew Lenharth | 8bf607a | 2005-06-18 18:28:17 +0000 | [diff] [blame] | 3532 | <p>The '<tt>llvm.va_copy</tt>' intrinsic works just like the <tt>va_copy</tt> macro |
| 3533 | available in C. In a target-dependent way, it copies the source |
| 3534 | <tt>va_list</tt> element into the destination list. This intrinsic is necessary |
| 3535 | because the <tt><a href="i_va_begin">llvm.va_begin</a></tt> intrinsic may be |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3536 | arbitrarily complex and require memory allocation, for example.</p> |
| 3537 | |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 3538 | </div> |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 3539 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3540 | <!-- ======================================================================= --> |
| 3541 | <div class="doc_subsection"> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3542 | <a name="int_gc">Accurate Garbage Collection Intrinsics</a> |
| 3543 | </div> |
| 3544 | |
| 3545 | <div class="doc_text"> |
| 3546 | |
| 3547 | <p> |
| 3548 | LLVM support for <a href="GarbageCollection.html">Accurate Garbage |
| 3549 | Collection</a> requires the implementation and generation of these intrinsics. |
| 3550 | These intrinsics allow identification of <a href="#i_gcroot">GC roots on the |
| 3551 | stack</a>, as well as garbage collector implementations that require <a |
| 3552 | href="#i_gcread">read</a> and <a href="#i_gcwrite">write</a> barriers. |
| 3553 | Front-ends for type-safe garbage collected languages should generate these |
| 3554 | intrinsics to make use of the LLVM garbage collectors. For more details, see <a |
| 3555 | href="GarbageCollection.html">Accurate Garbage Collection with LLVM</a>. |
| 3556 | </p> |
| 3557 | </div> |
| 3558 | |
| 3559 | <!-- _______________________________________________________________________ --> |
| 3560 | <div class="doc_subsubsection"> |
| 3561 | <a name="i_gcroot">'<tt>llvm.gcroot</tt>' Intrinsic</a> |
| 3562 | </div> |
| 3563 | |
| 3564 | <div class="doc_text"> |
| 3565 | |
| 3566 | <h5>Syntax:</h5> |
| 3567 | |
| 3568 | <pre> |
Reid Spencer | a8d451e | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 3569 | declare void %llvm.gcroot(<ty>** %ptrloc, <ty2>* %metadata) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3570 | </pre> |
| 3571 | |
| 3572 | <h5>Overview:</h5> |
| 3573 | |
John Criswell | 9e2485c | 2004-12-10 15:51:16 +0000 | [diff] [blame] | 3574 | <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] | 3575 | the code generator, and allows some metadata to be associated with it.</p> |
| 3576 | |
| 3577 | <h5>Arguments:</h5> |
| 3578 | |
| 3579 | <p>The first argument specifies the address of a stack object that contains the |
| 3580 | root pointer. The second pointer (which must be either a constant or a global |
| 3581 | value address) contains the meta-data to be associated with the root.</p> |
| 3582 | |
| 3583 | <h5>Semantics:</h5> |
| 3584 | |
| 3585 | <p>At runtime, a call to this intrinsics stores a null pointer into the "ptrloc" |
| 3586 | location. At compile-time, the code generator generates information to allow |
| 3587 | the runtime to find the pointer at GC safe points. |
| 3588 | </p> |
| 3589 | |
| 3590 | </div> |
| 3591 | |
| 3592 | |
| 3593 | <!-- _______________________________________________________________________ --> |
| 3594 | <div class="doc_subsubsection"> |
| 3595 | <a name="i_gcread">'<tt>llvm.gcread</tt>' Intrinsic</a> |
| 3596 | </div> |
| 3597 | |
| 3598 | <div class="doc_text"> |
| 3599 | |
| 3600 | <h5>Syntax:</h5> |
| 3601 | |
| 3602 | <pre> |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 3603 | declare sbyte* %llvm.gcread(sbyte* %ObjPtr, sbyte** %Ptr) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3604 | </pre> |
| 3605 | |
| 3606 | <h5>Overview:</h5> |
| 3607 | |
| 3608 | <p>The '<tt>llvm.gcread</tt>' intrinsic identifies reads of references from heap |
| 3609 | locations, allowing garbage collector implementations that require read |
| 3610 | barriers.</p> |
| 3611 | |
| 3612 | <h5>Arguments:</h5> |
| 3613 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 3614 | <p>The second argument is the address to read from, which should be an address |
| 3615 | allocated from the garbage collector. The first object is a pointer to the |
| 3616 | start of the referenced object, if needed by the language runtime (otherwise |
| 3617 | null).</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3618 | |
| 3619 | <h5>Semantics:</h5> |
| 3620 | |
| 3621 | <p>The '<tt>llvm.gcread</tt>' intrinsic has the same semantics as a load |
| 3622 | instruction, but may be replaced with substantially more complex code by the |
| 3623 | garbage collector runtime, as needed.</p> |
| 3624 | |
| 3625 | </div> |
| 3626 | |
| 3627 | |
| 3628 | <!-- _______________________________________________________________________ --> |
| 3629 | <div class="doc_subsubsection"> |
| 3630 | <a name="i_gcwrite">'<tt>llvm.gcwrite</tt>' Intrinsic</a> |
| 3631 | </div> |
| 3632 | |
| 3633 | <div class="doc_text"> |
| 3634 | |
| 3635 | <h5>Syntax:</h5> |
| 3636 | |
| 3637 | <pre> |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 3638 | declare void %llvm.gcwrite(sbyte* %P1, sbyte* %Obj, sbyte** %P2) |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3639 | </pre> |
| 3640 | |
| 3641 | <h5>Overview:</h5> |
| 3642 | |
| 3643 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic identifies writes of references to heap |
| 3644 | locations, allowing garbage collector implementations that require write |
| 3645 | barriers (such as generational or reference counting collectors).</p> |
| 3646 | |
| 3647 | <h5>Arguments:</h5> |
| 3648 | |
Chris Lattner | 80626e9 | 2006-03-14 20:02:51 +0000 | [diff] [blame] | 3649 | <p>The first argument is the reference to store, the second is the start of the |
| 3650 | object to store it to, and the third is the address of the field of Obj to |
| 3651 | store to. If the runtime does not require a pointer to the object, Obj may be |
| 3652 | null.</p> |
Chris Lattner | d792391 | 2004-05-23 21:06:01 +0000 | [diff] [blame] | 3653 | |
| 3654 | <h5>Semantics:</h5> |
| 3655 | |
| 3656 | <p>The '<tt>llvm.gcwrite</tt>' intrinsic has the same semantics as a store |
| 3657 | instruction, but may be replaced with substantially more complex code by the |
| 3658 | garbage collector runtime, as needed.</p> |
| 3659 | |
| 3660 | </div> |
| 3661 | |
| 3662 | |
| 3663 | |
| 3664 | <!-- ======================================================================= --> |
| 3665 | <div class="doc_subsection"> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3666 | <a name="int_codegen">Code Generator Intrinsics</a> |
| 3667 | </div> |
| 3668 | |
| 3669 | <div class="doc_text"> |
| 3670 | <p> |
| 3671 | These intrinsics are provided by LLVM to expose special features that may only |
| 3672 | be implemented with code generator support. |
| 3673 | </p> |
| 3674 | |
| 3675 | </div> |
| 3676 | |
| 3677 | <!-- _______________________________________________________________________ --> |
| 3678 | <div class="doc_subsubsection"> |
| 3679 | <a name="i_returnaddress">'<tt>llvm.returnaddress</tt>' Intrinsic</a> |
| 3680 | </div> |
| 3681 | |
| 3682 | <div class="doc_text"> |
| 3683 | |
| 3684 | <h5>Syntax:</h5> |
| 3685 | <pre> |
Chris Lattner | fcf39d4 | 2006-01-13 01:20:27 +0000 | [diff] [blame] | 3686 | declare sbyte *%llvm.returnaddress(uint <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3687 | </pre> |
| 3688 | |
| 3689 | <h5>Overview:</h5> |
| 3690 | |
| 3691 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 3692 | The '<tt>llvm.returnaddress</tt>' intrinsic attempts to compute a |
| 3693 | target-specific value indicating the return address of the current function |
| 3694 | or one of its callers. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3695 | </p> |
| 3696 | |
| 3697 | <h5>Arguments:</h5> |
| 3698 | |
| 3699 | <p> |
| 3700 | The argument to this intrinsic indicates which function to return the address |
| 3701 | for. Zero indicates the calling function, one indicates its caller, etc. The |
| 3702 | argument is <b>required</b> to be a constant integer value. |
| 3703 | </p> |
| 3704 | |
| 3705 | <h5>Semantics:</h5> |
| 3706 | |
| 3707 | <p> |
| 3708 | The '<tt>llvm.returnaddress</tt>' intrinsic either returns a pointer indicating |
| 3709 | the return address of the specified call frame, or zero if it cannot be |
| 3710 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 3711 | for arguments other than zero, so it should only be used for debugging purposes. |
| 3712 | </p> |
| 3713 | |
| 3714 | <p> |
| 3715 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 3716 | 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] | 3717 | source-language caller. |
| 3718 | </p> |
| 3719 | </div> |
| 3720 | |
| 3721 | |
| 3722 | <!-- _______________________________________________________________________ --> |
| 3723 | <div class="doc_subsubsection"> |
| 3724 | <a name="i_frameaddress">'<tt>llvm.frameaddress</tt>' Intrinsic</a> |
| 3725 | </div> |
| 3726 | |
| 3727 | <div class="doc_text"> |
| 3728 | |
| 3729 | <h5>Syntax:</h5> |
| 3730 | <pre> |
Chris Lattner | fcf39d4 | 2006-01-13 01:20:27 +0000 | [diff] [blame] | 3731 | declare sbyte *%llvm.frameaddress(uint <level>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3732 | </pre> |
| 3733 | |
| 3734 | <h5>Overview:</h5> |
| 3735 | |
| 3736 | <p> |
Chris Lattner | 32b5d71 | 2006-10-15 20:05:59 +0000 | [diff] [blame] | 3737 | The '<tt>llvm.frameaddress</tt>' intrinsic attempts to return the |
| 3738 | target-specific frame pointer value for the specified stack frame. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3739 | </p> |
| 3740 | |
| 3741 | <h5>Arguments:</h5> |
| 3742 | |
| 3743 | <p> |
| 3744 | The argument to this intrinsic indicates which function to return the frame |
| 3745 | pointer for. Zero indicates the calling function, one indicates its caller, |
| 3746 | etc. The argument is <b>required</b> to be a constant integer value. |
| 3747 | </p> |
| 3748 | |
| 3749 | <h5>Semantics:</h5> |
| 3750 | |
| 3751 | <p> |
| 3752 | The '<tt>llvm.frameaddress</tt>' intrinsic either returns a pointer indicating |
| 3753 | the frame address of the specified call frame, or zero if it cannot be |
| 3754 | identified. The value returned by this intrinsic is likely to be incorrect or 0 |
| 3755 | for arguments other than zero, so it should only be used for debugging purposes. |
| 3756 | </p> |
| 3757 | |
| 3758 | <p> |
| 3759 | Note that calling this intrinsic does not prevent function inlining or other |
Chris Lattner | b40bb38 | 2005-03-07 20:30:51 +0000 | [diff] [blame] | 3760 | 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] | 3761 | source-language caller. |
| 3762 | </p> |
| 3763 | </div> |
| 3764 | |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 3765 | <!-- _______________________________________________________________________ --> |
| 3766 | <div class="doc_subsubsection"> |
Chris Lattner | 57e1f39 | 2006-01-13 02:03:13 +0000 | [diff] [blame] | 3767 | <a name="i_stacksave">'<tt>llvm.stacksave</tt>' Intrinsic</a> |
| 3768 | </div> |
| 3769 | |
| 3770 | <div class="doc_text"> |
| 3771 | |
| 3772 | <h5>Syntax:</h5> |
| 3773 | <pre> |
| 3774 | declare sbyte *%llvm.stacksave() |
| 3775 | </pre> |
| 3776 | |
| 3777 | <h5>Overview:</h5> |
| 3778 | |
| 3779 | <p> |
| 3780 | The '<tt>llvm.stacksave</tt>' intrinsic is used to remember the current state of |
| 3781 | the function stack, for use with <a href="#i_stackrestore"> |
| 3782 | <tt>llvm.stackrestore</tt></a>. This is useful for implementing language |
| 3783 | features like scoped automatic variable sized arrays in C99. |
| 3784 | </p> |
| 3785 | |
| 3786 | <h5>Semantics:</h5> |
| 3787 | |
| 3788 | <p> |
| 3789 | This intrinsic returns a opaque pointer value that can be passed to <a |
| 3790 | href="#i_stackrestore"><tt>llvm.stackrestore</tt></a>. When an |
| 3791 | <tt>llvm.stackrestore</tt> intrinsic is executed with a value saved from |
| 3792 | <tt>llvm.stacksave</tt>, it effectively restores the state of the stack to the |
| 3793 | state it was in when the <tt>llvm.stacksave</tt> intrinsic executed. In |
| 3794 | practice, this pops any <a href="#i_alloca">alloca</a> blocks from the stack |
| 3795 | that were allocated after the <tt>llvm.stacksave</tt> was executed. |
| 3796 | </p> |
| 3797 | |
| 3798 | </div> |
| 3799 | |
| 3800 | <!-- _______________________________________________________________________ --> |
| 3801 | <div class="doc_subsubsection"> |
| 3802 | <a name="i_stackrestore">'<tt>llvm.stackrestore</tt>' Intrinsic</a> |
| 3803 | </div> |
| 3804 | |
| 3805 | <div class="doc_text"> |
| 3806 | |
| 3807 | <h5>Syntax:</h5> |
| 3808 | <pre> |
| 3809 | declare void %llvm.stackrestore(sbyte* %ptr) |
| 3810 | </pre> |
| 3811 | |
| 3812 | <h5>Overview:</h5> |
| 3813 | |
| 3814 | <p> |
| 3815 | The '<tt>llvm.stackrestore</tt>' intrinsic is used to restore the state of |
| 3816 | the function stack to the state it was in when the corresponding <a |
| 3817 | href="#llvm.stacksave"><tt>llvm.stacksave</tt></a> intrinsic executed. This is |
| 3818 | useful for implementing language features like scoped automatic variable sized |
| 3819 | arrays in C99. |
| 3820 | </p> |
| 3821 | |
| 3822 | <h5>Semantics:</h5> |
| 3823 | |
| 3824 | <p> |
| 3825 | See the description for <a href="#i_stacksave"><tt>llvm.stacksave</tt></a>. |
| 3826 | </p> |
| 3827 | |
| 3828 | </div> |
| 3829 | |
| 3830 | |
| 3831 | <!-- _______________________________________________________________________ --> |
| 3832 | <div class="doc_subsubsection"> |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 3833 | <a name="i_prefetch">'<tt>llvm.prefetch</tt>' Intrinsic</a> |
| 3834 | </div> |
| 3835 | |
| 3836 | <div class="doc_text"> |
| 3837 | |
| 3838 | <h5>Syntax:</h5> |
| 3839 | <pre> |
Reid Spencer | a8d451e | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 3840 | declare void %llvm.prefetch(sbyte * <address>, |
| 3841 | uint <rw>, uint <locality>) |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 3842 | </pre> |
| 3843 | |
| 3844 | <h5>Overview:</h5> |
| 3845 | |
| 3846 | |
| 3847 | <p> |
| 3848 | 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] | 3849 | a prefetch instruction if supported; otherwise, it is a noop. Prefetches have |
| 3850 | no |
| 3851 | effect on the behavior of the program but can change its performance |
Chris Lattner | 2a61536 | 2005-02-28 19:47:14 +0000 | [diff] [blame] | 3852 | characteristics. |
Chris Lattner | 9a9d7ac | 2005-02-28 19:24:19 +0000 | [diff] [blame] | 3853 | </p> |
| 3854 | |
| 3855 | <h5>Arguments:</h5> |
| 3856 | |
| 3857 | <p> |
| 3858 | <tt>address</tt> is the address to be prefetched, <tt>rw</tt> is the specifier |
| 3859 | determining if the fetch should be for a read (0) or write (1), and |
| 3860 | <tt>locality</tt> is a temporal locality specifier ranging from (0) - no |
Chris Lattner | aeffb4a | 2005-03-07 20:31:38 +0000 | [diff] [blame] | 3861 | 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] | 3862 | <tt>locality</tt> arguments must be constant integers. |
| 3863 | </p> |
| 3864 | |
| 3865 | <h5>Semantics:</h5> |
| 3866 | |
| 3867 | <p> |
| 3868 | This intrinsic does not modify the behavior of the program. In particular, |
| 3869 | prefetches cannot trap and do not produce a value. On targets that support this |
| 3870 | intrinsic, the prefetch can provide hints to the processor cache for better |
| 3871 | performance. |
| 3872 | </p> |
| 3873 | |
| 3874 | </div> |
| 3875 | |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 3876 | <!-- _______________________________________________________________________ --> |
| 3877 | <div class="doc_subsubsection"> |
| 3878 | <a name="i_pcmarker">'<tt>llvm.pcmarker</tt>' Intrinsic</a> |
| 3879 | </div> |
| 3880 | |
| 3881 | <div class="doc_text"> |
| 3882 | |
| 3883 | <h5>Syntax:</h5> |
| 3884 | <pre> |
Reid Spencer | a8d451e | 2005-04-26 20:50:44 +0000 | [diff] [blame] | 3885 | declare void %llvm.pcmarker( uint <id> ) |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 3886 | </pre> |
| 3887 | |
| 3888 | <h5>Overview:</h5> |
| 3889 | |
| 3890 | |
| 3891 | <p> |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3892 | The '<tt>llvm.pcmarker</tt>' intrinsic is a method to export a Program Counter |
| 3893 | (PC) in a region of |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 3894 | code to simulators and other tools. The method is target specific, but it is |
| 3895 | 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] | 3896 | 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] | 3897 | 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] | 3898 | optimizations. The intended use is to be inserted after optimizations to allow |
John Criswell | fc6b895 | 2005-05-16 16:17:45 +0000 | [diff] [blame] | 3899 | correlations of simulation runs. |
Andrew Lenharth | 7f4ec3b | 2005-03-28 20:05:49 +0000 | [diff] [blame] | 3900 | </p> |
| 3901 | |
| 3902 | <h5>Arguments:</h5> |
| 3903 | |
| 3904 | <p> |
| 3905 | <tt>id</tt> is a numerical id identifying the marker. |
| 3906 | </p> |
| 3907 | |
| 3908 | <h5>Semantics:</h5> |
| 3909 | |
| 3910 | <p> |
| 3911 | This intrinsic does not modify the behavior of the program. Backends that do not |
| 3912 | support this intrinisic may ignore it. |
| 3913 | </p> |
| 3914 | |
| 3915 | </div> |
| 3916 | |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 3917 | <!-- _______________________________________________________________________ --> |
| 3918 | <div class="doc_subsubsection"> |
| 3919 | <a name="i_readcyclecounter">'<tt>llvm.readcyclecounter</tt>' Intrinsic</a> |
| 3920 | </div> |
| 3921 | |
| 3922 | <div class="doc_text"> |
| 3923 | |
| 3924 | <h5>Syntax:</h5> |
| 3925 | <pre> |
| 3926 | declare ulong %llvm.readcyclecounter( ) |
| 3927 | </pre> |
| 3928 | |
| 3929 | <h5>Overview:</h5> |
| 3930 | |
| 3931 | |
| 3932 | <p> |
| 3933 | The '<tt>llvm.readcyclecounter</tt>' intrinsic provides access to the cycle |
| 3934 | counter register (or similar low latency, high accuracy clocks) on those targets |
| 3935 | that support it. On X86, it should map to RDTSC. On Alpha, it should map to RPCC. |
| 3936 | As the backing counters overflow quickly (on the order of 9 seconds on alpha), this |
| 3937 | should only be used for small timings. |
| 3938 | </p> |
| 3939 | |
| 3940 | <h5>Semantics:</h5> |
| 3941 | |
| 3942 | <p> |
| 3943 | When directly supported, reading the cycle counter should not modify any memory. |
| 3944 | Implementations are allowed to either return a application specific value or a |
| 3945 | system wide value. On backends without support, this is lowered to a constant 0. |
| 3946 | </p> |
| 3947 | |
| 3948 | </div> |
| 3949 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3950 | <!-- ======================================================================= --> |
| 3951 | <div class="doc_subsection"> |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3952 | <a name="int_libc">Standard C Library Intrinsics</a> |
| 3953 | </div> |
| 3954 | |
| 3955 | <div class="doc_text"> |
| 3956 | <p> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 3957 | LLVM provides intrinsics for a few important standard C library functions. |
| 3958 | These intrinsics allow source-language front-ends to pass information about the |
| 3959 | alignment of the pointer arguments to the code generator, providing opportunity |
| 3960 | for more efficient code generation. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3961 | </p> |
| 3962 | |
| 3963 | </div> |
| 3964 | |
| 3965 | <!-- _______________________________________________________________________ --> |
| 3966 | <div class="doc_subsubsection"> |
| 3967 | <a name="i_memcpy">'<tt>llvm.memcpy</tt>' Intrinsic</a> |
| 3968 | </div> |
| 3969 | |
| 3970 | <div class="doc_text"> |
| 3971 | |
| 3972 | <h5>Syntax:</h5> |
| 3973 | <pre> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 3974 | declare void %llvm.memcpy.i32(sbyte* <dest>, sbyte* <src>, |
| 3975 | uint <len>, uint <align>) |
| 3976 | declare void %llvm.memcpy.i64(sbyte* <dest>, sbyte* <src>, |
| 3977 | ulong <len>, uint <align>) |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3978 | </pre> |
| 3979 | |
| 3980 | <h5>Overview:</h5> |
| 3981 | |
| 3982 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 3983 | 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] | 3984 | location to the destination location. |
| 3985 | </p> |
| 3986 | |
| 3987 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 3988 | Note that, unlike the standard libc function, the <tt>llvm.memcpy.*</tt> |
| 3989 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3990 | </p> |
| 3991 | |
| 3992 | <h5>Arguments:</h5> |
| 3993 | |
| 3994 | <p> |
| 3995 | 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] | 3996 | the source. The third argument is an integer argument |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 3997 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 3998 | of the source and destination locations. |
| 3999 | </p> |
| 4000 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4001 | <p> |
| 4002 | 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] | 4003 | the caller guarantees that both the source and destination pointers are aligned |
| 4004 | to that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4005 | </p> |
| 4006 | |
Chris Lattner | 33aec9e | 2004-02-12 17:01:32 +0000 | [diff] [blame] | 4007 | <h5>Semantics:</h5> |
| 4008 | |
| 4009 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4010 | 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] | 4011 | location to the destination location, which are not allowed to overlap. It |
| 4012 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 4013 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 4014 | be set to 0 or 1. |
| 4015 | </p> |
| 4016 | </div> |
| 4017 | |
| 4018 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4019 | <!-- _______________________________________________________________________ --> |
| 4020 | <div class="doc_subsubsection"> |
| 4021 | <a name="i_memmove">'<tt>llvm.memmove</tt>' Intrinsic</a> |
| 4022 | </div> |
| 4023 | |
| 4024 | <div class="doc_text"> |
| 4025 | |
| 4026 | <h5>Syntax:</h5> |
| 4027 | <pre> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4028 | declare void %llvm.memmove.i32(sbyte* <dest>, sbyte* <src>, |
| 4029 | uint <len>, uint <align>) |
| 4030 | declare void %llvm.memmove.i64(sbyte* <dest>, sbyte* <src>, |
| 4031 | ulong <len>, uint <align>) |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4032 | </pre> |
| 4033 | |
| 4034 | <h5>Overview:</h5> |
| 4035 | |
| 4036 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4037 | The '<tt>llvm.memmove.*</tt>' intrinsics move a block of memory from the source |
| 4038 | location to the destination location. It is similar to the |
| 4039 | '<tt>llvm.memcmp</tt>' intrinsic but allows the two memory locations to overlap. |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4040 | </p> |
| 4041 | |
| 4042 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4043 | Note that, unlike the standard libc function, the <tt>llvm.memmove.*</tt> |
| 4044 | intrinsics do not return a value, and takes an extra alignment argument. |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4045 | </p> |
| 4046 | |
| 4047 | <h5>Arguments:</h5> |
| 4048 | |
| 4049 | <p> |
| 4050 | 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] | 4051 | the source. The third argument is an integer argument |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4052 | specifying the number of bytes to copy, and the fourth argument is the alignment |
| 4053 | of the source and destination locations. |
| 4054 | </p> |
| 4055 | |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4056 | <p> |
| 4057 | 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] | 4058 | the caller guarantees that the source and destination pointers are aligned to |
| 4059 | that boundary. |
Chris Lattner | 3301ced | 2004-02-12 21:18:15 +0000 | [diff] [blame] | 4060 | </p> |
| 4061 | |
Chris Lattner | 0eb51b4 | 2004-02-12 18:10:10 +0000 | [diff] [blame] | 4062 | <h5>Semantics:</h5> |
| 4063 | |
| 4064 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4065 | 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] | 4066 | location to the destination location, which may overlap. It |
| 4067 | copies "len" bytes of memory over. If the argument is known to be aligned to |
| 4068 | some boundary, this can be specified as the fourth argument, otherwise it should |
| 4069 | be set to 0 or 1. |
| 4070 | </p> |
| 4071 | </div> |
| 4072 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4073 | |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4074 | <!-- _______________________________________________________________________ --> |
| 4075 | <div class="doc_subsubsection"> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4076 | <a name="i_memset">'<tt>llvm.memset.*</tt>' Intrinsics</a> |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4077 | </div> |
| 4078 | |
| 4079 | <div class="doc_text"> |
| 4080 | |
| 4081 | <h5>Syntax:</h5> |
| 4082 | <pre> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4083 | declare void %llvm.memset.i32(sbyte* <dest>, ubyte <val>, |
| 4084 | uint <len>, uint <align>) |
| 4085 | declare void %llvm.memset.i64(sbyte* <dest>, ubyte <val>, |
| 4086 | ulong <len>, uint <align>) |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4087 | </pre> |
| 4088 | |
| 4089 | <h5>Overview:</h5> |
| 4090 | |
| 4091 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4092 | 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] | 4093 | byte value. |
| 4094 | </p> |
| 4095 | |
| 4096 | <p> |
| 4097 | Note that, unlike the standard libc function, the <tt>llvm.memset</tt> intrinsic |
| 4098 | does not return a value, and takes an extra alignment argument. |
| 4099 | </p> |
| 4100 | |
| 4101 | <h5>Arguments:</h5> |
| 4102 | |
| 4103 | <p> |
| 4104 | 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] | 4105 | byte value to fill it with, the third argument is an integer |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4106 | argument specifying the number of bytes to fill, and the fourth argument is the |
| 4107 | known alignment of destination location. |
| 4108 | </p> |
| 4109 | |
| 4110 | <p> |
| 4111 | 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] | 4112 | the caller guarantees that the destination pointer is aligned to that boundary. |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4113 | </p> |
| 4114 | |
| 4115 | <h5>Semantics:</h5> |
| 4116 | |
| 4117 | <p> |
Chris Lattner | 5b310c3 | 2006-03-03 00:07:20 +0000 | [diff] [blame] | 4118 | The '<tt>llvm.memset.*</tt>' intrinsics fill "len" bytes of memory starting at |
| 4119 | the |
Chris Lattner | 1061064 | 2004-02-14 04:08:35 +0000 | [diff] [blame] | 4120 | destination location. If the argument is known to be aligned to some boundary, |
| 4121 | this can be specified as the fourth argument, otherwise it should be set to 0 or |
| 4122 | 1. |
| 4123 | </p> |
| 4124 | </div> |
| 4125 | |
| 4126 | |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 4127 | <!-- _______________________________________________________________________ --> |
| 4128 | <div class="doc_subsubsection"> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4129 | <a name="i_isunordered">'<tt>llvm.isunordered.*</tt>' Intrinsic</a> |
Alkis Evlogimenos | 26bbe93 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 4130 | </div> |
| 4131 | |
| 4132 | <div class="doc_text"> |
| 4133 | |
| 4134 | <h5>Syntax:</h5> |
| 4135 | <pre> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4136 | declare bool %llvm.isunordered.f32(float Val1, float Val2) |
| 4137 | declare bool %llvm.isunordered.f64(double Val1, double Val2) |
Alkis Evlogimenos | 26bbe93 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 4138 | </pre> |
| 4139 | |
| 4140 | <h5>Overview:</h5> |
| 4141 | |
| 4142 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4143 | The '<tt>llvm.isunordered</tt>' intrinsics return true if either or both of the |
Alkis Evlogimenos | 26bbe93 | 2004-06-13 01:16:15 +0000 | [diff] [blame] | 4144 | specified floating point values is a NAN. |
| 4145 | </p> |
| 4146 | |
| 4147 | <h5>Arguments:</h5> |
| 4148 | |
| 4149 | <p> |
| 4150 | The arguments are floating point numbers of the same type. |
| 4151 | </p> |
| 4152 | |
| 4153 | <h5>Semantics:</h5> |
| 4154 | |
| 4155 | <p> |
| 4156 | If either or both of the arguments is a SNAN or QNAN, it returns true, otherwise |
| 4157 | false. |
| 4158 | </p> |
| 4159 | </div> |
| 4160 | |
| 4161 | |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4162 | <!-- _______________________________________________________________________ --> |
| 4163 | <div class="doc_subsubsection"> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4164 | <a name="i_sqrt">'<tt>llvm.sqrt.*</tt>' Intrinsic</a> |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4165 | </div> |
| 4166 | |
| 4167 | <div class="doc_text"> |
| 4168 | |
| 4169 | <h5>Syntax:</h5> |
| 4170 | <pre> |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4171 | declare float %llvm.sqrt.f32(float %Val) |
| 4172 | declare double %llvm.sqrt.f64(double %Val) |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4173 | </pre> |
| 4174 | |
| 4175 | <h5>Overview:</h5> |
| 4176 | |
| 4177 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4178 | The '<tt>llvm.sqrt</tt>' intrinsics return the sqrt of the specified operand, |
Chris Lattner | a4d7414 | 2005-07-21 01:29:16 +0000 | [diff] [blame] | 4179 | returning the same value as the libm '<tt>sqrt</tt>' function would. Unlike |
| 4180 | <tt>sqrt</tt> in libm, however, <tt>llvm.sqrt</tt> has undefined behavior for |
| 4181 | negative numbers (which allows for better optimization). |
| 4182 | </p> |
| 4183 | |
| 4184 | <h5>Arguments:</h5> |
| 4185 | |
| 4186 | <p> |
| 4187 | The argument and return value are floating point numbers of the same type. |
| 4188 | </p> |
| 4189 | |
| 4190 | <h5>Semantics:</h5> |
| 4191 | |
| 4192 | <p> |
| 4193 | This function returns the sqrt of the specified operand if it is a positive |
| 4194 | floating point number. |
| 4195 | </p> |
| 4196 | </div> |
| 4197 | |
Chris Lattner | f4d252d | 2006-09-08 06:34:02 +0000 | [diff] [blame] | 4198 | <!-- _______________________________________________________________________ --> |
| 4199 | <div class="doc_subsubsection"> |
| 4200 | <a name="i_powi">'<tt>llvm.powi.*</tt>' Intrinsic</a> |
| 4201 | </div> |
| 4202 | |
| 4203 | <div class="doc_text"> |
| 4204 | |
| 4205 | <h5>Syntax:</h5> |
| 4206 | <pre> |
| 4207 | declare float %llvm.powi.f32(float %Val, int %power) |
| 4208 | declare double %llvm.powi.f64(double %Val, int %power) |
| 4209 | </pre> |
| 4210 | |
| 4211 | <h5>Overview:</h5> |
| 4212 | |
| 4213 | <p> |
| 4214 | The '<tt>llvm.powi.*</tt>' intrinsics return the first operand raised to the |
| 4215 | specified (positive or negative) power. The order of evaluation of |
| 4216 | multiplications is not defined. |
| 4217 | </p> |
| 4218 | |
| 4219 | <h5>Arguments:</h5> |
| 4220 | |
| 4221 | <p> |
| 4222 | The second argument is an integer power, and the first is a value to raise to |
| 4223 | that power. |
| 4224 | </p> |
| 4225 | |
| 4226 | <h5>Semantics:</h5> |
| 4227 | |
| 4228 | <p> |
| 4229 | This function returns the first value raised to the second power with an |
| 4230 | unspecified sequence of rounding operations.</p> |
| 4231 | </div> |
| 4232 | |
| 4233 | |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4234 | <!-- ======================================================================= --> |
| 4235 | <div class="doc_subsection"> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4236 | <a name="int_manip">Bit Manipulation Intrinsics</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4237 | </div> |
| 4238 | |
| 4239 | <div class="doc_text"> |
| 4240 | <p> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4241 | LLVM provides intrinsics for a few important bit manipulation operations. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4242 | These allow efficient code generation for some algorithms. |
| 4243 | </p> |
| 4244 | |
| 4245 | </div> |
| 4246 | |
| 4247 | <!-- _______________________________________________________________________ --> |
| 4248 | <div class="doc_subsubsection"> |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4249 | <a name="i_bswap">'<tt>llvm.bswap.*</tt>' Intrinsics</a> |
| 4250 | </div> |
| 4251 | |
| 4252 | <div class="doc_text"> |
| 4253 | |
| 4254 | <h5>Syntax:</h5> |
| 4255 | <pre> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4256 | declare ushort %llvm.bswap.i16(ushort <id>) |
| 4257 | declare uint %llvm.bswap.i32(uint <id>) |
| 4258 | declare ulong %llvm.bswap.i64(ulong <id>) |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4259 | </pre> |
| 4260 | |
| 4261 | <h5>Overview:</h5> |
| 4262 | |
| 4263 | <p> |
| 4264 | The '<tt>llvm.bwsap</tt>' family of intrinsics is used to byteswap a 16, 32 or |
| 4265 | 64 bit quantity. These are useful for performing operations on data that is not |
| 4266 | in the target's native byte order. |
| 4267 | </p> |
| 4268 | |
| 4269 | <h5>Semantics:</h5> |
| 4270 | |
| 4271 | <p> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4272 | The <tt>llvm.bswap.16</tt> intrinsic returns a ushort value that has the high and low |
| 4273 | byte of the input ushort swapped. Similarly, the <tt>llvm.bswap.i32</tt> intrinsic |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4274 | returns a uint value that has the four bytes of the input uint swapped, so that |
| 4275 | if the input bytes are numbered 0, 1, 2, 3 then the returned uint will have its |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4276 | bytes in 3, 2, 1, 0 order. The <tt>llvm.bswap.i64</tt> intrinsic extends this concept |
Nate Begeman | 7e36c47 | 2006-01-13 23:26:38 +0000 | [diff] [blame] | 4277 | to 64 bits. |
| 4278 | </p> |
| 4279 | |
| 4280 | </div> |
| 4281 | |
| 4282 | <!-- _______________________________________________________________________ --> |
| 4283 | <div class="doc_subsubsection"> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4284 | <a name="int_ctpop">'<tt>llvm.ctpop.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4285 | </div> |
| 4286 | |
| 4287 | <div class="doc_text"> |
| 4288 | |
| 4289 | <h5>Syntax:</h5> |
| 4290 | <pre> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4291 | declare ubyte %llvm.ctpop.i8 (ubyte <src>) |
| 4292 | declare ushort %llvm.ctpop.i16(ushort <src>) |
| 4293 | declare uint %llvm.ctpop.i32(uint <src>) |
| 4294 | declare ulong %llvm.ctpop.i64(ulong <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4295 | </pre> |
| 4296 | |
| 4297 | <h5>Overview:</h5> |
| 4298 | |
| 4299 | <p> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4300 | The '<tt>llvm.ctpop</tt>' family of intrinsics counts the number of bits set in a |
| 4301 | value. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4302 | </p> |
| 4303 | |
| 4304 | <h5>Arguments:</h5> |
| 4305 | |
| 4306 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 4307 | The only argument is the value to be counted. The argument may be of any |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4308 | unsigned integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4309 | </p> |
| 4310 | |
| 4311 | <h5>Semantics:</h5> |
| 4312 | |
| 4313 | <p> |
| 4314 | The '<tt>llvm.ctpop</tt>' intrinsic counts the 1's in a variable. |
| 4315 | </p> |
| 4316 | </div> |
| 4317 | |
| 4318 | <!-- _______________________________________________________________________ --> |
| 4319 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 4320 | <a name="int_ctlz">'<tt>llvm.ctlz.*</tt>' Intrinsic</a> |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4321 | </div> |
| 4322 | |
| 4323 | <div class="doc_text"> |
| 4324 | |
| 4325 | <h5>Syntax:</h5> |
| 4326 | <pre> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4327 | declare ubyte %llvm.ctlz.i8 (ubyte <src>) |
| 4328 | declare ushort %llvm.ctlz.i16(ushort <src>) |
| 4329 | declare uint %llvm.ctlz.i32(uint <src>) |
| 4330 | declare ulong %llvm.ctlz.i64(ulong <src>) |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4331 | </pre> |
| 4332 | |
| 4333 | <h5>Overview:</h5> |
| 4334 | |
| 4335 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4336 | The '<tt>llvm.ctlz</tt>' family of intrinsic functions counts the number of |
| 4337 | leading zeros in a variable. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4338 | </p> |
| 4339 | |
| 4340 | <h5>Arguments:</h5> |
| 4341 | |
| 4342 | <p> |
Chris Lattner | cfe6b37 | 2005-05-07 01:46:40 +0000 | [diff] [blame] | 4343 | The only argument is the value to be counted. The argument may be of any |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4344 | unsigned integer type. The return type must match the argument type. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4345 | </p> |
| 4346 | |
| 4347 | <h5>Semantics:</h5> |
| 4348 | |
| 4349 | <p> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4350 | The '<tt>llvm.ctlz</tt>' intrinsic counts the leading (most significant) zeros |
| 4351 | in a variable. If the src == 0 then the result is the size in bits of the type |
Chris Lattner | 99d3c27 | 2006-04-21 21:37:40 +0000 | [diff] [blame] | 4352 | of src. For example, <tt>llvm.ctlz(int 2) = 30</tt>. |
Andrew Lenharth | ec370fd | 2005-05-03 18:01:48 +0000 | [diff] [blame] | 4353 | </p> |
| 4354 | </div> |
Chris Lattner | 3200628 | 2004-06-11 02:28:03 +0000 | [diff] [blame] | 4355 | |
| 4356 | |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4357 | |
| 4358 | <!-- _______________________________________________________________________ --> |
| 4359 | <div class="doc_subsubsection"> |
Chris Lattner | 8a886be | 2006-01-16 22:34:14 +0000 | [diff] [blame] | 4360 | <a name="int_cttz">'<tt>llvm.cttz.*</tt>' Intrinsic</a> |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4361 | </div> |
| 4362 | |
| 4363 | <div class="doc_text"> |
| 4364 | |
| 4365 | <h5>Syntax:</h5> |
| 4366 | <pre> |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4367 | declare ubyte %llvm.cttz.i8 (ubyte <src>) |
| 4368 | declare ushort %llvm.cttz.i16(ushort <src>) |
| 4369 | declare uint %llvm.cttz.i32(uint <src>) |
| 4370 | declare ulong %llvm.cttz.i64(ulong <src>) |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4371 | </pre> |
| 4372 | |
| 4373 | <h5>Overview:</h5> |
| 4374 | |
| 4375 | <p> |
Reid Spencer | 0b11820 | 2006-01-16 21:12:35 +0000 | [diff] [blame] | 4376 | The '<tt>llvm.cttz</tt>' family of intrinsic functions counts the number of |
| 4377 | trailing zeros. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4378 | </p> |
| 4379 | |
| 4380 | <h5>Arguments:</h5> |
| 4381 | |
| 4382 | <p> |
| 4383 | The only argument is the value to be counted. The argument may be of any |
Chris Lattner | ec6cb61 | 2006-01-16 22:38:59 +0000 | [diff] [blame] | 4384 | unsigned integer type. The return type must match the argument type. |
Chris Lattner | eff29ab | 2005-05-15 19:39:26 +0000 | [diff] [blame] | 4385 | </p> |
| 4386 | |
| 4387 | <h5>Semantics:</h5> |
| 4388 | |
| 4389 | <p> |
| 4390 | The '<tt>llvm.cttz</tt>' intrinsic counts the trailing (least significant) zeros |
| 4391 | in a variable. If the src == 0 then the result is the size in bits of the type |
| 4392 | of src. For example, <tt>llvm.cttz(2) = 1</tt>. |
| 4393 | </p> |
| 4394 | </div> |
| 4395 | |
Chris Lattner | 8ff7590 | 2004-01-06 05:31:32 +0000 | [diff] [blame] | 4396 | <!-- ======================================================================= --> |
| 4397 | <div class="doc_subsection"> |
| 4398 | <a name="int_debugger">Debugger Intrinsics</a> |
| 4399 | </div> |
| 4400 | |
| 4401 | <div class="doc_text"> |
| 4402 | <p> |
| 4403 | The LLVM debugger intrinsics (which all start with <tt>llvm.dbg.</tt> prefix), |
| 4404 | are described in the <a |
| 4405 | href="SourceLevelDebugging.html#format_common_intrinsics">LLVM Source Level |
| 4406 | Debugging</a> document. |
| 4407 | </p> |
| 4408 | </div> |
| 4409 | |
| 4410 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4411 | <!-- *********************************************************************** --> |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 4412 | <hr> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 4413 | <address> |
| 4414 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 4415 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 4416 | <a href="http://validator.w3.org/check/referer"><img |
| 4417 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /></a> |
| 4418 | |
| 4419 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 4420 | <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> |
Misha Brukman | daa4cb0 | 2004-03-01 17:47:27 +0000 | [diff] [blame] | 4421 | Last modified: $Date$ |
| 4422 | </address> |
Misha Brukman | 9d0919f | 2003-11-08 01:05:38 +0000 | [diff] [blame] | 4423 | </body> |
| 4424 | </html> |