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