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