Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 2 | <html> |
| 3 | <head> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 5 | <title>LLVM Bytecode File Format</title> |
| 6 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 7 | <style type="text/css"> |
Reid Spencer | 2de2999 | 2004-08-03 20:21:05 +0000 | [diff] [blame] | 8 | TR, TD { border: 2px solid gray; padding-left: 4pt; padding-right: 4pt; |
| 9 | padding-top: 2pt; padding-bottom: 2pt; } |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 10 | TH { border: 2px solid gray; font-weight: bold; font-size: 105%; } |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 11 | TABLE { text-align: center; border: 2px solid black; |
Reid Spencer | 2de2999 | 2004-08-03 20:21:05 +0000 | [diff] [blame] | 12 | border-collapse: collapse; margin-top: 1em; margin-left: 1em; |
| 13 | margin-right: 1em; margin-bottom: 1em; } |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 14 | .td_left { border: 2px solid gray; text-align: left; } |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 15 | </style> |
| 16 | </head> |
| 17 | <body> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 18 | <div class="doc_title"> LLVM Bytecode File Format </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 19 | <ol> |
| 20 | <li><a href="#abstract">Abstract</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 21 | <li><a href="#concepts">Concepts</a> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 22 | <ol> |
| 23 | <li><a href="#blocks">Blocks</a></li> |
| 24 | <li><a href="#lists">Lists</a></li> |
| 25 | <li><a href="#fields">Fields</a></li> |
| 26 | <li><a href="#align">Alignment</a></li> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 27 | <li><a href="#vbr">Variable Bit-Rate Encoding</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 28 | <li><a href="#encoding">Encoding Primitives</a></li> |
| 29 | <li><a href="#slots">Slots</a></li> |
| 30 | </ol> |
| 31 | </li> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 32 | <li><a href="#general">General Structure</a> </li> |
| 33 | <li><a href="#blockdefs">Block Definitions</a> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 34 | <ol> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 35 | <li><a href="#signature">Signature Block</a></li> |
| 36 | <li><a href="#module">Module Block</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 37 | <li><a href="#globaltypes">Global Type Pool</a></li> |
| 38 | <li><a href="#globalinfo">Module Info Block</a></li> |
| 39 | <li><a href="#constantpool">Global Constant Pool</a></li> |
| 40 | <li><a href="#functiondefs">Function Definition</a></li> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 41 | <li><a href="#instructionlist">Instructions List</a></li> |
| 42 | <li><a href="#instructions">Instructions</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 43 | <li><a href="#symtab">Symbol Table</a></li> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 44 | </ol> |
| 45 | </li> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 46 | <li><a href="#versiondiffs">Version Differences</a> |
| 47 | <ol> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 48 | <li><a href="#vers13">Version 1.3 Differences From 1.4</a></li> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 49 | <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li> |
| 50 | <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li> |
| 51 | <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li> |
| 52 | </ol> |
| 53 | </li> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 54 | </ol> |
Chris Lattner | 8dabb50 | 2004-05-25 17:44:58 +0000 | [diff] [blame] | 55 | <div class="doc_author"> |
| 56 | <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> |
| 57 | </p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 58 | </div> |
| 59 | <!-- *********************************************************************** --> |
| 60 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 61 | <!-- *********************************************************************** --> |
| 62 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 63 | <p>This document describes the LLVM bytecode file format. It specifies |
| 64 | the binary encoding rules of the bytecode file format so that |
| 65 | equivalent systems can encode bytecode files correctly. The LLVM |
| 66 | bytecode representation is used to store the intermediate |
| 67 | representation on disk in compacted form.</p> |
| 68 | <p>The LLVM bytecode format may change in the future, but LLVM will |
| 69 | always be backwards compatible with older formats. This document will |
| 70 | only describe the most current version of the bytecode format. See <a |
| 71 | href="#versiondiffs">Version Differences</a> for the details on how |
| 72 | the current version is different from previous versions.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 73 | </div> |
| 74 | <!-- *********************************************************************** --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 75 | <div class="doc_section"> <a name="concepts">Concepts</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 76 | <!-- *********************************************************************** --> |
| 77 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 78 | <p>This section describes the general concepts of the bytecode file |
| 79 | format without getting into specific layout details. It is recommended |
| 80 | that you read this section thoroughly before interpreting the detailed |
| 81 | descriptions.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 82 | </div> |
| 83 | <!-- _______________________________________________________________________ --> |
| 84 | <div class="doc_subsection"><a name="blocks">Blocks</a> </div> |
| 85 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 86 | <p>LLVM bytecode files consist simply of a sequence of blocks of bytes |
| 87 | using a binary encoding Each block begins with an header of two |
| 88 | unsigned integers. The first value identifies the type of block and the |
| 89 | second value provides the size of the block in bytes. The block |
| 90 | identifier is used because it is possible for entire blocks to be |
| 91 | omitted from the file if they are empty. The block identifier helps the |
| 92 | reader determine which kind of block is next in the file. Note that |
| 93 | blocks can be nested within other blocks.</p> |
| 94 | <p> All blocks are variable length, and the block header specifies the |
| 95 | size of the block. All blocks begin on a byte index that is aligned to |
| 96 | an even 32-bit boundary. That is, the first block is 32-bit aligned |
| 97 | because it starts at offset 0. Each block is padded with zero fill |
| 98 | bytes to ensure that the next block also starts on a 32-bit boundary.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 99 | </div> |
| 100 | <!-- _______________________________________________________________________ --> |
| 101 | <div class="doc_subsection"><a name="lists">Lists</a> </div> |
| 102 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 103 | <p>LLVM Bytecode blocks often contain lists of things of a similar |
| 104 | type. For example, a function contains a list of instructions and a |
| 105 | function type contains a list of argument types. There are two basic |
| 106 | types of lists: length lists (<a href="#llist">llist</a>), and null |
| 107 | terminated lists (<a href="#zlist">zlist</a>), as described below in |
| 108 | the <a href="#encoding">Encoding Primitives</a>.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 109 | </div> |
| 110 | <!-- _______________________________________________________________________ --> |
| 111 | <div class="doc_subsection"><a name="fields">Fields</a> </div> |
| 112 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 113 | <p>Fields are units of information that LLVM knows how to write atomically. Most |
| 114 | fields have a uniform length or some kind of length indication built into their |
| 115 | encoding. For example, a constant string (array of bytes) is written simply as |
| 116 | the length followed by the characters. Although this is similar to a list, |
| 117 | constant strings are treated atomically and are thus fields.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 118 | <p>Fields use a condensed bit format specific to the type of information |
| 119 | they must contain. As few bits as possible are written for each field. The |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 120 | sections that follow will provide the details on how these fields are |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 121 | written and how the bits are to be interpreted.</p> |
| 122 | </div> |
| 123 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 124 | <div class="doc_subsection"><a name="align">Alignment</a> </div> |
Reid Spencer | 7aa940d | 2004-05-25 15:47:57 +0000 | [diff] [blame] | 125 | <div class="doc_text"> |
Reid Spencer | 267660f | 2004-08-03 20:33:56 +0000 | [diff] [blame] | 126 | <p>To support cross-platform differences, the bytecode file is aligned on |
| 127 | certain boundaries. This means that a small amount of padding (at most 3 |
| 128 | bytes) will be added to ensure that the next entry is aligned to a 32-bit |
| 129 | boundary.</p> |
Chris Lattner | 8dabb50 | 2004-05-25 17:44:58 +0000 | [diff] [blame] | 130 | </div> |
Reid Spencer | 7aa940d | 2004-05-25 15:47:57 +0000 | [diff] [blame] | 131 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 132 | <div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 133 | </div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 134 | <div class="doc_text"> |
| 135 | <p>Most of the values written to LLVM bytecode files are small integers. To |
| 136 | minimize the number of bytes written for these quantities, an encoding scheme |
| 137 | similar to UTF-8 is used to write integer data. The scheme is known as |
| 138 | variable bit rate (vbr) encoding. In this encoding, the high bit of |
| 139 | each byte is used to indicate if more bytes follow. If (byte & |
| 140 | 0x80) is non-zero in any given byte, it means there is another byte |
| 141 | immediately following that also contributes to the value. For the final |
| 142 | byte (byte & 0x80) is false (the high bit is not set). In each byte |
| 143 | only the low seven bits contribute to the value. Consequently 32-bit |
| 144 | quantities can take from one to <em>five</em> bytes to encode. In |
| 145 | general, smaller quantities will encode in fewer bytes, as follows:</p> |
| 146 | <table> |
| 147 | <tbody> |
| 148 | <tr> |
| 149 | <th>Byte #</th> |
| 150 | <th>Significant Bits</th> |
| 151 | <th>Maximum Value</th> |
| 152 | </tr> |
| 153 | <tr> |
| 154 | <td>1</td> |
| 155 | <td>0-6</td> |
| 156 | <td>127</td> |
| 157 | </tr> |
| 158 | <tr> |
| 159 | <td>2</td> |
| 160 | <td>7-13</td> |
| 161 | <td>16,383</td> |
| 162 | </tr> |
| 163 | <tr> |
| 164 | <td>3</td> |
| 165 | <td>14-20</td> |
| 166 | <td>2,097,151</td> |
| 167 | </tr> |
| 168 | <tr> |
| 169 | <td>4</td> |
| 170 | <td>21-27</td> |
| 171 | <td>268,435,455</td> |
| 172 | </tr> |
| 173 | <tr> |
| 174 | <td>5</td> |
| 175 | <td>28-34</td> |
| 176 | <td>34,359,738,367</td> |
| 177 | </tr> |
| 178 | <tr> |
| 179 | <td>6</td> |
| 180 | <td>35-41</td> |
| 181 | <td>4,398,046,511,103</td> |
| 182 | </tr> |
| 183 | <tr> |
| 184 | <td>7</td> |
| 185 | <td>42-48</td> |
| 186 | <td>562,949,953,421,311</td> |
| 187 | </tr> |
| 188 | <tr> |
| 189 | <td>8</td> |
| 190 | <td>49-55</td> |
| 191 | <td>72,057,594,037,927,935</td> |
| 192 | </tr> |
| 193 | <tr> |
| 194 | <td>9</td> |
| 195 | <td>56-62</td> |
| 196 | <td>9,223,372,036,854,775,807</td> |
| 197 | </tr> |
| 198 | <tr> |
| 199 | <td>10</td> |
| 200 | <td>63-69</td> |
| 201 | <td>1,180,591,620,717,411,303,423</td> |
| 202 | </tr> |
| 203 | </tbody> |
| 204 | </table> |
| 205 | <p>Note that in practice, the tenth byte could only encode bit 63 since |
| 206 | the maximum quantity to use this encoding is a 64-bit integer.</p> |
| 207 | <p><em>Signed</em> VBR values are encoded with the standard vbr |
| 208 | encoding, but with the sign bit as the low order bit instead of the |
| 209 | high order bit. This allows small negative quantities to be encoded |
| 210 | efficiently. For example, -3 |
| 211 | is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << |
| 212 | 1) | 0)", emitted with the standard vbr encoding above.</p> |
| 213 | </div> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 214 | <!-- _______________________________________________________________________ --> |
| 215 | <div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div> |
| 216 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 217 | <p>Each field in the bytecode format is encoded into the file using a |
| 218 | small set of primitive formats. The table below defines the encoding |
| 219 | rules for the various primitives used and gives them each a type name. |
| 220 | The type names used in the descriptions of blocks and fields in the <a |
| 221 | href="#details">Detailed Layout</a>next section. Any type name with |
| 222 | the suffix <em>_vbr</em> indicates a quantity that is encoded using |
| 223 | variable bit rate encoding as described above.</p> |
| 224 | <table class="doc_table"> |
| 225 | <tbody> |
| 226 | <tr> |
| 227 | <th><b>Type</b></th> |
| 228 | <th class="td_left"><b>Rule</b></th> |
| 229 | </tr> |
| 230 | <tr> |
| 231 | <td><a name="unsigned"><b>unsigned</b></a></td> |
| 232 | <td class="td_left">A 32-bit unsigned integer that always occupies four |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 233 | consecutive bytes. The unsigned integer is encoded using LSB first |
| 234 | ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the |
| 235 | byte with the lowest file offset (little endian).</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 236 | </tr> |
| 237 | <tr> |
Reid Spencer | 301fe48 | 2004-08-03 20:57:56 +0000 | [diff] [blame] | 238 | <td style="vertical-align: top;"><a name="uint24_vbr"> |
| 239 | <b>uint24_vbr</b></a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 240 | <td style="vertical-align: top; text-align: left;">A 24-bit unsigned |
| 241 | integer that occupies from one to four bytes using variable bit rate |
| 242 | encoding.</td> |
| 243 | </tr> |
| 244 | <tr> |
| 245 | <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 246 | <td class="td_left">A 32-bit unsigned integer that occupies from one to |
| 247 | five bytes using variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 248 | </tr> |
| 249 | <tr> |
| 250 | <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 251 | <td class="td_left">A 64-bit unsigned integer that occupies from one to ten |
| 252 | bytes using variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 253 | </tr> |
| 254 | <tr> |
| 255 | <td><a name="int64_vbr"><b>int64_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 256 | <td class="td_left">A 64-bit signed integer that occupies from one to ten |
| 257 | bytes using the signed variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 258 | </tr> |
| 259 | <tr> |
| 260 | <td><a name="char"><b>char</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 261 | <td class="td_left">A single unsigned character encoded into one byte</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 262 | </tr> |
| 263 | <tr> |
| 264 | <td><a name="bit"><b>bit(n-m)</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 265 | <td class="td_left">A set of bit within some larger integer field. The values |
| 266 | of <code>n</code> and <code>m</code> specify the inclusive range of bits |
| 267 | that define the subfield. The value for <code>m</code> may be omitted if |
| 268 | its the same as <code>n</code>.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 269 | </tr> |
| 270 | <tr> |
| 271 | <td style="vertical-align: top;"><b><a name="float"><b>float</b></a></b></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 272 | <td style="vertical-align: top; text-align: left;">A floating point value encoded |
| 273 | as a 32-bit IEEE value written in little-endian form.<br> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 274 | </td> |
| 275 | </tr> |
| 276 | <tr> |
| 277 | <td style="vertical-align: top;"><b><b><a name="double"><b>double</b></a></b></b></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 278 | <td style="vertical-align: top; text-align: left;">A floating point value encoded |
| 279 | as a64-bit IEEE value written in little-endian form</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 280 | </tr> |
| 281 | <tr> |
| 282 | <td><a name="string"><b>string</b></a></td> |
| 283 | <td class="td_left">A uint32_vbr indicating the type of the |
| 284 | constant string which also includes its length, immediately followed by |
| 285 | the characters of the string. There is no terminating null byte in the |
| 286 | string.</td> |
| 287 | </tr> |
| 288 | <tr> |
| 289 | <td><a name="data"><b>data</b></a></td> |
| 290 | <td class="td_left">An arbitrarily long segment of data to which |
| 291 | no interpretation is implied. This is used for constant initializers.<br> |
| 292 | </td> |
| 293 | </tr> |
| 294 | <tr> |
| 295 | <td><a name="llist"><b>llist(x)</b></a></td> |
| 296 | <td class="td_left">A length list of x. This means the list is |
| 297 | encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the |
| 298 | length of the list, followed by a sequence of that many "x" items. This |
| 299 | implies that the reader should iterate the number of times provided by |
| 300 | the length.</td> |
| 301 | </tr> |
| 302 | <tr> |
| 303 | <td><a name="zlist"><b>zlist(x)</b></a></td> |
| 304 | <td class="td_left">A zero-terminated list of x. This means the |
| 305 | list is encoded as a sequence of an indeterminate number of "x" items, |
| 306 | followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value. |
| 307 | This implies that none of the "x" items can have a zero value (or else |
| 308 | the list terminates).</td> |
| 309 | </tr> |
| 310 | <tr> |
| 311 | <td><a name="block"><b>block</b></a></td> |
| 312 | <td class="td_left">A block of data that is logically related. A |
| 313 | block is an unsigned 32-bit integer that encodes the type of the block |
| 314 | in the low 5 bits and the size of the block in the high 27 bits. The |
| 315 | length does not include the block header or any alignment bytes at the |
| 316 | end of the block. Blocks may compose other blocks. </td> |
| 317 | </tr> |
| 318 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 319 | </table> |
| 320 | </div> |
| 321 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 322 | <div class="doc_subsection"><a name="notation">Field Notation</a> </div> |
| 323 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 324 | <p>In the detailed block and field descriptions that follow, a regex |
| 325 | like notation is used to describe optional and repeated fields. A very |
| 326 | limited subset of regex is used to describe these, as given in the |
| 327 | following table: </p> |
| 328 | <table class="doc_table"> |
| 329 | <tbody> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 330 | <tr> |
| 331 | <th><b>Character</b></th> |
| 332 | <th class="td_left"><b>Meaning</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 333 | </tr> |
| 334 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 335 | <td><b><code>?</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 336 | <td class="td_left">The question mark indicates 0 or 1 |
| 337 | occurrences of the thing preceding it.</td> |
| 338 | </tr> |
| 339 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 340 | <td><b><code>*</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 341 | <td class="td_left">The asterisk indicates 0 or more occurrences |
| 342 | of the thing preceding it.</td> |
| 343 | </tr> |
| 344 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 345 | <td><b><code>+</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 346 | <td class="td_left">The plus sign indicates 1 or more occurrences |
| 347 | of the thing preceding it.</td> |
| 348 | </tr> |
| 349 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 350 | <td><b><code>()</code></b></td> |
| 351 | <td class="td_left">Parentheses are used for grouping.</td> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 352 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 353 | <tr> |
| 354 | <td><b><code>,</code></b></td> |
| 355 | <td class="td_left">The comma separates sequential fields.</td> |
| 356 | </tr> |
| 357 | </tbody> |
| 358 | </table> |
| 359 | <p>So, for example, consider the following specifications:</p> |
| 360 | <div class="doc_code"> |
| 361 | <ol> |
| 362 | <li><code>string?</code></li> |
| 363 | <li><code>(uint32_vbr,uin32_vbr)+</code></li> |
| 364 | <li><code>(unsigned?,uint32_vbr)*</code></li> |
| 365 | <li><code>(llist(unsigned))?</code></li> |
| 366 | </ol> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 367 | </div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 368 | <p>with the following interpretations:</p> |
| 369 | <ol> |
| 370 | <li>An optional string. Matches either nothing or a single string</li> |
| 371 | <li>One or more pairs of uint32_vbr.</li> |
| 372 | <li>Zero or more occurrences of either an unsigned followed by a |
| 373 | uint32_vbr or just a uint32_vbr.</li> |
| 374 | <li>An optional length list of unsigned values.</li> |
| 375 | </ol> |
| 376 | </div> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 377 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 378 | <div class="doc_subsection"><a name="slots">Slots</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 379 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 380 | <p>The bytecode format uses the notion of a "slot" to reference Types |
| 381 | and Values. Since the bytecode file is a <em>direct</em> representation of |
| 382 | LLVM's intermediate representation, there is a need to represent pointers in |
| 383 | the file. Slots are used for this purpose. For example, if one has the following |
| 384 | assembly: |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 385 | </p> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 386 | <div class="doc_code"><code> %MyType = type { int, sbyte }<br> |
| 387 | %MyVar = external global %MyType |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 388 | </code></div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 389 | <p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>. |
| 390 | In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt> |
| 391 | is explicit through the use of C++ pointers. In bytecode, however, there's no |
| 392 | ability to store memory addresses. Instead, we compute and write out |
| 393 | slot numbers for every Type and Value written to the file.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 394 | <p>A slot number is simply an unsigned 32-bit integer encoded in the variable |
| 395 | bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that |
| 396 | low slot numbers are encoded in one byte. Through various bits of magic LLVM |
| 397 | attempts to always keep the slot numbers low. The first attempt is to associate |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 398 | slot numbers with their "type plane". That is, Values of the same type |
| 399 | are written to the bytecode file in a list (sequentially). Their order in |
| 400 | that list determines their slot number. This means that slot #1 doesn't mean |
| 401 | anything unless you also specify for which type you want slot #1. Types are |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 402 | always written to the file first (in the <a href="#globaltypes">Global Type |
| 403 | Pool</a>) and in such a way that both forward and backward references of the |
| 404 | types can often be resolved with a single pass through the type pool. </p> |
Reid Spencer | c4a8d39 | 2007-01-31 00:26:08 +0000 | [diff] [blame] | 405 | <p>In summary then, a slot number can be thought of as just a vbr encoded index |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 406 | into a list of Type* or Value*. To keep slot numbers low, Value* are indexed by |
| 407 | two slot numbers: the "type plane index" (type slot) and the "value index" |
| 408 | (value slot).</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 409 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 410 | <!-- *********************************************************************** --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 411 | <div class="doc_section"> <a name="general">General Structure</a> </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 412 | <!-- *********************************************************************** --> |
| 413 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 414 | <p>This section provides the general structure of the LLVM bytecode |
| 415 | file format. The bytecode file format requires blocks to be in a |
| 416 | certain order and nested in a particular way so that an LLVM module can |
| 417 | be constructed efficiently from the contents of the file. This ordering |
| 418 | defines a general structure for bytecode files as shown below. The |
| 419 | table below shows the order in which all block types may appear. Please |
| 420 | note that some of the blocks are optional and some may be repeated. The |
| 421 | structure is fairly loose because optional blocks, if empty, are |
| 422 | completely omitted from the file.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 423 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 424 | <tbody> |
| 425 | <tr> |
| 426 | <th>ID</th> |
| 427 | <th>Parent</th> |
| 428 | <th>Optional?</th> |
| 429 | <th>Repeated?</th> |
| 430 | <th>Level</th> |
| 431 | <th>Block Type</th> |
| 432 | <th>Description</th> |
| 433 | </tr> |
| 434 | <tr> |
| 435 | <td>N/A</td> |
| 436 | <td>File</td> |
| 437 | <td>No</td> |
| 438 | <td>No</td> |
| 439 | <td>0</td> |
| 440 | <td class="td_left"><a href="#signature">Signature</a></td> |
| 441 | <td class="td_left">This contains the file signature (magic |
| 442 | number) that identifies the file as LLVM bytecode.</td> |
| 443 | </tr> |
| 444 | <tr> |
| 445 | <td>0x01</td> |
| 446 | <td>File</td> |
| 447 | <td>No</td> |
| 448 | <td>No</td> |
| 449 | <td>0</td> |
| 450 | <td class="td_left"><a href="#module">Module</a></td> |
| 451 | <td class="td_left">This is the top level block in a bytecode |
| 452 | file. It contains all the other blocks. </td> |
| 453 | </tr> |
| 454 | <tr> |
| 455 | <td>0x06</td> |
| 456 | <td>Module</td> |
| 457 | <td>No</td> |
| 458 | <td>No</td> |
| 459 | <td>1</td> |
| 460 | <td class="td_left"> <a href="#globaltypes">Global Type Pool</a></td> |
| 461 | <td class="td_left">This block contains all the global (module) |
| 462 | level types.</td> |
| 463 | </tr> |
| 464 | <tr> |
| 465 | <td>0x05</td> |
| 466 | <td>Module</td> |
| 467 | <td>No</td> |
| 468 | <td>No</td> |
| 469 | <td>1</td> |
| 470 | <td class="td_left"> <a href="#globalinfo">Module Globals Info</a></td> |
| 471 | <td class="td_left">This block contains the type, constness, and |
| 472 | linkage for each of the global variables in the module. It also |
| 473 | contains the type of the functions and the constant initializers.</td> |
| 474 | </tr> |
| 475 | <tr> |
| 476 | <td>0x03</td> |
| 477 | <td>Module</td> |
| 478 | <td>Yes</td> |
| 479 | <td>No</td> |
| 480 | <td>1</td> |
| 481 | <td class="td_left"> <a href="#constantpool">Module Constant Pool</a></td> |
| 482 | <td class="td_left">This block contains all the global constants |
| 483 | except function arguments, global values and constant strings.</td> |
| 484 | </tr> |
| 485 | <tr> |
| 486 | <td>0x02</td> |
| 487 | <td>Module</td> |
| 488 | <td>Yes</td> |
| 489 | <td>Yes</td> |
| 490 | <td>1</td> |
| 491 | <td class="td_left"> <a href="#functiondefs">Function Definitions</a>*</td> |
| 492 | <td class="td_left">One function block is written for each |
| 493 | function in the module. The function block contains the instructions, |
Reid Spencer | c4a8d39 | 2007-01-31 00:26:08 +0000 | [diff] [blame] | 494 | type constant pool, and symbol table for the function.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 495 | </tr> |
| 496 | <tr> |
| 497 | <td>0x03</td> |
| 498 | <td>Function</td> |
| 499 | <td>Yes</td> |
| 500 | <td>No</td> |
| 501 | <td>2</td> |
| 502 | <td class="td_left"> <a |
| 503 | href="#constantpool">Function Constant Pool</a></td> |
| 504 | <td class="td_left">Any constants (including types) used solely |
| 505 | within the function are emitted here in the function constant pool. </td> |
| 506 | </tr> |
| 507 | <tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 508 | <td>0x07</td> |
| 509 | <td>Function</td> |
| 510 | <td>No</td> |
| 511 | <td>No</td> |
| 512 | <td>2</td> |
| 513 | <td class="td_left"> <a |
| 514 | href="#instructionlist">Instruction List</a></td> |
| 515 | <td class="td_left">This block contains all the instructions of |
| 516 | the function. The basic blocks are inferred by terminating |
| 517 | instructions. </td> |
| 518 | </tr> |
| 519 | <tr> |
| 520 | <td>0x04</td> |
| 521 | <td>Function</td> |
| 522 | <td>Yes</td> |
| 523 | <td>No</td> |
| 524 | <td>2</td> |
| 525 | <td class="td_left"> <a |
| 526 | href="#symtab">Function Symbol Table</a></td> |
| 527 | <td class="td_left">This symbol table provides the names for the |
| 528 | function specific values used (basic block labels mostly).</td> |
| 529 | </tr> |
| 530 | <tr> |
| 531 | <td>0x04</td> |
| 532 | <td>Module</td> |
| 533 | <td>Yes</td> |
| 534 | <td>No</td> |
| 535 | <td>1</td> |
| 536 | <td class="td_left"> <a href="#symtab">Module Symbol Table</a></td> |
| 537 | <td class="td_left">This symbol table provides the names for the |
| 538 | various entries in the file that are not function specific (global |
| 539 | vars, and functions mostly).</td> |
| 540 | </tr> |
| 541 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 542 | </table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 543 | <p>Use the links in the table for details about the contents of each of |
| 544 | the block types.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 545 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 546 | <!-- *********************************************************************** --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 547 | <div class="doc_section"> <a name="blockdefs">Block Definitions</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 548 | <!-- *********************************************************************** --> |
| 549 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 550 | <p>This section provides the detailed layout of the individual block |
| 551 | types in the LLVM bytecode file format. </p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 552 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 553 | <!-- _______________________________________________________________________ --> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 554 | <div class="doc_subsection"><a name="signature">Signature Block</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 555 | <div class="doc_text"> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 556 | <p>The signature occurs in every LLVM bytecode file and is always first. |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 557 | It simply provides a few bytes of data to identify the file as being an LLVM |
| 558 | bytecode file. This block is always four bytes in length and differs from the |
| 559 | other blocks because there is no identifier and no block length at the start |
| 560 | of the block. Essentially, this block is just the "magic number" for the file. |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 561 | </p> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 562 | <p>There are two types of signatures for LLVM bytecode: uncompressed and |
| 563 | compressed as shown in the table below. </p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 564 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 565 | <tbody> |
| 566 | <tr> |
| 567 | <th><b>Type</b></th> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 568 | <th class="td_left"><b>Uncompressed</b></th> |
| 569 | <th class="td_left"><b>Compressed</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 570 | </tr> |
| 571 | <tr> |
| 572 | <td><a href="#char">char</a></td> |
| 573 | <td class="td_left">Constant "l" (0x6C)</td> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 574 | <td class="td_left">Constant "l" (0x6C)</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 575 | </tr> |
| 576 | <tr> |
| 577 | <td><a href="#char">char</a></td> |
| 578 | <td class="td_left">Constant "l" (0x6C)</td> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 579 | <td class="td_left">Constant "l" (0x6C)</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 580 | </tr> |
| 581 | <tr> |
| 582 | <td><a href="#char">char</a></td> |
| 583 | <td class="td_left">Constant "v" (0x76)</td> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 584 | <td class="td_left">Constant "v" (0x76)</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 585 | </tr> |
| 586 | <tr> |
| 587 | <td><a href="#char">char</a></td> |
| 588 | <td class="td_left">Constant "m" (0x6D)</td> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 589 | <td class="td_left">Constant "c" (0x63)</td> |
| 590 | </tr> |
| 591 | <tr> |
| 592 | <td><a href="#char">char</a></td> |
| 593 | <td class="td_left">N/A</td> |
| 594 | <td class="td_left">'0'=null,'1'=gzip,'2'=bzip2</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 595 | </tr> |
| 596 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 597 | </table> |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 598 | <p>In other words, the uncompressed signature is just the characters 'llvm' |
| 599 | while the compressed signature is the characters 'llvc' followed by an ascii |
| 600 | digit ('0', '1', or '2') that indicates the kind of compression used. A value of |
| 601 | '0' indicates that null compression was used. This can happen when compression |
| 602 | was requested on a platform that wasn't configured for gzip or bzip2. A value of |
| 603 | '1' means that the rest of the file is compressed using the gzip algorithm and |
| 604 | should be uncompressed before interpretation. A value of '2' means that the rest |
| 605 | of the file is compressed using the bzip2 algorithm and should be uncompressed |
| 606 | before interpretation. In all cases, the data resulting from uncompression |
| 607 | should be interpreted as if it occurred immediately after the 'llvm' |
| 608 | signature (i.e. the uncompressed data begins with the |
| 609 | <a href="#module">Module Block</a></p> |
| 610 | <p><b>NOTE:</b> As of LLVM 1.4, all bytecode files produced by the LLVM tools |
Reid Spencer | a4213b2 | 2004-11-08 09:10:50 +0000 | [diff] [blame] | 611 | are compressed by default. To disable compression, pass the |
Reid Spencer | da794e7 | 2004-11-08 08:55:21 +0000 | [diff] [blame] | 612 | <tt>--disable-compression</tt> option to the tool, if it supports it. |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 613 | </div> |
| 614 | <!-- _______________________________________________________________________ --> |
| 615 | <div class="doc_subsection"><a name="module">Module Block</a> </div> |
| 616 | <div class="doc_text"> |
| 617 | <p>The module block contains a small pre-amble and all the other blocks in |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 618 | the file. The table below shows the structure of the module block. Note that it |
| 619 | only provides the module identifier, size of the module block, and the format |
| 620 | information. Everything else is contained in other blocks, described in other |
| 621 | sections.</p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 622 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 623 | <tbody> |
| 624 | <tr> |
| 625 | <th><b>Type</b></th> |
| 626 | <th class="td_left"><b>Field Description</b></th> |
| 627 | </tr> |
| 628 | <tr> |
Reid Spencer | 5bc74d5 | 2004-08-16 19:24:36 +0000 | [diff] [blame] | 629 | <td><a href="#unsigned">unsigned</a><br></td> |
| 630 | <td class="td_left"><a href="#mod_header">Module Block Identifier |
| 631 | (0x01)</a></td> |
| 632 | </tr> |
| 633 | <tr> |
| 634 | <td><a href="#unsigned">unsigned</a></td> |
| 635 | <td class="td_left"><a href="#mod_header">Module Block Size</a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 636 | </tr> |
| 637 | <tr> |
| 638 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 639 | <td class="td_left"><a href="#format">Format Information</a></td> |
| 640 | </tr> |
| 641 | <tr> |
| 642 | <td><a href="#block">block</a></td> |
| 643 | <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td> |
| 644 | </tr> |
| 645 | <tr> |
| 646 | <td><a href="#block">block</a></td> |
| 647 | <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td> |
| 648 | </tr> |
| 649 | <tr> |
| 650 | <td><a href="#block">block</a></td> |
| 651 | <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td> |
| 652 | </tr> |
| 653 | <tr> |
| 654 | <td><a href="#block">block</a>*</td> |
| 655 | <td class="td_left"><a href="#functiondefs">Function Definitions</a></td> |
| 656 | </tr> |
| 657 | <tr> |
| 658 | <td><a href="#block">block</a></td> |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 659 | <td class="td_left"><a href="#symtab">Module Symbol Table</a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 660 | </tr> |
| 661 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 662 | </table> |
| 663 | </div> |
Reid Spencer | 5bc74d5 | 2004-08-16 19:24:36 +0000 | [diff] [blame] | 664 | |
| 665 | <!-- _______________________________________________________________________ --> |
| 666 | <div class="doc_subsubsection"><a name="mod_header">Module Block Header</a></div> |
| 667 | <div class="doc_text"> |
| 668 | <p>The block header for the module block uses a longer format than the other |
| 669 | blocks in a bytecode file. Specifically, instead of encoding the type and size |
| 670 | of the block into a 32-bit integer with 5-bits for type and 27-bits for size, |
| 671 | the module block header uses two 32-bit unsigned values, one for type, and one |
| 672 | for size. While the 2<sup>27</sup> byte limit on block size is sufficient for the blocks |
| 673 | contained in the module, it isn't sufficient for the module block itself |
| 674 | because we want to ensure that bytecode files as large as 2<sup>32</sup> bytes |
| 675 | are possible. For this reason, the module block (and only the module block) |
| 676 | uses a long format header.</p> |
| 677 | </div> |
| 678 | |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 679 | <!-- _______________________________________________________________________ --> |
| 680 | <div class="doc_subsubsection"><a name="format">Format Information</a></div> |
| 681 | <div class="doc_text"> |
Owen Anderson | d753fbc | 2007-01-27 19:23:25 +0000 | [diff] [blame] | 682 | <p>The format information field is encoded into a <a href="#uint32_vbr">uint32_vbr</a>.</p> |
| 683 | |
| 684 | <p>Of particular note, the bytecode format number is simply a 32-bit |
John Criswell | 611a8d1 | 2005-10-24 16:20:10 +0000 | [diff] [blame] | 685 | monotonically increasing integer that identifies the version of the bytecode |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 686 | format (which is not directly related to the LLVM release number). The |
| 687 | bytecode versions defined so far are (note that this document only |
Owen Anderson | d753fbc | 2007-01-27 19:23:25 +0000 | [diff] [blame] | 688 | describes the latest version, 2.0):</p> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 689 | <ul> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 690 | <li>#0: LLVM 1.0 & 1.1</li> |
| 691 | <li>#1: LLVM 1.2</li> |
| 692 | <li>#2: LLVM 1.2.5 (not released)</li> |
John Criswell | 1d9be9e | 2005-10-24 17:10:57 +0000 | [diff] [blame] | 693 | <li>#3: LLVM 1.3</li> |
| 694 | <li>#4: LLVM 1.3.x (not released)</li> |
Owen Anderson | d753fbc | 2007-01-27 19:23:25 +0000 | [diff] [blame] | 695 | <li>#5: LLVM 1.4 through 1.8</li> |
| 696 | <li>#6: LLVM 1.9</li> |
| 697 | <li>#7: LLVM 2.0 and newer</li> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 698 | </ul> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 699 | </div> |
| 700 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 701 | <div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 702 | <div class="doc_text"> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 703 | <p>The global type pool consists of type definitions. Their order of appearance |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 704 | in the file determines their type slot number (0 based). Slot numbers are |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 705 | used to replace pointers in the intermediate representation. Each slot number |
| 706 | uniquely identifies one entry in a type plane (a collection of values of the |
| 707 | same type). Since all values have types and are associated with the order in |
| 708 | which the type pool is written, the global type pool <em>must</em> be written |
| 709 | as the first block of a module. If it is not, attempts to read the file will |
| 710 | fail because both forward and backward type resolution will not be possible.</p> |
| 711 | <p>The type pool is simply a list of type definitions, as shown in the |
| 712 | table below.</p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 713 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 714 | <tbody> |
| 715 | <tr> |
| 716 | <th><b>Type</b></th> |
| 717 | <th class="td_left"><b>Field Description</b></th> |
| 718 | </tr> |
| 719 | <tr> |
| 720 | <td><a href="#unsigned">block</a></td> |
| 721 | <td class="td_left">Type Pool Identifier (0x06) + Size<br> |
| 722 | </td> |
| 723 | </tr> |
| 724 | <tr> |
| 725 | <td><a href="#llist">llist</a>(<a href="#type">type</a>)</td> |
| 726 | <td class="td_left">A length list of type definitions.</td> |
| 727 | </tr> |
| 728 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 729 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 730 | </div> |
| 731 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 732 | <div class="doc_subsubsection"><a name="type">Type Definitions</a></div> |
| 733 | <div class="doc_text"> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 734 | <p>Types in the type pool are defined using a different format for each kind |
| 735 | of type, as given in the following sections.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 736 | <h3>Primitive Types</h3> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 737 | <p>The primitive types encompass the basic integer and floating point |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 738 | types. They are encoded simply as their TypeID.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 739 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 740 | <tbody> |
| 741 | <tr> |
| 742 | <th><b>Type</b></th> |
| 743 | <th class="td_left"><b>Description</b></th> |
| 744 | </tr> |
| 745 | <tr> |
| 746 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 747 | <td class="td_left">Type ID for the primitive types (values 1 to |
| 748 | 11) <sup>1</sup></td> |
| 749 | </tr> |
| 750 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 751 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 752 | Notes: |
| 753 | <ol> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 754 | <li>The values for the Type IDs for the primitive types are provided |
| 755 | by the definition of the <code>llvm::Type::TypeID</code> enumeration |
| 756 | in <code>include/llvm/Type.h</code>. The enumeration gives the |
| 757 | following mapping: |
| 758 | <ol> |
| 759 | <li>bool</li> |
| 760 | <li>ubyte</li> |
| 761 | <li>sbyte</li> |
| 762 | <li>ushort</li> |
| 763 | <li>short</li> |
| 764 | <li>uint</li> |
| 765 | <li>int</li> |
| 766 | <li>ulong</li> |
| 767 | <li>long</li> |
| 768 | <li>float</li> |
| 769 | <li>double</li> |
| 770 | </ol> |
| 771 | </li> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 772 | </ol> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 773 | <h3>Function Types</h3> |
| 774 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 775 | <tbody> |
| 776 | <tr> |
| 777 | <th><b>Type</b></th> |
| 778 | <th class="td_left"><b>Description</b></th> |
| 779 | </tr> |
| 780 | <tr> |
| 781 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 782 | <td class="td_left">Type ID for function types (13)</td> |
| 783 | </tr> |
| 784 | <tr> |
| 785 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 786 | <td class="td_left">Type slot number of function's return type.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 787 | </tr> |
| 788 | <tr> |
| 789 | <td><a href="#llist">llist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 790 | <td class="td_left">Type slot number of each argument's type.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 791 | </tr> |
| 792 | <tr> |
| 793 | <td><a href="#uint32_vbr">uint32_vbr</a>?</td> |
| 794 | <td class="td_left">Value 0 if this is a varargs function, |
| 795 | missing otherwise.</td> |
| 796 | </tr> |
| 797 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 798 | </table> |
| 799 | <h3>Structure Types</h3> |
| 800 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 801 | <tbody> |
| 802 | <tr> |
| 803 | <th><b>Type</b></th> |
| 804 | <th class="td_left"><b>Description</b></th> |
| 805 | </tr> |
| 806 | <tr> |
| 807 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 808 | <td class="td_left">Type ID for structure types (14)</td> |
| 809 | </tr> |
| 810 | <tr> |
| 811 | <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
| 812 | <td class="td_left">Slot number of each of the element's fields.</td> |
| 813 | </tr> |
| 814 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 815 | </table> |
| 816 | <h3>Array Types</h3> |
| 817 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 818 | <tbody> |
| 819 | <tr> |
| 820 | <th><b>Type</b></th> |
| 821 | <th class="td_left"><b>Description</b></th> |
| 822 | </tr> |
| 823 | <tr> |
| 824 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 825 | <td class="td_left">Type ID for Array Types (15)</td> |
| 826 | </tr> |
| 827 | <tr> |
| 828 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 829 | <td class="td_left">Type slot number of array's element type.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 830 | </tr> |
| 831 | <tr> |
| 832 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 833 | <td class="td_left">The number of elements in the array.</td> |
| 834 | </tr> |
| 835 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 836 | </table> |
| 837 | <h3>Pointer Types</h3> |
| 838 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 839 | <tbody> |
| 840 | <tr> |
| 841 | <th><b>Type</b></th> |
| 842 | <th class="td_left"><b>Description</b></th> |
| 843 | </tr> |
| 844 | <tr> |
| 845 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 846 | <td class="td_left">Type ID For Pointer Types (16)</td> |
| 847 | </tr> |
| 848 | <tr> |
| 849 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 850 | <td class="td_left">Type slot number of pointer's element type.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 851 | </tr> |
| 852 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 853 | </table> |
| 854 | <h3>Opaque Types</h3> |
| 855 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 856 | <tbody> |
| 857 | <tr> |
| 858 | <th><b>Type</b></th> |
| 859 | <th class="td_left"><b>Description</b></th> |
| 860 | </tr> |
| 861 | <tr> |
| 862 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 863 | <td class="td_left">Type ID For Opaque Types (17)</td> |
| 864 | </tr> |
| 865 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 866 | </table> |
Brian Gaeke | 715c90b | 2004-08-20 06:00:58 +0000 | [diff] [blame] | 867 | <h3>Packed Types</h3> |
| 868 | <table> |
| 869 | <tbody> |
| 870 | <tr> |
| 871 | <th><b>Type</b></th> |
| 872 | <th class="td_left"><b>Description</b></th> |
| 873 | </tr> |
| 874 | <tr> |
| 875 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 876 | <td class="td_left">Type ID for Packed Types (18)</td> |
| 877 | </tr> |
| 878 | <tr> |
| 879 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 880 | <td class="td_left">Slot number of packed vector's element type.</td> |
| 881 | </tr> |
| 882 | <tr> |
| 883 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 884 | <td class="td_left">The number of elements in the packed vector.</td> |
| 885 | </tr> |
| 886 | </tbody> |
| 887 | </table> |
Andrew Lenharth | 8894255 | 2006-12-08 17:50:05 +0000 | [diff] [blame] | 888 | <h3>Packed Structure Types</h3> |
| 889 | <table> |
| 890 | <tbody> |
| 891 | <tr> |
| 892 | <th><b>Type</b></th> |
| 893 | <th class="td_left"><b>Description</b></th> |
| 894 | </tr> |
| 895 | <tr> |
| 896 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 897 | <td class="td_left">Type ID for packed structure types (19)</td> |
| 898 | </tr> |
| 899 | <tr> |
| 900 | <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
| 901 | <td class="td_left">Slot number of each of the element's fields.</td> |
| 902 | </tr> |
| 903 | </tbody> |
| 904 | </table> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 905 | </div> |
| 906 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 907 | <div class="doc_subsection"><a name="globalinfo">Module Global Info</a> |
| 908 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 909 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 910 | <p>The module global info block contains the definitions of all global |
| 911 | variables including their initializers and the <em>declaration</em> of |
| 912 | all functions. The format is shown in the table below:</p> |
| 913 | <table> |
| 914 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 915 | <tr> |
| 916 | <th><b>Type</b></th> |
| 917 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 918 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 919 | <tr> |
| 920 | <td><a href="#block">block</a></td> |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 921 | <td class="td_left">Module global info identifier (0x05) + size</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 922 | </tr> |
| 923 | <tr> |
| 924 | <td><a href="#zlist">zlist</a>(<a href="#globalvar">globalvar</a>)</td> |
| 925 | <td class="td_left">A zero terminated list of global var |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 926 | definitions occurring in the module.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 927 | </tr> |
| 928 | <tr> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 929 | <td><a href="#zlist">zlist</a>(<a href="#funcfield">funcfield</a>)</td> |
| 930 | <td class="td_left">A zero terminated list of function definitions |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 931 | occurring in the module.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 932 | </tr> |
| 933 | <tr> |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 934 | <td><a href="#llist">llist</a>(<a href="#string">string</a>)</td> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 935 | <td class="td_left">A length list |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 936 | of strings that specify the names of the libraries that this module |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 937 | depends upon.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 938 | </tr> |
| 939 | <tr> |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 940 | <td><a href="#string">string</a></td> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 941 | <td class="td_left">The target |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 942 | triple for the module (blank means no target triple specified, i.e. a |
Owen Anderson | d753fbc | 2007-01-27 19:23:25 +0000 | [diff] [blame] | 943 | platform-independent module).</td> |
| 944 | </tr> |
| 945 | <tr> |
| 946 | <td><a href="#string">string</a></td> |
| 947 | <td class="td_left">The data layout string describing the endianness, pointer size, and |
| 948 | type alignments for which the module was written (blank means no data layout specified, i.e. a platform-independent module).</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 949 | </tr> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 950 | <tr> |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 951 | <td><a href="#llist">llist</a>(<a href="#string">string</a>)</td> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 952 | <td class="td_left">A length list |
| 953 | of strings that defines a table of section strings for globals. A global's |
Chris Lattner | 45f5051 | 2006-01-23 23:38:09 +0000 | [diff] [blame] | 954 | SectionID is an index into this table.</td> |
| 955 | </tr> |
| 956 | <tr> |
| 957 | <td><a href="#string">string</a></td> |
| 958 | <td class="td_left">The inline asm block for this module.</td> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 959 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 960 | </tbody> |
| 961 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 962 | </div> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 963 | |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 964 | <!-- _______________________________________________________________________ --> |
| 965 | <div class="doc_subsubsection"><a name="globalvar">Global Variable Field</a> |
| 966 | </div> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 967 | |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 968 | <div class="doc_text"> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 969 | |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 970 | <p>Global variables are written using an <a href="#uint32_vbr">uint32_vbr</a> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 971 | that encodes information about the global variable, an optional extension vbr, |
| 972 | and a an optional initializers for the global var.</p> |
| 973 | |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 974 | <p>The table below provides the bit layout of the first <a |
| 975 | href="#uint32_vbr">uint32_vbr</a> that describes the global variable.</p> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 976 | |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 977 | <table> |
| 978 | <tbody> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 979 | <tr> |
| 980 | <th><b>Type</b></th> |
| 981 | <th class="td_left"><b>Description</b></th> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 982 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 983 | <tr> |
| 984 | <td><a href="#bit">bit(0)</a></td> |
| 985 | <td class="td_left">Is constant?</td> |
| 986 | </tr> |
| 987 | <tr> |
| 988 | <td><a href="#bit">bit(1)</a></td> |
| 989 | <td class="td_left">Has initializer? Note that this bit |
| 990 | determines whether the constant initializer field (described below) |
| 991 | follows. </td> |
| 992 | </tr> |
| 993 | <tr> |
| 994 | <td><a href="#bit">bit(2-4)</a></td> |
| 995 | <td class="td_left">Linkage type: 0=External, 1=Weak, |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 996 | 2=Appending, 3=Internal, 4=LinkOnce, 5=DllImport, |
| 997 | 6=DllExport, 7=ExternWeak</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 998 | </tr> |
| 999 | <tr> |
| 1000 | <td><a href="#bit">bit(5-31)</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1001 | <td class="td_left">Type slot number of type for the global variable.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1002 | </tr> |
| 1003 | </tbody> |
| 1004 | </table> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1005 | |
| 1006 | <p>When the Linkage type is set to 3 (internal) and the initializer field is set |
| 1007 | to 0 (an invalid combination), an extension word follows the first <a |
| 1008 | href="#uint32_vbr">uint32_vbr</a> which encodes the real linkage and init flag, |
| 1009 | and can includes more information:</p> |
| 1010 | |
| 1011 | <table> |
| 1012 | <tbody> |
| 1013 | <tr> |
| 1014 | <th><b>Type</b></th> |
| 1015 | <th class="td_left"><b>Description</b></th> |
| 1016 | </tr> |
| 1017 | <tr> |
| 1018 | <td><a href="#bit">bit(0)</a></td> |
| 1019 | <td class="td_left">Has initializer? Indicates the real value of the "Has |
| 1020 | initializer" field for the global. </td> |
| 1021 | </tr> |
| 1022 | <tr> |
| 1023 | <td><a href="#bit">bit(2-4)</a></td> |
| 1024 | <td class="td_left">Linkage type: Indicates the real value of the "linkage |
| 1025 | type" field for the global.</td> |
| 1026 | </tr> |
| 1027 | <tr> |
| 1028 | <td><a href="#bit">bit(4-8)</a></td> |
| 1029 | <td class="td_left">The log-base-2 of the alignment for the global.</td> |
| 1030 | </tr> |
| 1031 | <tr> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1032 | <td><a href="#bit">bit(9)</a></td> |
| 1033 | <td class="td_left">If this bit is set, a SectionID follows this vbr.</td> |
| 1034 | </tr> |
| 1035 | <tr> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1036 | <td><a href="#bit">bit(10-12)</a></td> |
| 1037 | <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td> |
| 1038 | </tr> |
| 1039 | <tr> |
| 1040 | <td><a href="#bit">bit(13-31)</a></td> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1041 | <td class="td_left">Currently unassigned.</td> |
| 1042 | </tr> |
| 1043 | </tbody> |
| 1044 | </table> |
| 1045 | |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1046 | <p>If the SectionID bit is set above, the following field is included:</p> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1047 | |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1048 | <table> |
| 1049 | <tbody> |
| 1050 | <tr> |
| 1051 | <th><b>Type</b></th> |
| 1052 | <th class="td_left"><b>Description</b></th> |
| 1053 | </tr> |
| 1054 | <tr> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1055 | <td><a href="#uint32_vbr">uint32_vbr</a> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1056 | </td> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1057 | <td class="td_left">An optional section ID number, specifying the string |
| 1058 | to use for the section of the global. This an index (+1) of an entry |
| 1059 | into the SectionID llist in the <a href="#globalinfo">Module Global |
| 1060 | Info</a> block. If this value is 0 or not present, the global has an |
| 1061 | empty section string.</td> |
| 1062 | </tr> |
| 1063 | </tbody> |
| 1064 | </table> |
| 1065 | |
| 1066 | <p>If the "Has initializer" field is set, the following field is included:</p> |
| 1067 | |
| 1068 | <table> |
| 1069 | <tbody> |
| 1070 | <tr> |
| 1071 | <th><b>Type</b></th> |
| 1072 | <th class="td_left"><b>Description</b></th> |
| 1073 | </tr> |
| 1074 | <tr> |
| 1075 | <td><a href="#uint32_vbr">uint32_vbr</a> |
| 1076 | </td> |
| 1077 | <td class="td_left">An optional value slot number for the global |
| 1078 | variable's constant initializer.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1079 | </tr> |
| 1080 | </tbody> |
| 1081 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1082 | </div> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1083 | |
| 1084 | <!-- _______________________________________________________________________ --> |
| 1085 | <div class="doc_subsubsection"><a name="funcfield">Function Field</a> |
| 1086 | </div> |
| 1087 | <div class="doc_text"> |
| 1088 | <p>Functions are written using an <a href="#uint32_vbr">uint32_vbr</a> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1089 | that encodes information about the function and a set of flags. If needed, |
| 1090 | an extension word may follow this first field.</p> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1091 | |
| 1092 | <p>The table below provides the bit layout of the <a |
| 1093 | href="#uint32_vbr">uint32_vbr</a> that describes the function.</p> |
| 1094 | |
| 1095 | <table> |
| 1096 | <tbody> |
| 1097 | <tr> |
| 1098 | <th><b>Type</b></th> |
| 1099 | <th class="td_left"><b>Description</b></th> |
| 1100 | </tr> |
| 1101 | <tr> |
Chris Lattner | ced6222 | 2004-11-15 22:54:50 +0000 | [diff] [blame] | 1102 | <td><a href="#bit">bit(0-3)</a></td> |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1103 | <td class="td_left"> |
Chris Lattner | 52942b5 | 2005-11-06 07:48:11 +0000 | [diff] [blame] | 1104 | Encodes the calling convention number of the function. The |
Chris Lattner | bad10ee | 2005-05-06 22:57:40 +0000 | [diff] [blame] | 1105 | CC number of the function is the value of this field minus one. |
| 1106 | </td> |
Chris Lattner | ced6222 | 2004-11-15 22:54:50 +0000 | [diff] [blame] | 1107 | </tr> |
| 1108 | <tr> |
| 1109 | <td><a href="#bit">bit(4)</a></td> |
| 1110 | <td class="td_left">If this bit is set to 1, the indicated function is |
| 1111 | external, and there is no <a href="#functiondefs">Function Definiton |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 1112 | Block</a> in the bytecode file for the function. If the function is |
| 1113 | external and has <tt>dllimport or extern_weak</tt> linkage additional |
| 1114 | field in the extension word is used to indicate the actual linkage |
| 1115 | type.</td> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1116 | </tr> |
| 1117 | <tr> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1118 | <td><a href="#bit">bit(5-30)</a></td> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1119 | <td class="td_left">Type slot number of type for the function.</td> |
| 1120 | </tr> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 1121 | <tr> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1122 | <td><a href="#bit">bit(31)</a></td> |
| 1123 | <td class="td_left">Indicates whether an extension word follows.</td> |
| 1124 | </tr> |
| 1125 | </tbody> |
| 1126 | </table> |
| 1127 | |
| 1128 | <p>If bit(31) is set, an additional <a href="#uint32_vbr">uint32_vbr</a> word |
| 1129 | follows with the following fields:</p> |
| 1130 | |
| 1131 | <table> |
| 1132 | <tbody> |
| 1133 | <tr> |
| 1134 | <th><b>Type</b></th> |
| 1135 | <th class="td_left"><b>Description</b></th> |
| 1136 | </tr> |
| 1137 | <tr> |
| 1138 | <td><a href="#bit">bit(0-4)</a></td> |
| 1139 | <td class="td_left">The log-base-2 of the alignment for the function.</td> |
| 1140 | </tr> |
| 1141 | <tr> |
Chris Lattner | 52942b5 | 2005-11-06 07:48:11 +0000 | [diff] [blame] | 1142 | <td><a href="#bit">bit(5-9)</a></td> |
| 1143 | <td class="td_left">The top nibble of the calling convention.</td> |
| 1144 | </tr> |
| 1145 | <tr> |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1146 | <td><a href="#bit">bit(10)</a></td> |
| 1147 | <td class="td_left">If this bit is set, a SectionID follows this vbr.</td> |
| 1148 | </tr> |
| 1149 | <tr> |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 1150 | <td><a href="#bit">bit(11-12)</a></td> |
| 1151 | <td class="td_left">Linkage type for external functions. 0 - External |
| 1152 | linkage, 1 - DLLImport linkage, 2 - External weak linkage.</td> |
| 1153 | </tr> |
| 1154 | <tr> |
| 1155 | <td><a href="#bit">bit(13-31)</a></td> |
Chris Lattner | afedcb3 | 2005-11-06 07:20:25 +0000 | [diff] [blame] | 1156 | <td class="td_left">Currently unassigned.</td> |
| 1157 | </tr> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1158 | </tbody> |
| 1159 | </table> |
| 1160 | |
Chris Lattner | 767d6ba | 2005-11-12 01:46:21 +0000 | [diff] [blame] | 1161 | <p>If the SectionID bit is set above, the following field is included:</p> |
| 1162 | |
| 1163 | <table> |
| 1164 | <tbody> |
| 1165 | <tr> |
| 1166 | <th><b>Type</b></th> |
| 1167 | <th class="td_left"><b>Description</b></th> |
| 1168 | </tr> |
| 1169 | <tr> |
| 1170 | <td><a href="#uint32_vbr">uint32_vbr</a> |
| 1171 | </td> |
| 1172 | <td class="td_left">An optional section ID number, specifying the string |
| 1173 | to use for the section of the function. This an index (+1) of an entry |
| 1174 | into the SectionID llist in the <a href="#globalinfo">Module Global |
| 1175 | Info</a> block. If this value is 0 or not present, the function has an |
| 1176 | empty section string.</td> |
| 1177 | </tr> |
| 1178 | </tbody> |
| 1179 | </table> |
| 1180 | |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1181 | </div> |
| 1182 | |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1183 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1184 | <div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1185 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1186 | <p>A constant pool defines as set of constant values. There are |
| 1187 | actually two types of constant pool blocks: one for modules and one for |
| 1188 | functions. For modules, the block begins with the constant strings |
| 1189 | encountered anywhere in the module. For functions, the block begins |
| 1190 | with types only encountered in the function. In both cases the header |
| 1191 | is identical. The tables that follow, show the header, module constant |
| 1192 | pool preamble, function constant pool preamble, and the part common to |
| 1193 | both function and module constant pools.</p> |
| 1194 | <p><b>Common Block Header</b></p> |
| 1195 | <table> |
| 1196 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1197 | <tr> |
| 1198 | <th><b>Type</b></th> |
| 1199 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1200 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1201 | <tr> |
| 1202 | <td><a href="#block">block</a></td> |
| 1203 | <td class="td_left">Constant pool identifier (0x03) + size<br> |
| 1204 | </td> |
| 1205 | </tr> |
| 1206 | </tbody> |
| 1207 | </table> |
| 1208 | <p><b>Module Constant Pool Preamble (constant strings)</b></p> |
| 1209 | <table> |
| 1210 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1211 | <tr> |
| 1212 | <th><b>Type</b></th> |
| 1213 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1214 | </tr> |
| 1215 | <tr> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1216 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1217 | <td class="td_left">The number of constant strings that follow.</td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1218 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1219 | <tr> |
| 1220 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1221 | <td class="td_left">Zero. This identifies the following "plane" |
| 1222 | as containing the constant strings. This is needed to identify it |
| 1223 | uniquely from other constant planes that follow. </td> |
| 1224 | </tr> |
| 1225 | <tr> |
| 1226 | <td><a href="#uint24_vbr">uint24_vbr</a>+</td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1227 | <td class="td_left">Type slot number of the constant string's type. |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1228 | Note that the constant string's type implicitly defines the length of |
| 1229 | the string. </td> |
| 1230 | </tr> |
| 1231 | </tbody> |
| 1232 | </table> |
| 1233 | <p><b>Function Constant Pool Preamble (function types)</b></p> |
| 1234 | <p>The structure of the types for functions is identical to the <a |
| 1235 | href="#globaltypes">Global Type Pool</a>. Please refer to that section |
| 1236 | for the details. </p> |
| 1237 | <p><b>Common Part (other constants)</b></p> |
| 1238 | <table> |
| 1239 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1240 | <tr> |
| 1241 | <th><b>Type</b></th> |
| 1242 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1243 | </tr> |
| 1244 | <tr> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1245 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1246 | <td class="td_left">Number of entries in this type plane.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1247 | </tr> |
| 1248 | <tr> |
| 1249 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1250 | <td class="td_left">Type slot number of this plane.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1251 | </tr> |
| 1252 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 1253 | <td><a href="#constant">constant</a>+</td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1254 | <td class="td_left">The definition of a constant (see below).</td> |
| 1255 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1256 | </tbody> |
| 1257 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1258 | </div> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1259 | |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1260 | <!-- _______________________________________________________________________ --> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1261 | <div class="doc_subsubsection"><a name="constant">Simple Constant Pool |
| 1262 | Entries</a></div> |
| 1263 | |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1264 | <div class="doc_text"> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1265 | |
| 1266 | <p>Constant pool entries come in many shapes and flavors. The sections that |
| 1267 | follow define the format for each of them. All constants start with a <a |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1268 | href="#uint32_vbr">uint32_vbr</a> encoded integer that provides the |
| 1269 | number of operands for the constant. For primitive, structure, and |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1270 | array constants, this will always be zero to indicate that the form of the |
| 1271 | constant is solely determined by its type. In this case, we have the following |
| 1272 | field definitions, based on type:</p> |
| 1273 | |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1274 | <ul> |
| 1275 | <li><b>Bool</b>. This is written as an <a href="#uint32_vbr">uint32_vbr</a> |
| 1276 | of value 1U or 0U.</li> |
| 1277 | <li><b>Signed Integers (sbyte,short,int,long)</b>. These are written |
| 1278 | as an <a href="#int64_vbr">int64_vbr</a> with the corresponding value.</li> |
| 1279 | <li><b>Unsigned Integers (ubyte,ushort,uint,ulong)</b>. These are |
| 1280 | written as an <a href="#uint64_vbr">uint64_vbr</a> with the |
| 1281 | corresponding value. </li> |
| 1282 | <li><b>Floating Point</b>. Both the float and double types are |
| 1283 | written literally in binary format.</li> |
| 1284 | <li><b>Arrays</b>. Arrays are written simply as a list of <a |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1285 | href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1286 | element values.</li> |
| 1287 | <li><b>Structures</b>. Structures are written simply as a list of <a |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1288 | href="#uint32_vbr">uint32_vbr</a> encoded value slot numbers to the constant |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1289 | field values of the structure.</li> |
| 1290 | </ul> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1291 | |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1292 | </div> |
| 1293 | |
| 1294 | <!-- _______________________________________________________________________ --> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1295 | <div class="doc_subsubsection">Undef Entries</div> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1296 | |
| 1297 | <div class="doc_text"> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1298 | <p>When the number of operands to the constant is one, we have an 'undef' value |
| 1299 | of the specified type.</p> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1300 | </div> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1301 | |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1302 | <!-- _______________________________________________________________________ --> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1303 | <div class="doc_subsubsection">Inline Assembler Entries</div> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1304 | |
| 1305 | <div class="doc_text"> |
| 1306 | <p>Inline Assembler entries are stored in the constant pool, though they are not |
| 1307 | officially LLVM constants. These entries are marked with a value of |
| 1308 | "4294967295" (all ones) for the number of operands. They are encoded as |
| 1309 | follows:</p> |
| 1310 | |
| 1311 | <table> |
| 1312 | <tbody> |
| 1313 | <tr> |
| 1314 | <th><b>Type</b></th> |
| 1315 | <th class="td_left"><b>Field Description</b></th> |
| 1316 | </tr> |
| 1317 | <tr> |
| 1318 | <td><a href="#string">string</a></td> |
| 1319 | <td class="td_left">The asm string.</td> |
| 1320 | </tr> |
| 1321 | <tr> |
| 1322 | <td><a href="#string">string</a></td> |
| 1323 | <td class="td_left">The constraints string.</td> |
| 1324 | </tr> |
| 1325 | <tr> |
| 1326 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1327 | <td class="td_left">Flags</td> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1328 | </tr> |
| 1329 | </tbody> |
| 1330 | </table> |
| 1331 | |
| 1332 | <p>Currently, the only defined flag, the low bit, indicates whether or not the |
| 1333 | inline assembler has side effects.</p> |
| 1334 | |
| 1335 | </div> |
| 1336 | |
| 1337 | <!-- _______________________________________________________________________ --> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1338 | <div class="doc_subsubsection">Constant Expression Entries</div> |
Chris Lattner | 591d049 | 2006-01-25 23:31:53 +0000 | [diff] [blame] | 1339 | |
| 1340 | <div class="doc_text"> |
| 1341 | |
| 1342 | <p>Otherwise, we have a constant expression. The format of the constant |
| 1343 | expression is specified in the table below, and the number is equal to the |
| 1344 | number of operands+1.</p> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1345 | <table> |
| 1346 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1347 | <tr> |
| 1348 | <th><b>Type</b></th> |
| 1349 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1350 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1351 | <tr> |
| 1352 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1353 | <td class="td_left">Op code of the instruction for the constant |
| 1354 | expression.</td> |
| 1355 | </tr> |
| 1356 | <tr> |
| 1357 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1358 | <td class="td_left">The value slot number of the constant value for an |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1359 | operand.<sup>1</sup></td> |
| 1360 | </tr> |
| 1361 | <tr> |
| 1362 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1363 | <td class="td_left">The type slot number for the type of the constant |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1364 | value for an operand.<sup>1</sup></td> |
| 1365 | </tr> |
| 1366 | </tbody> |
| 1367 | </table> |
| 1368 | Notes: |
| 1369 | <ol> |
| 1370 | <li>Both these fields are repeatable but only in pairs.</li> |
| 1371 | </ol> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1372 | </div> |
| 1373 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1374 | <div class="doc_subsection"><a name="functiondefs">Function Definition</a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1375 | <div class="doc_text"> |
Reid Spencer | c4a8d39 | 2007-01-31 00:26:08 +0000 | [diff] [blame] | 1376 | <p>Function definitions contain the linkage, constant pool, instruction list, |
| 1377 | and symbol table for a function. The following table shows the structure of |
| 1378 | a function definition.</p> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1379 | <table> |
| 1380 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1381 | <tr> |
| 1382 | <th><b>Type</b></th> |
| 1383 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1384 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1385 | <tr> |
| 1386 | <td><a href="#block">block</a><br> |
| 1387 | </td> |
| 1388 | <td class="td_left">Function definition block identifier (0x02) + |
| 1389 | size<br> |
| 1390 | </td> |
| 1391 | </tr> |
| 1392 | <tr> |
| 1393 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1394 | <td class="td_left"><a href="#funclinkage_and_visibility">The linkage and |
| 1395 | visibility</a> style field</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1396 | </tr> |
| 1397 | <tr> |
| 1398 | <td><a href="#block">block</a></td> |
| 1399 | <td class="td_left">The <a href="#constantpool">constant pool</a> |
| 1400 | block for this function.<sup>2</sup></td> |
| 1401 | </tr> |
| 1402 | <tr> |
| 1403 | <td><a href="#block">block</a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1404 | <td class="td_left">The <a href="#instructionlist">instruction |
| 1405 | list</a> for the function.</td> |
| 1406 | </tr> |
| 1407 | <tr> |
| 1408 | <td><a href="#block">block</a></td> |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 1409 | <td class="td_left">The function's <a href="#symtab">symbol |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1410 | table</a> containing only those symbols pertinent to the function |
| 1411 | (mostly block labels).</td> |
| 1412 | </tr> |
| 1413 | </tbody> |
| 1414 | </table> |
| 1415 | Notes: |
| 1416 | <ol> |
| 1417 | <li>Note that if the linkage type is "External" then none of the |
| 1418 | other fields will be present as the function is defined elsewhere.</li> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1419 | </ol> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1420 | |
| 1421 | <!-- _______________________________________________________________________ --> |
| 1422 | <div class="doc_subsubsection"><a name="funclinkage_and_visibility">Linkage and |
| 1423 | visibility word</a> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1424 | </div> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1425 | <div class="doc_text"> |
| 1426 | |
| 1427 | <table> |
| 1428 | <tbody> |
| 1429 | <tr> |
| 1430 | <th><b>Type</b></th> |
| 1431 | <th class="td_left"><b>Field Description</b></th> |
| 1432 | </tr> |
| 1433 | <tr> |
| 1434 | <td><a href="#bit">bit(0-15)</a></td> |
| 1435 | <td class="td_left">The linkage type of the function: 0=External, 1=Weak, |
| 1436 | 2=Appending, 3=Internal, 4=LinkOnce, 5=DllImport, 6=DllExport<sup>1</sup></td> |
| 1437 | </tr> |
| 1438 | <tr> |
Anton Korobeynikov | daa3189 | 2007-01-23 12:43:53 +0000 | [diff] [blame] | 1439 | <td><a href="#bit">bit(16-18)</a></td> |
Anton Korobeynikov | 7f70559 | 2007-01-12 19:20:47 +0000 | [diff] [blame] | 1440 | <td class="td_left">Visibility style: 0=Default, 1=Hidden.</td> |
| 1441 | </tr> |
Anton Korobeynikov | daa3189 | 2007-01-23 12:43:53 +0000 | [diff] [blame] | 1442 | <tr> |
| 1443 | <td><a href="#bit">bit(19-31)</a></td> |
Reid Spencer | c4a8d39 | 2007-01-31 00:26:08 +0000 | [diff] [blame] | 1444 | <td class="td_left">Currently unassigned.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1445 | </tr> |
| 1446 | </tbody> |
| 1447 | </table> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1448 | </div> |
Reid Spencer | c4a8d39 | 2007-01-31 00:26:08 +0000 | [diff] [blame] | 1449 | |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1450 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1451 | <div class="doc_subsection"><a name="instructionlist">Instruction List</a></div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1452 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1453 | <p>The instructions in a function are written as a simple list. Basic |
| 1454 | blocks are inferred by the terminating instruction types. The format of |
| 1455 | the block is given in the following table.</p> |
| 1456 | <table> |
| 1457 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1458 | <tr> |
| 1459 | <th><b>Type</b></th> |
| 1460 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1461 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1462 | <tr> |
| 1463 | <td><a href="#block">block</a><br> |
| 1464 | </td> |
| 1465 | <td class="td_left">Instruction list identifier (0x07) + size<br> |
| 1466 | </td> |
| 1467 | </tr> |
| 1468 | <tr> |
| 1469 | <td><a href="#instruction">instruction</a>+</td> |
| 1470 | <td class="td_left">An instruction. Instructions have a variety |
| 1471 | of formats. See <a href="#instruction">Instructions</a> for details.</td> |
| 1472 | </tr> |
| 1473 | </tbody> |
| 1474 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1475 | </div> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1476 | |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1477 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1478 | <div class="doc_subsection"><a name="instructions">Instructions</a></div> |
| 1479 | |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1480 | <div class="doc_text"> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1481 | <p>Instructions are written out one at a time as distinct units. Each |
| 1482 | instruction |
| 1483 | record contains at least an <a href="#opcodes">opcode</a> and a type field, |
Chris Lattner | 49b1602 | 2005-11-05 22:32:06 +0000 | [diff] [blame] | 1484 | and may contain a <a href="#instoperands">list of operands</a> (whose |
| 1485 | interpretation depends on the opcode). Based on the number of operands, the |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1486 | <a href="#instencode">instruction is encoded</a> in a |
| 1487 | dense format that tries to encoded each instruction into 32-bits if |
| 1488 | possible. </p> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1489 | </div> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1490 | |
| 1491 | <!-- _______________________________________________________________________ --> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1492 | <div class="doc_subsubsection"><a name="opcodes">Instruction Opcodes</a></div> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1493 | <div class="doc_text"> |
| 1494 | <p>Instructions encode an opcode that identifies the kind of instruction. |
| 1495 | Opcodes are an enumerated integer value. The specific values used depend on |
| 1496 | the version of LLVM you're using. The opcode values are defined in the |
Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 1497 | <a href="http://llvm.org/cvsweb/cvsweb.cgi/llvm/include/llvm/Instruction.def"> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1498 | <tt>include/llvm/Instruction.def</tt></a> file. You should check there for the |
| 1499 | most recent definitions. The table below provides the opcodes defined as of |
Nate Begeman | 52ca9e4 | 2004-08-27 07:59:37 +0000 | [diff] [blame] | 1500 | the writing of this document. The table associates each opcode mnemonic with |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1501 | its enumeration value and the bytecode and LLVM version numbers in which the |
| 1502 | opcode was introduced.</p> |
| 1503 | <table> |
| 1504 | <tbody> |
| 1505 | <tr> |
| 1506 | <th>Opcode</th> |
| 1507 | <th>Number</th> |
| 1508 | <th>Bytecode Version</th> |
| 1509 | <th>LLVM Version</th> |
| 1510 | </tr> |
| 1511 | <tr><td colspan="4"><b>Terminator Instructions</b></td></tr> |
| 1512 | <tr><td>Ret</td><td>1</td><td>1</td><td>1.0</td></tr> |
| 1513 | <tr><td>Br</td><td>2</td><td>1</td><td>1.0</td></tr> |
| 1514 | <tr><td>Switch</td><td>3</td><td>1</td><td>1.0</td></tr> |
| 1515 | <tr><td>Invoke</td><td>4</td><td>1</td><td>1.0</td></tr> |
| 1516 | <tr><td>Unwind</td><td>5</td><td>1</td><td>1.0</td></tr> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1517 | <tr><td>Unreachable</td><td>6</td><td>1</td><td>1.4</td></tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1518 | <tr><td colspan="4"><b>Binary Operators</b></td></tr> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1519 | <tr><td>Add</td><td>7</td><td>1</td><td>1.0</td></tr> |
| 1520 | <tr><td>Sub</td><td>8</td><td>1</td><td>1.0</td></tr> |
| 1521 | <tr><td>Mul</td><td>9</td><td>1</td><td>1.0</td></tr> |
Reid Spencer | 3727fd3 | 2006-11-08 20:06:36 +0000 | [diff] [blame] | 1522 | <tr><td>UDiv</td><td>10</td><td>1</td><td>1.9</td></tr> |
| 1523 | <tr><td>SDiv</td><td>11</td><td>1</td><td>1.9</td></tr> |
| 1524 | <tr><td>FDiv</td><td>12</td><td>1</td><td>1.9</td></tr> |
| 1525 | <tr><td>URem</td><td>13</td><td>1</td><td>1.9</td></tr> |
| 1526 | <tr><td>SRem</td><td>14</td><td>1</td><td>1.9</td></tr> |
| 1527 | <tr><td>FRem</td><td>15</td><td>1</td><td>1.9</td></tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1528 | <tr><td colspan="4"><b>Logical Operators</b></td></tr> |
Reid Spencer | 3727fd3 | 2006-11-08 20:06:36 +0000 | [diff] [blame] | 1529 | <tr><td>And</td><td>16</td><td>1</td><td>1.0</td></tr> |
| 1530 | <tr><td>Or</td><td>17</td><td>1</td><td>1.0</td></tr> |
| 1531 | <tr><td>Xor</td><td>18</td><td>1</td><td>1.0</td></tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1532 | <tr><td colspan="4"><b>Memory Operators</b></td></tr> |
Reid Spencer | fec152b | 2007-01-31 00:38:46 +0000 | [diff] [blame^] | 1533 | <tr><td>Malloc</td><td>19</td><td>1</td><td>1.0</td></tr> |
| 1534 | <tr><td>Free</td><td>20</td><td>1</td><td>1.0</td></tr> |
| 1535 | <tr><td>Alloca</td><td>21</td><td>1</td><td>1.0</td></tr> |
| 1536 | <tr><td>Load</td><td>22</td><td>1</td><td>1.0</td></tr> |
| 1537 | <tr><td>Store</td><td>23</td><td>1</td><td>1.0</td></tr> |
| 1538 | <tr><td>GetElementPtr</td><td>24</td><td>1</td><td>1.0</td></tr> |
| 1539 | <tr><td colspan="4"><b>Cast Operators</b></td></tr> |
| 1540 | <tr><td>Trunc</td><td>25</td><td>1</td><td>2.0</td></tr> |
| 1541 | <tr><td>ZExt</td><td>26</td><td>1</td><td>2.0</td></tr> |
| 1542 | <tr><td>SExt</td><td>27</td><td>1</td><td>2.0</td></tr> |
| 1543 | <tr><td>FPToUI</td><td>28</td><td>1</td><td>2.0</td></tr> |
| 1544 | <tr><td>FPToSI</td><td>29</td><td>1</td><td>2.0</td></tr> |
| 1545 | <tr><td>UIToFP</td><td>30</td><td>1</td><td>2.0</td></tr> |
| 1546 | <tr><td>SIToFP</td><td>31</td><td>1</td><td>2.0</td></tr> |
| 1547 | <tr><td>FPTrunc</td><td>32</td><td>1</td><td>2.0</td></tr> |
| 1548 | <tr><td>FPExt</td><td>33</td><td>1</td><td>2.0</td></tr> |
| 1549 | <tr><td>PtrToInt</td><td>34</td><td>1</td><td>2.0</td></tr> |
| 1550 | <tr><td>IntToPtr</td><td>35</td><td>1</td><td>2.0</td></tr> |
| 1551 | <tr><td>BitCast</td><td>36</td><td>1</td><td>2.0</td></tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1552 | <tr><td colspan="4"><b>Other Operators</b></td></tr> |
Reid Spencer | fec152b | 2007-01-31 00:38:46 +0000 | [diff] [blame^] | 1553 | <tr><td>ICmp</td><td>37</td><td>1</td><td>1.0</td></tr> |
| 1554 | <tr><td>FCmp</td><td>38</td><td>1</td><td>1.0</td></tr> |
| 1555 | <tr><td>PHI</td><td>39</td><td>1</td><td>1.0</td></tr> |
| 1556 | <tr><td>Call</td><td>40</td><td>1</td><td>1.0</td></tr> |
| 1557 | <tr><td>Shl</td><td>41</td><td>1</td><td>1.0</td></tr> |
| 1558 | <tr><td>LShr</td><td>42</td><td>6</td><td>2.0</td></tr> |
| 1559 | <tr><td>AShr</td><td>43</td><td>6</td><td>2.0</td></tr> |
| 1560 | <tr><td>Select</td><td>44</td><td>2</td><td>1.2</td></tr> |
| 1561 | <tr><td>UserOp1</td><td>45</td><td>1</td><td>1.0</td></tr> |
| 1562 | <tr><td>UserOp2</td><td>46</td><td>1</td><td>1.0</td></tr> |
| 1563 | <tr><td>VAArg</td><td>47</td><td>5</td><td>1.5</td></tr> |
| 1564 | <tr><td>ExtractElement</td><td>48</td><td>5</td><td>1.5</td></tr> |
| 1565 | <tr><td>InsertElement</td><td>49</td><td>5</td><td>1.5</td></tr> |
| 1566 | <tr><td>ShuffleElement</td><td>50</td><td>5</td><td>1.5</td></tr> |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1567 | <tr><td colspan="4"> |
| 1568 | <b>Pseudo Instructions<a href="#pi_note">*</a></b> |
| 1569 | </td></tr> |
| 1570 | <tr><td>Invoke+CC </td><td>56</td><td>5</td><td>1.5</td></tr> |
| 1571 | <tr><td>Invoke+FastCC</td><td>57</td><td>5</td><td>1.5</td></tr> |
| 1572 | <tr><td>Call+CC</td><td>58</td><td>5</td><td>1.5</td></tr> |
| 1573 | <tr><td>Call+FastCC+TailCall</td><td>59</td><td>5</td><td>1.5</td></tr> |
| 1574 | <tr><td>Call+FastCC</td><td>60</td><td>5</td><td>1.5</td></tr> |
| 1575 | <tr><td>Call+CCC+TailCall</td><td>61</td><td>5</td><td>1.5</td></tr> |
| 1576 | <tr><td>Load+Volatile</td><td>62</td><td>3</td><td>1.3</td></tr> |
| 1577 | <tr><td>Store+Volatile</td><td>63</td><td>3</td><td>1.3</td></tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1578 | </tbody> |
| 1579 | </table> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1580 | |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1581 | <p><b><a name="pi_note">* Note: </a></b> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1582 | These aren't really opcodes from an LLVM language perspective. They encode |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1583 | information into other opcodes without reserving space for that information. |
| 1584 | For example, opcode=63 is a Volatile Store. The opcode for this |
| 1585 | instruction is 25 (Store) but we encode it as 63 to indicate that is a Volatile |
| 1586 | Store. The same is done for the calling conventions and tail calls. |
| 1587 | In each of these entries in range 56-63, the opcode is documented as the base |
| 1588 | opcode (Invoke, Call, Store) plus some set of modifiers, as follows:</p> |
| 1589 | <dl> |
| 1590 | <dt>CC</dt> |
Chris Lattner | 120bc6d | 2005-05-14 01:30:15 +0000 | [diff] [blame] | 1591 | <dd>This means an arbitrary calling convention is specified |
| 1592 | in a VBR that follows the opcode. This is used when the instruction cannot |
| 1593 | be encoded with one of the more compact forms. |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1594 | </dd> |
| 1595 | <dt>FastCC</dt> |
| 1596 | <dd>This indicates that the Call or Invoke is using the FastCC calling |
Chris Lattner | 120bc6d | 2005-05-14 01:30:15 +0000 | [diff] [blame] | 1597 | convention.</dd> |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1598 | <dt>CCC</dt> |
Chris Lattner | 120bc6d | 2005-05-14 01:30:15 +0000 | [diff] [blame] | 1599 | <dd>This indicates that the Call or Invoke is using the native "C" calling |
| 1600 | convention.</dd> |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1601 | <dt>TailCall</dt> |
Chris Lattner | 120bc6d | 2005-05-14 01:30:15 +0000 | [diff] [blame] | 1602 | <dd>This indicates that the Call has the 'tail' modifier.</dd> |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1603 | </dl> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1604 | </div> |
| 1605 | |
Chris Lattner | 49b1602 | 2005-11-05 22:32:06 +0000 | [diff] [blame] | 1606 | <!-- _______________________________________________________________________ --> |
| 1607 | <div class="doc_subsubsection"><a name="instoperands">Instruction |
| 1608 | Operands</a></div> |
| 1609 | |
| 1610 | <div class="doc_text"> |
| 1611 | <p> |
| 1612 | Based on the instruction opcode and type, the bytecode format implicitly (to |
| 1613 | save space) specifies the interpretation of the operand list. For most |
| 1614 | instructions, the type of each operand is implicit from the type of the |
| 1615 | instruction itself (e.g. the type of operands of a binary operator must match |
| 1616 | the type of the instruction). As such, the bytecode format generally only |
| 1617 | encodes the value number of the operand, not the type.</p> |
| 1618 | |
| 1619 | <p>In some cases, however, this is not sufficient. This section enumerates |
| 1620 | those cases:</p> |
| 1621 | |
| 1622 | <ul> |
| 1623 | <li>getelementptr: the slot numbers for sequential type indexes are shifted up |
| 1624 | two bits. This allows the low order bits will encode the type of index used, |
| 1625 | as follows: 0=uint, 1=int, 2=ulong, 3=long.</li> |
| 1626 | <li>cast: the result type number is encoded as the second operand.</li> |
| 1627 | <li>alloca/malloc: If the allocation has an explicit alignment, the log2 of the |
| 1628 | alignment is encoded as the second operand.</li> |
| 1629 | <li>call: If the tail marker and calling convention cannot be <a |
| 1630 | href="#pi_note">encoded into the opcode</a> of the call, it is passed as an |
| 1631 | additional operand. The low bit of the operand is a flag indicating whether |
| 1632 | the call is a tail call. The rest of the bits contain the calling |
| 1633 | convention number (shifted left by one bit).</li> |
| 1634 | </ul> |
| 1635 | </div> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1636 | |
| 1637 | <!-- _______________________________________________________________________ --> |
| 1638 | <div class="doc_subsubsection"><a name="instencode">Instruction |
| 1639 | Encoding</a></div> |
| 1640 | |
| 1641 | <div class="doc_text"> |
| 1642 | <p>For brevity, instructions are written in one of four formats, |
| 1643 | depending on the number of operands to the instruction. Each |
| 1644 | instruction begins with a <a href="#uint32_vbr">uint32_vbr</a> that |
| 1645 | encodes the type of the instruction as well as other things. The tables |
| 1646 | that follow describe the format of this first part of each instruction.</p> |
| 1647 | <p><b>Instruction Format 0</b></p> |
| 1648 | <p>This format is used for a few instructions that can't easily be |
| 1649 | shortened because they have large numbers of operands (e.g. PHI Node or |
| 1650 | getelementptr). Each of the opcode, type, and operand fields is found in |
| 1651 | successive fields.</p> |
| 1652 | <table> |
| 1653 | <tbody> |
| 1654 | <tr> |
| 1655 | <th><b>Type</b></th> |
| 1656 | <th class="td_left"><b>Field Description</b></th> |
| 1657 | </tr> |
| 1658 | <tr> |
| 1659 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1660 | <td class="td_left">Specifies the opcode of the instruction. Note |
| 1661 | that for compatibility with the other instruction formats, the opcode |
| 1662 | is shifted left by 2 bits. Bits 0 and 1 must have value zero for this |
| 1663 | format.</td> |
| 1664 | </tr> |
| 1665 | <tr> |
| 1666 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 1667 | <td class="td_left">Provides the type slot number of the result type of |
| 1668 | the instruction.</td> |
| 1669 | </tr> |
| 1670 | <tr> |
| 1671 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1672 | <td class="td_left">The number of operands that follow.</td> |
| 1673 | </tr> |
| 1674 | <tr> |
| 1675 | <td><a href="#uint32_vbr">uint32_vbr</a>+</td> |
| 1676 | <td class="td_left">The slot number of the value(s) for the operand(s). |
Chris Lattner | 49b1602 | 2005-11-05 22:32:06 +0000 | [diff] [blame] | 1677 | </td> |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1678 | </tr> |
| 1679 | </tbody> |
| 1680 | </table> |
Chris Lattner | 49b1602 | 2005-11-05 22:32:06 +0000 | [diff] [blame] | 1681 | |
Chris Lattner | f97fa59 | 2005-11-05 22:20:06 +0000 | [diff] [blame] | 1682 | <p><b>Instruction Format 1</b></p> |
| 1683 | <p>This format encodes the opcode, type and a single operand into a |
| 1684 | single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1685 | <table> |
| 1686 | <tbody> |
| 1687 | <tr> |
| 1688 | <th><b>Bits</b></th> |
| 1689 | <th><b>Type</b></th> |
| 1690 | <th class="td_left"><b>Field Description</b></th> |
| 1691 | </tr> |
| 1692 | <tr> |
| 1693 | <td>0-1</td> |
| 1694 | <td>constant "1"</td> |
| 1695 | <td class="td_left">These two bits must be the value 1 which identifies |
| 1696 | this as an instruction of format 1.</td> |
| 1697 | </tr> |
| 1698 | <tr> |
| 1699 | <td>2-7</td> |
| 1700 | <td><a href="#instructions">opcode</a></td> |
| 1701 | <td class="td_left">Specifies the opcode of the instruction. Note that |
| 1702 | the maximum opcode value is 63.</td> |
| 1703 | </tr> |
| 1704 | <tr> |
| 1705 | <td>8-19</td> |
| 1706 | <td><a href="#unsigned">unsigned</a></td> |
| 1707 | <td class="td_left">Specifies the slot number of the type for this |
| 1708 | instruction. Maximum slot number is 2<sup>12</sup>-1=4095.</td> |
| 1709 | </tr> |
| 1710 | <tr> |
| 1711 | <td>20-31</td> |
| 1712 | <td><a href="#unsigned">unsigned</a></td> |
| 1713 | <td class="td_left">Specifies the slot number of the value for the |
| 1714 | first operand. Maximum slot number is 2<sup>12</sup>-1=4095. Note that |
| 1715 | the value 2<sup>12</sup>-1 denotes zero operands.</td> |
| 1716 | </tr> |
| 1717 | </tbody> |
| 1718 | </table> |
| 1719 | <p><b>Instruction Format 2</b></p> |
| 1720 | <p>This format encodes the opcode, type and two operands into a single <a |
| 1721 | href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1722 | <table> |
| 1723 | <tbody> |
| 1724 | <tr> |
| 1725 | <th><b>Bits</b></th> |
| 1726 | <th><b>Type</b></th> |
| 1727 | <th class="td_left"><b>Field Description</b></th> |
| 1728 | </tr> |
| 1729 | <tr> |
| 1730 | <td>0-1</td> |
| 1731 | <td>constant "2"</td> |
| 1732 | <td class="td_left">These two bits must be the value 2 which identifies |
| 1733 | this as an instruction of format 2.</td> |
| 1734 | </tr> |
| 1735 | <tr> |
| 1736 | <td>2-7</td> |
| 1737 | <td><a href="#instructions">opcode</a></td> |
| 1738 | <td class="td_left">Specifies the opcode of the instruction. Note that |
| 1739 | the maximum opcode value is 63.</td> |
| 1740 | </tr> |
| 1741 | <tr> |
| 1742 | <td>8-15</td> |
| 1743 | <td><a href="#unsigned">unsigned</a></td> |
| 1744 | <td class="td_left">Specifies the slot number of the type for this |
| 1745 | instruction. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1746 | </tr> |
| 1747 | <tr> |
| 1748 | <td>16-23</td> |
| 1749 | <td><a href="#unsigned">unsigned</a></td> |
| 1750 | <td class="td_left">Specifies the slot number of the value for the first |
| 1751 | operand. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1752 | </tr> |
| 1753 | <tr> |
| 1754 | <td>24-31</td> |
| 1755 | <td><a href="#unsigned">unsigned</a></td> |
| 1756 | <td class="td_left">Specifies the slot number of the value for the second |
| 1757 | operand. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1758 | </tr> |
| 1759 | </tbody> |
| 1760 | </table> |
| 1761 | <p><b>Instruction Format 3</b></p> |
| 1762 | <p>This format encodes the opcode, type and three operands into a |
| 1763 | single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1764 | <table> |
| 1765 | <tbody> |
| 1766 | <tr> |
| 1767 | <th><b>Bits</b></th> |
| 1768 | <th><b>Type</b></th> |
| 1769 | <th class="td_left"><b>Field Description</b></th> |
| 1770 | </tr> |
| 1771 | <tr> |
| 1772 | <td>0-1</td> |
| 1773 | <td>constant "3"</td> |
| 1774 | <td class="td_left">These two bits must be the value 3 which identifies |
| 1775 | this as an instruction of format 3.</td> |
| 1776 | </tr> |
| 1777 | <tr> |
| 1778 | <td>2-7</td> |
| 1779 | <td><a href="#instructions">opcode</a></td> |
| 1780 | <td class="td_left">Specifies the opcode of the instruction. Note that |
| 1781 | the maximum opcode value is 63.</td> |
| 1782 | </tr> |
| 1783 | <tr> |
| 1784 | <td>8-13</td> |
| 1785 | <td><a href="#unsigned">unsigned</a></td> |
| 1786 | <td class="td_left">Specifies the slot number of the type for this |
| 1787 | instruction. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1788 | </tr> |
| 1789 | <tr> |
| 1790 | <td>14-19</td> |
| 1791 | <td><a href="#unsigned">unsigned</a></td> |
| 1792 | <td class="td_left">Specifies the slot number of the value for the first |
| 1793 | operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1794 | </tr> |
| 1795 | <tr> |
| 1796 | <td>20-25</td> |
| 1797 | <td><a href="#unsigned">unsigned</a></td> |
| 1798 | <td class="td_left">Specifies the slot number of the value for the second |
| 1799 | operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1800 | </tr> |
| 1801 | <tr> |
| 1802 | <td>26-31</td> |
| 1803 | <td><a href="#unsigned">unsigned</a></td> |
| 1804 | <td class="td_left">Specifies the slot number of the value for the third |
| 1805 | operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1806 | </tr> |
| 1807 | </tbody> |
| 1808 | </table> |
| 1809 | </div> |
Reid Spencer | a568177 | 2005-05-14 00:06:06 +0000 | [diff] [blame] | 1810 | |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1811 | <!-- _______________________________________________________________________ --> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 1812 | <div class="doc_subsection"><a name="symtab">Symbol Table</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1813 | <div class="doc_text"> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1814 | <p>A symbol table can be put out in conjunction with a module or a function. A |
| 1815 | symbol table has a list of name/type associations followed by a list of |
| 1816 | name/value associations. The name/value associations are organized into "type |
| 1817 | planes" so that all values of a common type are listed together. Each type |
| 1818 | plane starts with the number of entries in the plane and the type slot number |
| 1819 | for all the values in that plane (so the type can be looked up in the global |
| 1820 | type pool). For each entry in a type plane, the slot number of the value and |
| 1821 | the name associated with that value are written. The format is given in the |
| 1822 | table below. </p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1823 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1824 | <tbody> |
| 1825 | <tr> |
| 1826 | <th><b>Type</b></th> |
| 1827 | <th class="td_left"><b>Field Description</b></th> |
| 1828 | </tr> |
| 1829 | <tr> |
| 1830 | <td><a href="#block">block</a><br> |
| 1831 | </td> |
| 1832 | <td class="td_left">Symbol Table Identifier (0x04)</td> |
| 1833 | </tr> |
| 1834 | <tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1835 | <td><a href="#llist">llist</a>(<a href="#symtab_entry">type_entry</a>)</td> |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 1836 | <td class="td_left">A length list of symbol table entries for |
| 1837 | <tt>Type</tt>s |
| 1838 | </td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1839 | </tr> |
| 1840 | <tr> |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 1841 | <td><a href="#zlist">llist</a>(<a href="#symtab_plane">symtab_plane</a>)</td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1842 | <td class="td_left">A length list of "type planes" of symbol table |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 1843 | entries for <tt>Value</tt>s</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1844 | </tr> |
| 1845 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 1846 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1847 | </div> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1848 | |
| 1849 | <!-- _______________________________________________________________________ --> |
| 1850 | <div class="doc_subsubsection"> <a name="type_entry">Symbol Table Type |
| 1851 | Entry</a> |
| 1852 | </div> |
| 1853 | <div class="doc_text"> |
| 1854 | <p>A symbol table type entry associates a name with a type. The name is provided |
| 1855 | simply as an array of chars. The type is provided as a type slot number (index) |
| 1856 | into the global type pool. The format is given in the following table:</p> |
| 1857 | <table> |
| 1858 | <tbody> |
| 1859 | <tr> |
| 1860 | <th><b>Type</b></th> |
| 1861 | <th class="td_left"><b>Field Description</b></th> |
| 1862 | </tr> |
| 1863 | <tr> |
| 1864 | <td><a href="#uint32_vbr">uint24_vbr</a></td> |
| 1865 | <td class="td_left">Type slot number of the type being given a |
| 1866 | name relative to the global type pool. |
| 1867 | </td> |
| 1868 | </tr> |
| 1869 | <tr> |
| 1870 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1871 | <td class="td_left">Length of the character array that follows.</td> |
| 1872 | </tr> |
| 1873 | <tr> |
| 1874 | <td><a href="#char">char</a>+</td> |
| 1875 | <td class="td_left">The characters of the name.</td> |
| 1876 | </tr> |
| 1877 | </tbody> |
| 1878 | </table> |
| 1879 | </div> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1880 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1881 | <div class="doc_subsubsection"> <a name="symtab_plane">Symbol Table |
| 1882 | Plane</a> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1883 | </div> |
| 1884 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1885 | <p>A symbol table plane provides the symbol table entries for all |
| 1886 | values of a common type. The encoding is given in the following table:</p> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1887 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1888 | <tbody> |
| 1889 | <tr> |
| 1890 | <th><b>Type</b></th> |
| 1891 | <th class="td_left"><b>Field Description</b></th> |
| 1892 | </tr> |
| 1893 | <tr> |
| 1894 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1895 | <td class="td_left">Number of entries in this plane.</td> |
| 1896 | </tr> |
| 1897 | <tr> |
| 1898 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1899 | <td class="td_left">Type slot number of type for all values in this plane..</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1900 | </tr> |
| 1901 | <tr> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1902 | <td><a href="#value_entry">value_entry</a>+</td> |
| 1903 | <td class="td_left">The symbol table entries for to associate values with |
| 1904 | names.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1905 | </tr> |
| 1906 | </tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1907 | </table> |
| 1908 | </div> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1909 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1910 | <div class="doc_subsubsection"><a name="value_entry">Symbol Table Value |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1911 | Entry</a> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1912 | </div> |
| 1913 | <div class="doc_text"> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1914 | <p>A symbol table value entry provides the assocation between a value and the |
| 1915 | name given to the value. The value is referenced by its slot number. The |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1916 | format is given in the following table:</p> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1917 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1918 | <tbody> |
| 1919 | <tr> |
| 1920 | <th><b>Type</b></th> |
| 1921 | <th class="td_left"><b>Field Description</b></th> |
| 1922 | </tr> |
| 1923 | <tr> |
| 1924 | <td><a href="#uint32_vbr">uint24_vbr</a></td> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1925 | <td class="td_left">Value slot number of the value being given a name. |
Reid Spencer | 8996e55 | 2004-08-17 00:49:03 +0000 | [diff] [blame] | 1926 | </td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1927 | </tr> |
| 1928 | <tr> |
| 1929 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1930 | <td class="td_left">Length of the character array that follows.</td> |
| 1931 | </tr> |
| 1932 | <tr> |
| 1933 | <td><a href="#char">char</a>+</td> |
| 1934 | <td class="td_left">The characters of the name.</td> |
| 1935 | </tr> |
| 1936 | </tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1937 | </table> |
| 1938 | </div> |
Reid Spencer | 09daa63 | 2004-08-18 20:06:19 +0000 | [diff] [blame] | 1939 | |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1940 | <!-- *********************************************************************** --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1941 | <div class="doc_section"> <a name="versiondiffs">Version Differences</a> |
| 1942 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1943 | <!-- *********************************************************************** --> |
| 1944 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1945 | <p>This section describes the differences in the Bytecode Format across |
| 1946 | LLVM |
| 1947 | versions. The versions are listed in reverse order because it assumes |
| 1948 | the current version is as documented in the previous sections. Each |
| 1949 | section here |
Chris Lattner | 1cc070c | 2004-07-05 18:05:48 +0000 | [diff] [blame] | 1950 | describes the differences between that version and the one that <i>follows</i>. |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1951 | </p> |
| 1952 | </div> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1953 | |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1954 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 43dfdb7 | 2004-08-18 20:17:05 +0000 | [diff] [blame] | 1955 | <div class="doc_subsection"><a name="vers13">Version 1.3 Differences From |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1956 | 1.4</a></div> |
Reid Spencer | cf549e1 | 2004-08-17 07:43:43 +0000 | [diff] [blame] | 1957 | <!-- _______________________________________________________________________ --> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1958 | |
| 1959 | <div class="doc_subsubsection">Unreachable Instruction</div> |
| 1960 | <div class="doc_text"> |
| 1961 | <p>The LLVM <a href="LangRef.html#i_unreachable">Unreachable</a> instruction |
| 1962 | was added in version 1.4 of LLVM. This caused all instruction numbers after |
| 1963 | it to shift down by one.</p> |
| 1964 | </div> |
| 1965 | |
| 1966 | <div class="doc_subsubsection">Function Flags</div> |
| 1967 | <div class="doc_text"> |
| 1968 | <p>LLVM bytecode versions prior to 1.4 did not include the 5 bit offset |
| 1969 | in <a href="#funcfield">the function list</a> in the <a |
| 1970 | href="#globalinfo">Module Global Info</a> block.</p> |
| 1971 | </div> |
| 1972 | |
| 1973 | <div class="doc_subsubsection">Function Flags</div> |
| 1974 | <div class="doc_text"> |
| 1975 | <p>LLVM bytecode versions prior to 1.4 did not include the 'undef' constant |
| 1976 | value, which affects the encoding of <a href="#constant">Constant |
| 1977 | Fields</a>.</p> |
| 1978 | </div> |
| 1979 | |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1980 | |
Reid Spencer | cf549e1 | 2004-08-17 07:43:43 +0000 | [diff] [blame] | 1981 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1982 | <div class="doc_subsection"><a name="vers12">Version 1.2 Differences |
| 1983 | From 1.3</a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1984 | <!-- _______________________________________________________________________ --> |
Chris Lattner | a1dad81 | 2004-10-16 18:03:55 +0000 | [diff] [blame] | 1985 | |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1986 | <div class="doc_subsubsection">Type Derives From Value</div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1987 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1988 | <p>In version 1.2, the Type class in the LLVM IR derives from the Value |
| 1989 | class. This is not the case in version 1.3. Consequently, in version |
| 1990 | 1.2 the notion of a "Type Type" was used to write out values that were |
| 1991 | Types. The types always occuped plane 12 (corresponding to the |
| 1992 | TypeTyID) of any type planed set of values. In 1.3 this representation |
| 1993 | is not convenient because the TypeTyID (12) is not present and its |
| 1994 | value is now used for LabelTyID. Consequently, the data structures |
| 1995 | written that involve types do so by writing all the types first and |
| 1996 | then each of the value planes according to those types. In version 1.2, |
| 1997 | the types would have been written intermingled with the values.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1998 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1999 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2000 | <div class="doc_subsubsection">Restricted getelementptr Types</div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 2001 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2002 | <p>In version 1.2, the getelementptr instruction required a ubyte type |
| 2003 | index for accessing a structure field and a long type index for |
| 2004 | accessing an array element. Consequently, it was only possible to |
| 2005 | access structures of 255 or fewer elements. Starting in version 1.3, |
| 2006 | this restriction was lifted. Structures must now be indexed with uint |
| 2007 | constants. Arrays may now be indexed with int, uint, long, or ulong |
| 2008 | typed values. The consequence of this was that the bytecode format had |
| 2009 | to change in order to accommodate the larger range of structure indices.</p> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2010 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2011 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2012 | <div class="doc_subsubsection">Short Block Headers</div> |
| 2013 | <div class="doc_text"> |
| 2014 | <p>In version 1.2, block headers were always 8 bytes being comprised of |
| 2015 | both an unsigned integer type and an unsigned integer size. For very |
| 2016 | small modules, these block headers turn out to be a large fraction of |
| 2017 | the total bytecode file size. In an attempt to make these small files |
| 2018 | smaller, the type and size information was encoded into a single |
| 2019 | unsigned integer (4 bytes) comprised of 5 bits for the block type |
| 2020 | (maximum 31 block types) and 27 bits for the block size (max |
| 2021 | ~134MBytes). These limits seemed sufficient for any blocks or sizes |
| 2022 | forseen in the future. Note that the module block, which encloses all |
| 2023 | the other blocks is still written as 8 bytes since bytecode files |
| 2024 | larger than 134MBytes might be possible.</p> |
| 2025 | </div> |
| 2026 | <!-- _______________________________________________________________________ --> |
| 2027 | <div class="doc_subsubsection">Dependent Libraries and Target Triples</div> |
| 2028 | <div class="doc_text"> |
| 2029 | <p>In version 1.2, the bytecode format does not store module's target |
| 2030 | triple or dependent. These fields have been added to the end of the <a |
| 2031 | href="#globalinfo">module global info block</a>. The purpose of these |
| 2032 | fields is to allow a front end compiler to specifiy that the generated |
| 2033 | module is specific to a particular target triple (operating |
| 2034 | system/manufacturer/processor) which makes it non-portable; and to |
| 2035 | allow front end compilers to specify the list of libraries that the |
| 2036 | module depends on for successful linking.</p> |
| 2037 | </div> |
| 2038 | <!-- _______________________________________________________________________ --> |
| 2039 | <div class="doc_subsubsection">Types Restricted to 24-bits</div> |
| 2040 | <div class="doc_text"> |
| 2041 | <p>In version 1.2, type slot identifiers were written as 32-bit VBR |
| 2042 | quantities. In 1.3 this has been reduced to 24-bits in order to ensure |
| 2043 | that it is not possible to overflow the type field of a global variable |
| 2044 | definition. 24-bits for type slot numbers is deemed sufficient for any |
| 2045 | practical use of LLVM.</p> |
| 2046 | </div> |
| 2047 | <!-- _______________________________________________________________________ --> |
| 2048 | <!-- _______________________________________________________________________ --> |
| 2049 | <div class="doc_subsection"><a name="vers11">Version 1.1 Differences |
| 2050 | From 1.2 </a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 2051 | <!-- _______________________________________________________________________ --> |
| 2052 | <div class="doc_subsubsection">Explicit Primitive Zeros</div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2053 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2054 | <p>In version 1.1, the zero value for primitives was explicitly encoded |
| 2055 | into the bytecode format. Since these zero values are constant values |
| 2056 | in the LLVM IR and never change, there is no reason to explicitly |
| 2057 | encode them. This explicit encoding was removed in version 1.2.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 2058 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 2059 | <!-- _______________________________________________________________________ --> |
| 2060 | <div class="doc_subsubsection">Inconsistent Module Global Info</div> |
| 2061 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2062 | <p>In version 1.1, the Module Global Info block was not aligned causing |
| 2063 | the next block to be read in on an unaligned boundary. This problem was |
| 2064 | corrected in version 1.2.<br> |
| 2065 | <br> |
| 2066 | </p> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2067 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2068 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2069 | <div class="doc_subsection"><a name="vers10">Version 1.0 Differences |
| 2070 | From 1.1</a></div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2071 | <div class="doc_text"> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 2072 | <p>None. Version 1.0 and 1.1 bytecode formats are identical.</p> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 2073 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 2074 | <!-- *********************************************************************** --> |
| 2075 | <hr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2076 | <address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 2077 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 2078 | <a href="http://validator.w3.org/check/referer"><img |
| 2079 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> |
| 2080 | <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and <a |
| 2081 | href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
Reid Spencer | 05fe4b0 | 2006-03-14 05:39:39 +0000 | [diff] [blame] | 2082 | <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2083 | Last modified: $Date$ |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 2084 | </address> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 2085 | </body> |
| 2086 | </html> |