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> |
| 4 | <title>LLVM Bytecode File Format</title> |
| 5 | <link rel="stylesheet" href="llvm.css" type="text/css"> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 6 | <style type="text/css"> |
Reid Spencer | 2de2999 | 2004-08-03 20:21:05 +0000 | [diff] [blame] | 7 | TR, TD { border: 2px solid gray; padding-left: 4pt; padding-right: 4pt; |
| 8 | padding-top: 2pt; padding-bottom: 2pt; } |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 9 | TH { border: 2px solid gray; font-weight: bold; font-size: 105%; } |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 10 | TABLE { text-align: center; border: 2px solid black; |
Reid Spencer | 2de2999 | 2004-08-03 20:21:05 +0000 | [diff] [blame] | 11 | border-collapse: collapse; margin-top: 1em; margin-left: 1em; |
| 12 | margin-right: 1em; margin-bottom: 1em; } |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 13 | .td_left { border: 2px solid gray; text-align: left; } |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 14 | </style> |
| 15 | </head> |
| 16 | <body> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 17 | <div class="doc_title"> LLVM Bytecode File Format </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 18 | <ol> |
| 19 | <li><a href="#abstract">Abstract</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 20 | <li><a href="#concepts">Concepts</a> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 21 | <ol> |
| 22 | <li><a href="#blocks">Blocks</a></li> |
| 23 | <li><a href="#lists">Lists</a></li> |
| 24 | <li><a href="#fields">Fields</a></li> |
| 25 | <li><a href="#align">Alignment</a></li> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 26 | <li><a href="#vbr">Variable Bit-Rate Encoding</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 27 | <li><a href="#encoding">Encoding Primitives</a></li> |
| 28 | <li><a href="#slots">Slots</a></li> |
| 29 | </ol> |
| 30 | </li> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 31 | <li><a href="#general">General Structure</a> </li> |
| 32 | <li><a href="#blockdefs">Block Definitions</a> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 33 | <ol> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 34 | <li><a href="#signature">Signature Block</a></li> |
| 35 | <li><a href="#module">Module Block</a></li> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 36 | <li><a href="#globaltypes">Global Type Pool</a></li> |
| 37 | <li><a href="#globalinfo">Module Info Block</a></li> |
| 38 | <li><a href="#constantpool">Global Constant Pool</a></li> |
| 39 | <li><a href="#functiondefs">Function Definition</a></li> |
| 40 | <li><a href="#compactiontable">Compaction Table</a></li> |
| 41 | <li><a href="#instructionlist">Instruction List</a></li> |
| 42 | <li><a href="#symtab">Symbol Table</a></li> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 43 | </ol> |
| 44 | </li> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 45 | <li><a href="#versiondiffs">Version Differences</a> |
| 46 | <ol> |
| 47 | <li><a href="#vers12">Version 1.2 Differences From 1.3</a></li> |
| 48 | <li><a href="#vers11">Version 1.1 Differences From 1.2</a></li> |
| 49 | <li><a href="#vers10">Version 1.0 Differences From 1.1</a></li> |
| 50 | </ol> |
| 51 | </li> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 52 | </ol> |
Chris Lattner | 8dabb50 | 2004-05-25 17:44:58 +0000 | [diff] [blame] | 53 | <div class="doc_author"> |
| 54 | <p>Written by <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> |
| 55 | </p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 56 | </div> |
| 57 | <!-- *********************************************************************** --> |
| 58 | <div class="doc_section"> <a name="abstract">Abstract </a></div> |
| 59 | <!-- *********************************************************************** --> |
| 60 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 61 | <p>This document describes the LLVM bytecode file format. It specifies |
| 62 | the binary encoding rules of the bytecode file format so that |
| 63 | equivalent systems can encode bytecode files correctly. The LLVM |
| 64 | bytecode representation is used to store the intermediate |
| 65 | representation on disk in compacted form.</p> |
| 66 | <p>The LLVM bytecode format may change in the future, but LLVM will |
| 67 | always be backwards compatible with older formats. This document will |
| 68 | only describe the most current version of the bytecode format. See <a |
| 69 | href="#versiondiffs">Version Differences</a> for the details on how |
| 70 | the current version is different from previous versions.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 71 | </div> |
| 72 | <!-- *********************************************************************** --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 73 | <div class="doc_section"> <a name="concepts">Concepts</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 74 | <!-- *********************************************************************** --> |
| 75 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 76 | <p>This section describes the general concepts of the bytecode file |
| 77 | format without getting into specific layout details. It is recommended |
| 78 | that you read this section thoroughly before interpreting the detailed |
| 79 | descriptions.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 80 | </div> |
| 81 | <!-- _______________________________________________________________________ --> |
| 82 | <div class="doc_subsection"><a name="blocks">Blocks</a> </div> |
| 83 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 84 | <p>LLVM bytecode files consist simply of a sequence of blocks of bytes |
| 85 | using a binary encoding Each block begins with an header of two |
| 86 | unsigned integers. The first value identifies the type of block and the |
| 87 | second value provides the size of the block in bytes. The block |
| 88 | identifier is used because it is possible for entire blocks to be |
| 89 | omitted from the file if they are empty. The block identifier helps the |
| 90 | reader determine which kind of block is next in the file. Note that |
| 91 | blocks can be nested within other blocks.</p> |
| 92 | <p> All blocks are variable length, and the block header specifies the |
| 93 | size of the block. All blocks begin on a byte index that is aligned to |
| 94 | an even 32-bit boundary. That is, the first block is 32-bit aligned |
| 95 | because it starts at offset 0. Each block is padded with zero fill |
| 96 | 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] | 97 | </div> |
| 98 | <!-- _______________________________________________________________________ --> |
| 99 | <div class="doc_subsection"><a name="lists">Lists</a> </div> |
| 100 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 101 | <p>LLVM Bytecode blocks often contain lists of things of a similar |
| 102 | type. For example, a function contains a list of instructions and a |
| 103 | function type contains a list of argument types. There are two basic |
| 104 | types of lists: length lists (<a href="#llist">llist</a>), and null |
| 105 | terminated lists (<a href="#zlist">zlist</a>), as described below in |
| 106 | the <a href="#encoding">Encoding Primitives</a>.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 107 | </div> |
| 108 | <!-- _______________________________________________________________________ --> |
| 109 | <div class="doc_subsection"><a name="fields">Fields</a> </div> |
| 110 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 111 | <p>Fields are units of information that LLVM knows how to write atomically. Most |
| 112 | fields have a uniform length or some kind of length indication built into their |
| 113 | encoding. For example, a constant string (array of bytes) is written simply as |
| 114 | the length followed by the characters. Although this is similar to a list, |
| 115 | constant strings are treated atomically and are thus fields.</p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 116 | <p>Fields use a condensed bit format specific to the type of information |
| 117 | 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] | 118 | sections that follow will provide the details on how these fields are |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 119 | written and how the bits are to be interpreted.</p> |
| 120 | </div> |
| 121 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 122 | <div class="doc_subsection"><a name="align">Alignment</a> </div> |
Reid Spencer | 7aa940d | 2004-05-25 15:47:57 +0000 | [diff] [blame] | 123 | <div class="doc_text"> |
Reid Spencer | 267660f | 2004-08-03 20:33:56 +0000 | [diff] [blame] | 124 | <p>To support cross-platform differences, the bytecode file is aligned on |
| 125 | certain boundaries. This means that a small amount of padding (at most 3 |
| 126 | bytes) will be added to ensure that the next entry is aligned to a 32-bit |
| 127 | boundary.</p> |
Chris Lattner | 8dabb50 | 2004-05-25 17:44:58 +0000 | [diff] [blame] | 128 | </div> |
Reid Spencer | 7aa940d | 2004-05-25 15:47:57 +0000 | [diff] [blame] | 129 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 130 | <div class="doc_subsection"><a name="vbr">Variable Bit-Rate Encoding</a> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 131 | </div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 132 | <div class="doc_text"> |
| 133 | <p>Most of the values written to LLVM bytecode files are small integers. To |
| 134 | minimize the number of bytes written for these quantities, an encoding scheme |
| 135 | similar to UTF-8 is used to write integer data. The scheme is known as |
| 136 | variable bit rate (vbr) encoding. In this encoding, the high bit of |
| 137 | each byte is used to indicate if more bytes follow. If (byte & |
| 138 | 0x80) is non-zero in any given byte, it means there is another byte |
| 139 | immediately following that also contributes to the value. For the final |
| 140 | byte (byte & 0x80) is false (the high bit is not set). In each byte |
| 141 | only the low seven bits contribute to the value. Consequently 32-bit |
| 142 | quantities can take from one to <em>five</em> bytes to encode. In |
| 143 | general, smaller quantities will encode in fewer bytes, as follows:</p> |
| 144 | <table> |
| 145 | <tbody> |
| 146 | <tr> |
| 147 | <th>Byte #</th> |
| 148 | <th>Significant Bits</th> |
| 149 | <th>Maximum Value</th> |
| 150 | </tr> |
| 151 | <tr> |
| 152 | <td>1</td> |
| 153 | <td>0-6</td> |
| 154 | <td>127</td> |
| 155 | </tr> |
| 156 | <tr> |
| 157 | <td>2</td> |
| 158 | <td>7-13</td> |
| 159 | <td>16,383</td> |
| 160 | </tr> |
| 161 | <tr> |
| 162 | <td>3</td> |
| 163 | <td>14-20</td> |
| 164 | <td>2,097,151</td> |
| 165 | </tr> |
| 166 | <tr> |
| 167 | <td>4</td> |
| 168 | <td>21-27</td> |
| 169 | <td>268,435,455</td> |
| 170 | </tr> |
| 171 | <tr> |
| 172 | <td>5</td> |
| 173 | <td>28-34</td> |
| 174 | <td>34,359,738,367</td> |
| 175 | </tr> |
| 176 | <tr> |
| 177 | <td>6</td> |
| 178 | <td>35-41</td> |
| 179 | <td>4,398,046,511,103</td> |
| 180 | </tr> |
| 181 | <tr> |
| 182 | <td>7</td> |
| 183 | <td>42-48</td> |
| 184 | <td>562,949,953,421,311</td> |
| 185 | </tr> |
| 186 | <tr> |
| 187 | <td>8</td> |
| 188 | <td>49-55</td> |
| 189 | <td>72,057,594,037,927,935</td> |
| 190 | </tr> |
| 191 | <tr> |
| 192 | <td>9</td> |
| 193 | <td>56-62</td> |
| 194 | <td>9,223,372,036,854,775,807</td> |
| 195 | </tr> |
| 196 | <tr> |
| 197 | <td>10</td> |
| 198 | <td>63-69</td> |
| 199 | <td>1,180,591,620,717,411,303,423</td> |
| 200 | </tr> |
| 201 | </tbody> |
| 202 | </table> |
| 203 | <p>Note that in practice, the tenth byte could only encode bit 63 since |
| 204 | the maximum quantity to use this encoding is a 64-bit integer.</p> |
| 205 | <p><em>Signed</em> VBR values are encoded with the standard vbr |
| 206 | encoding, but with the sign bit as the low order bit instead of the |
| 207 | high order bit. This allows small negative quantities to be encoded |
| 208 | efficiently. For example, -3 |
| 209 | is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << |
| 210 | 1) | 0)", emitted with the standard vbr encoding above.</p> |
| 211 | </div> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 212 | <!-- _______________________________________________________________________ --> |
| 213 | <div class="doc_subsection"><a name="encoding">Encoding Primitives</a> </div> |
| 214 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 215 | <p>Each field in the bytecode format is encoded into the file using a |
| 216 | small set of primitive formats. The table below defines the encoding |
| 217 | rules for the various primitives used and gives them each a type name. |
| 218 | The type names used in the descriptions of blocks and fields in the <a |
| 219 | href="#details">Detailed Layout</a>next section. Any type name with |
| 220 | the suffix <em>_vbr</em> indicates a quantity that is encoded using |
| 221 | variable bit rate encoding as described above.</p> |
| 222 | <table class="doc_table"> |
| 223 | <tbody> |
| 224 | <tr> |
| 225 | <th><b>Type</b></th> |
| 226 | <th class="td_left"><b>Rule</b></th> |
| 227 | </tr> |
| 228 | <tr> |
| 229 | <td><a name="unsigned"><b>unsigned</b></a></td> |
| 230 | <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] | 231 | consecutive bytes. The unsigned integer is encoded using LSB first |
| 232 | ordering. That is bits 2<sup>0</sup> through 2<sup>7</sup> are in the |
| 233 | byte with the lowest file offset (little endian).</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 234 | </tr> |
| 235 | <tr> |
Reid Spencer | 301fe48 | 2004-08-03 20:57:56 +0000 | [diff] [blame] | 236 | <td style="vertical-align: top;"><a name="uint24_vbr"> |
| 237 | <b>uint24_vbr</b></a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 238 | <td style="vertical-align: top; text-align: left;">A 24-bit unsigned |
| 239 | integer that occupies from one to four bytes using variable bit rate |
| 240 | encoding.</td> |
| 241 | </tr> |
| 242 | <tr> |
| 243 | <td><a name="uint32_vbr"><b>uint32_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 244 | <td class="td_left">A 32-bit unsigned integer that occupies from one to |
| 245 | five bytes using variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 246 | </tr> |
| 247 | <tr> |
| 248 | <td><a name="uint64_vbr"><b>uint64_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 249 | <td class="td_left">A 64-bit unsigned integer that occupies from one to ten |
| 250 | bytes using variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 251 | </tr> |
| 252 | <tr> |
| 253 | <td><a name="int64_vbr"><b>int64_vbr</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 254 | <td class="td_left">A 64-bit signed integer that occupies from one to ten |
| 255 | bytes using the signed variable bit rate encoding.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 256 | </tr> |
| 257 | <tr> |
| 258 | <td><a name="char"><b>char</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 259 | <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] | 260 | </tr> |
| 261 | <tr> |
| 262 | <td><a name="bit"><b>bit(n-m)</b></a></td> |
Reid Spencer | f08561f | 2004-08-03 19:20:18 +0000 | [diff] [blame] | 263 | <td class="td_left">A set of bit within some larger integer field. The values |
| 264 | of <code>n</code> and <code>m</code> specify the inclusive range of bits |
| 265 | that define the subfield. The value for <code>m</code> may be omitted if |
| 266 | its the same as <code>n</code>.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 267 | </tr> |
| 268 | <tr> |
| 269 | <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] | 270 | <td style="vertical-align: top; text-align: left;">A floating point value encoded |
| 271 | as a 32-bit IEEE value written in little-endian form.<br> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 272 | </td> |
| 273 | </tr> |
| 274 | <tr> |
| 275 | <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] | 276 | <td style="vertical-align: top; text-align: left;">A floating point value encoded |
| 277 | as a64-bit IEEE value written in little-endian form</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 278 | </tr> |
| 279 | <tr> |
| 280 | <td><a name="string"><b>string</b></a></td> |
| 281 | <td class="td_left">A uint32_vbr indicating the type of the |
| 282 | constant string which also includes its length, immediately followed by |
| 283 | the characters of the string. There is no terminating null byte in the |
| 284 | string.</td> |
| 285 | </tr> |
| 286 | <tr> |
| 287 | <td><a name="data"><b>data</b></a></td> |
| 288 | <td class="td_left">An arbitrarily long segment of data to which |
| 289 | no interpretation is implied. This is used for constant initializers.<br> |
| 290 | </td> |
| 291 | </tr> |
| 292 | <tr> |
| 293 | <td><a name="llist"><b>llist(x)</b></a></td> |
| 294 | <td class="td_left">A length list of x. This means the list is |
| 295 | encoded as an <a href="#uint32_vbr">uint32_vbr</a> providing the |
| 296 | length of the list, followed by a sequence of that many "x" items. This |
| 297 | implies that the reader should iterate the number of times provided by |
| 298 | the length.</td> |
| 299 | </tr> |
| 300 | <tr> |
| 301 | <td><a name="zlist"><b>zlist(x)</b></a></td> |
| 302 | <td class="td_left">A zero-terminated list of x. This means the |
| 303 | list is encoded as a sequence of an indeterminate number of "x" items, |
| 304 | followed by an <a href="#uint32_vbr">uint32_vbr</a> terminating value. |
| 305 | This implies that none of the "x" items can have a zero value (or else |
| 306 | the list terminates).</td> |
| 307 | </tr> |
| 308 | <tr> |
| 309 | <td><a name="block"><b>block</b></a></td> |
| 310 | <td class="td_left">A block of data that is logically related. A |
| 311 | block is an unsigned 32-bit integer that encodes the type of the block |
| 312 | in the low 5 bits and the size of the block in the high 27 bits. The |
| 313 | length does not include the block header or any alignment bytes at the |
| 314 | end of the block. Blocks may compose other blocks. </td> |
| 315 | </tr> |
| 316 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 317 | </table> |
| 318 | </div> |
| 319 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 320 | <div class="doc_subsection"><a name="notation">Field Notation</a> </div> |
| 321 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 322 | <p>In the detailed block and field descriptions that follow, a regex |
| 323 | like notation is used to describe optional and repeated fields. A very |
| 324 | limited subset of regex is used to describe these, as given in the |
| 325 | following table: </p> |
| 326 | <table class="doc_table"> |
| 327 | <tbody> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 328 | <tr> |
| 329 | <th><b>Character</b></th> |
| 330 | <th class="td_left"><b>Meaning</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 331 | </tr> |
| 332 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 333 | <td><b><code>?</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 334 | <td class="td_left">The question mark indicates 0 or 1 |
| 335 | occurrences of the thing preceding it.</td> |
| 336 | </tr> |
| 337 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 338 | <td><b><code>*</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 339 | <td class="td_left">The asterisk indicates 0 or more occurrences |
| 340 | of the thing preceding it.</td> |
| 341 | </tr> |
| 342 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 343 | <td><b><code>+</code></b></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 344 | <td class="td_left">The plus sign indicates 1 or more occurrences |
| 345 | of the thing preceding it.</td> |
| 346 | </tr> |
| 347 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 348 | <td><b><code>()</code></b></td> |
| 349 | <td class="td_left">Parentheses are used for grouping.</td> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 350 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 351 | <tr> |
| 352 | <td><b><code>,</code></b></td> |
| 353 | <td class="td_left">The comma separates sequential fields.</td> |
| 354 | </tr> |
| 355 | </tbody> |
| 356 | </table> |
| 357 | <p>So, for example, consider the following specifications:</p> |
| 358 | <div class="doc_code"> |
| 359 | <ol> |
| 360 | <li><code>string?</code></li> |
| 361 | <li><code>(uint32_vbr,uin32_vbr)+</code></li> |
| 362 | <li><code>(unsigned?,uint32_vbr)*</code></li> |
| 363 | <li><code>(llist(unsigned))?</code></li> |
| 364 | </ol> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 365 | </div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 366 | <p>with the following interpretations:</p> |
| 367 | <ol> |
| 368 | <li>An optional string. Matches either nothing or a single string</li> |
| 369 | <li>One or more pairs of uint32_vbr.</li> |
| 370 | <li>Zero or more occurrences of either an unsigned followed by a |
| 371 | uint32_vbr or just a uint32_vbr.</li> |
| 372 | <li>An optional length list of unsigned values.</li> |
| 373 | </ol> |
| 374 | </div> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 375 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 376 | <div class="doc_subsection"><a name="slots">Slots</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 377 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 378 | <p>The bytecode format uses the notion of a "slot" to reference Types |
| 379 | and Values. Since the bytecode file is a <em>direct</em> representation of |
| 380 | LLVM's intermediate representation, there is a need to represent pointers in |
| 381 | the file. Slots are used for this purpose. For example, if one has the following |
| 382 | assembly: |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 383 | </p> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 384 | <div class="doc_code"><code> %MyType = type { int, sbyte }<br> |
| 385 | %MyVar = external global %MyType |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 386 | </code></div> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 387 | <p>there are two definitions. The definition of <tt>%MyVar</tt> uses <tt>%MyType</tt>. |
| 388 | In the C++ IR this linkage between <tt>%MyVar</tt> and <tt>%MyType</tt> |
| 389 | is explicit through the use of C++ pointers. In bytecode, however, there's no |
| 390 | ability to store memory addresses. Instead, we compute and write out |
| 391 | slot numbers for every Type and Value written to the file.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 392 | <p>A slot number is simply an unsigned 32-bit integer encoded in the variable |
| 393 | bit rate scheme (see <a href="#encoding">encoding</a>). This ensures that |
| 394 | low slot numbers are encoded in one byte. Through various bits of magic LLVM |
| 395 | 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] | 396 | slot numbers with their "type plane". That is, Values of the same type |
| 397 | are written to the bytecode file in a list (sequentially). Their order in |
| 398 | that list determines their slot number. This means that slot #1 doesn't mean |
| 399 | anything unless you also specify for which type you want slot #1. Types are |
| 400 | handled specially and are always written to the file first (in the <a |
| 401 | href="#globaltypes">Global Type Pool</a>) and in such a way that both forward |
| 402 | and backward references of the types can often be resolved with a single pass |
| 403 | through the type pool. </p> |
| 404 | <p>Slot numbers are also kept small by rearranging their order. Because |
| 405 | of the structure of LLVM, certain values are much more likely to be used |
| 406 | frequently in the body of a function. For this reason, a compaction table is |
| 407 | provided in the body of a function if its use would make the function body |
| 408 | smaller. Suppose you have a function body that uses just the types "int*" and |
| 409 | "{double}" but uses them thousands of time. Its worthwhile to ensure that the |
| 410 | slot number for these types are low so they can be encoded in a single byte |
| 411 | (via vbr). This is exactly what the compaction table does.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 412 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 413 | <!-- *********************************************************************** --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 414 | <div class="doc_section"> <a name="general">General Structure</a> </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 415 | <!-- *********************************************************************** --> |
| 416 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 417 | <p>This section provides the general structure of the LLVM bytecode |
| 418 | file format. The bytecode file format requires blocks to be in a |
| 419 | certain order and nested in a particular way so that an LLVM module can |
| 420 | be constructed efficiently from the contents of the file. This ordering |
| 421 | defines a general structure for bytecode files as shown below. The |
| 422 | table below shows the order in which all block types may appear. Please |
| 423 | note that some of the blocks are optional and some may be repeated. The |
| 424 | structure is fairly loose because optional blocks, if empty, are |
| 425 | completely omitted from the file.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 426 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 427 | <tbody> |
| 428 | <tr> |
| 429 | <th>ID</th> |
| 430 | <th>Parent</th> |
| 431 | <th>Optional?</th> |
| 432 | <th>Repeated?</th> |
| 433 | <th>Level</th> |
| 434 | <th>Block Type</th> |
| 435 | <th>Description</th> |
| 436 | </tr> |
| 437 | <tr> |
| 438 | <td>N/A</td> |
| 439 | <td>File</td> |
| 440 | <td>No</td> |
| 441 | <td>No</td> |
| 442 | <td>0</td> |
| 443 | <td class="td_left"><a href="#signature">Signature</a></td> |
| 444 | <td class="td_left">This contains the file signature (magic |
| 445 | number) that identifies the file as LLVM bytecode.</td> |
| 446 | </tr> |
| 447 | <tr> |
| 448 | <td>0x01</td> |
| 449 | <td>File</td> |
| 450 | <td>No</td> |
| 451 | <td>No</td> |
| 452 | <td>0</td> |
| 453 | <td class="td_left"><a href="#module">Module</a></td> |
| 454 | <td class="td_left">This is the top level block in a bytecode |
| 455 | file. It contains all the other blocks. </td> |
| 456 | </tr> |
| 457 | <tr> |
| 458 | <td>0x06</td> |
| 459 | <td>Module</td> |
| 460 | <td>No</td> |
| 461 | <td>No</td> |
| 462 | <td>1</td> |
| 463 | <td class="td_left"> <a href="#globaltypes">Global Type Pool</a></td> |
| 464 | <td class="td_left">This block contains all the global (module) |
| 465 | level types.</td> |
| 466 | </tr> |
| 467 | <tr> |
| 468 | <td>0x05</td> |
| 469 | <td>Module</td> |
| 470 | <td>No</td> |
| 471 | <td>No</td> |
| 472 | <td>1</td> |
| 473 | <td class="td_left"> <a href="#globalinfo">Module Globals Info</a></td> |
| 474 | <td class="td_left">This block contains the type, constness, and |
| 475 | linkage for each of the global variables in the module. It also |
| 476 | contains the type of the functions and the constant initializers.</td> |
| 477 | </tr> |
| 478 | <tr> |
| 479 | <td>0x03</td> |
| 480 | <td>Module</td> |
| 481 | <td>Yes</td> |
| 482 | <td>No</td> |
| 483 | <td>1</td> |
| 484 | <td class="td_left"> <a href="#constantpool">Module Constant Pool</a></td> |
| 485 | <td class="td_left">This block contains all the global constants |
| 486 | except function arguments, global values and constant strings.</td> |
| 487 | </tr> |
| 488 | <tr> |
| 489 | <td>0x02</td> |
| 490 | <td>Module</td> |
| 491 | <td>Yes</td> |
| 492 | <td>Yes</td> |
| 493 | <td>1</td> |
| 494 | <td class="td_left"> <a href="#functiondefs">Function Definitions</a>*</td> |
| 495 | <td class="td_left">One function block is written for each |
| 496 | function in the module. The function block contains the instructions, |
| 497 | compaction table, type constant pool, and symbol table for the function.</td> |
| 498 | </tr> |
| 499 | <tr> |
| 500 | <td>0x03</td> |
| 501 | <td>Function</td> |
| 502 | <td>Yes</td> |
| 503 | <td>No</td> |
| 504 | <td>2</td> |
| 505 | <td class="td_left"> <a |
| 506 | href="#constantpool">Function Constant Pool</a></td> |
| 507 | <td class="td_left">Any constants (including types) used solely |
| 508 | within the function are emitted here in the function constant pool. </td> |
| 509 | </tr> |
| 510 | <tr> |
| 511 | <td>0x08</td> |
| 512 | <td>Function</td> |
| 513 | <td>Yes</td> |
| 514 | <td>No</td> |
| 515 | <td>2</td> |
| 516 | <td class="td_left"> <a |
| 517 | href="#compactiontable">Compaction Table</a></td> |
| 518 | <td class="td_left">This table reduces bytecode size by providing |
| 519 | a funtion-local mapping of type and value slot numbers to their global |
| 520 | slot numbers</td> |
| 521 | </tr> |
| 522 | <tr> |
| 523 | <td>0x07</td> |
| 524 | <td>Function</td> |
| 525 | <td>No</td> |
| 526 | <td>No</td> |
| 527 | <td>2</td> |
| 528 | <td class="td_left"> <a |
| 529 | href="#instructionlist">Instruction List</a></td> |
| 530 | <td class="td_left">This block contains all the instructions of |
| 531 | the function. The basic blocks are inferred by terminating |
| 532 | instructions. </td> |
| 533 | </tr> |
| 534 | <tr> |
| 535 | <td>0x04</td> |
| 536 | <td>Function</td> |
| 537 | <td>Yes</td> |
| 538 | <td>No</td> |
| 539 | <td>2</td> |
| 540 | <td class="td_left"> <a |
| 541 | href="#symtab">Function Symbol Table</a></td> |
| 542 | <td class="td_left">This symbol table provides the names for the |
| 543 | function specific values used (basic block labels mostly).</td> |
| 544 | </tr> |
| 545 | <tr> |
| 546 | <td>0x04</td> |
| 547 | <td>Module</td> |
| 548 | <td>Yes</td> |
| 549 | <td>No</td> |
| 550 | <td>1</td> |
| 551 | <td class="td_left"> <a href="#symtab">Module Symbol Table</a></td> |
| 552 | <td class="td_left">This symbol table provides the names for the |
| 553 | various entries in the file that are not function specific (global |
| 554 | vars, and functions mostly).</td> |
| 555 | </tr> |
| 556 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 557 | </table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 558 | <p>Use the links in the table for details about the contents of each of |
| 559 | the block types.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 560 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 561 | <!-- *********************************************************************** --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 562 | <div class="doc_section"> <a name="blockdefs">Block Definitions</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 563 | <!-- *********************************************************************** --> |
| 564 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 565 | <p>This section provides the detailed layout of the individual block |
| 566 | types in the LLVM bytecode file format. </p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 567 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 568 | <!-- _______________________________________________________________________ --> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 569 | <div class="doc_subsection"><a name="signature">Signature Block</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 570 | <div class="doc_text"> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 571 | <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] | 572 | It simply provides a few bytes of data to identify the file as being an LLVM |
| 573 | bytecode file. This block is always four bytes in length and differs from the |
| 574 | other blocks because there is no identifier and no block length at the start |
| 575 | 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] | 576 | </p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 577 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 578 | <tbody> |
| 579 | <tr> |
| 580 | <th><b>Type</b></th> |
| 581 | <th class="td_left"><b>Field Description</b></th> |
| 582 | </tr> |
| 583 | <tr> |
| 584 | <td><a href="#char">char</a></td> |
| 585 | <td class="td_left">Constant "l" (0x6C)</td> |
| 586 | </tr> |
| 587 | <tr> |
| 588 | <td><a href="#char">char</a></td> |
| 589 | <td class="td_left">Constant "l" (0x6C)</td> |
| 590 | </tr> |
| 591 | <tr> |
| 592 | <td><a href="#char">char</a></td> |
| 593 | <td class="td_left">Constant "v" (0x76)</td> |
| 594 | </tr> |
| 595 | <tr> |
| 596 | <td><a href="#char">char</a></td> |
| 597 | <td class="td_left">Constant "m" (0x6D)</td> |
| 598 | </tr> |
| 599 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 600 | </table> |
| 601 | </div> |
| 602 | <!-- _______________________________________________________________________ --> |
| 603 | <div class="doc_subsection"><a name="module">Module Block</a> </div> |
| 604 | <div class="doc_text"> |
| 605 | <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] | 606 | the file. The table below shows the structure of the module block. Note that it |
| 607 | only provides the module identifier, size of the module block, and the format |
| 608 | information. Everything else is contained in other blocks, described in other |
| 609 | sections.</p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 610 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 611 | <tbody> |
| 612 | <tr> |
| 613 | <th><b>Type</b></th> |
| 614 | <th class="td_left"><b>Field Description</b></th> |
| 615 | </tr> |
| 616 | <tr> |
Reid Spencer | 5bc74d5 | 2004-08-16 19:24:36 +0000 | [diff] [blame^] | 617 | <td><a href="#unsigned">unsigned</a><br></td> |
| 618 | <td class="td_left"><a href="#mod_header">Module Block Identifier |
| 619 | (0x01)</a></td> |
| 620 | </tr> |
| 621 | <tr> |
| 622 | <td><a href="#unsigned">unsigned</a></td> |
| 623 | <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] | 624 | </tr> |
| 625 | <tr> |
| 626 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 627 | <td class="td_left"><a href="#format">Format Information</a></td> |
| 628 | </tr> |
| 629 | <tr> |
| 630 | <td><a href="#block">block</a></td> |
| 631 | <td class="td_left"><a href="#globaltypes">Global Type Pool</a></td> |
| 632 | </tr> |
| 633 | <tr> |
| 634 | <td><a href="#block">block</a></td> |
| 635 | <td class="td_left"><a href="#globalinfo">Module Globals Info</a></td> |
| 636 | </tr> |
| 637 | <tr> |
| 638 | <td><a href="#block">block</a></td> |
| 639 | <td class="td_left"><a href="#constantpool">Module Constant Pool</a></td> |
| 640 | </tr> |
| 641 | <tr> |
| 642 | <td><a href="#block">block</a>*</td> |
| 643 | <td class="td_left"><a href="#functiondefs">Function Definitions</a></td> |
| 644 | </tr> |
| 645 | <tr> |
| 646 | <td><a href="#block">block</a></td> |
| 647 | <td class="td_left"><a href="#symboltable">Module Symbol Table</a></td> |
| 648 | </tr> |
| 649 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 650 | </table> |
| 651 | </div> |
Reid Spencer | 5bc74d5 | 2004-08-16 19:24:36 +0000 | [diff] [blame^] | 652 | |
| 653 | <!-- _______________________________________________________________________ --> |
| 654 | <div class="doc_subsubsection"><a name="mod_header">Module Block Header</a></div> |
| 655 | <div class="doc_text"> |
| 656 | <p>The block header for the module block uses a longer format than the other |
| 657 | blocks in a bytecode file. Specifically, instead of encoding the type and size |
| 658 | of the block into a 32-bit integer with 5-bits for type and 27-bits for size, |
| 659 | the module block header uses two 32-bit unsigned values, one for type, and one |
| 660 | for size. While the 2<sup>27</sup> byte limit on block size is sufficient for the blocks |
| 661 | contained in the module, it isn't sufficient for the module block itself |
| 662 | because we want to ensure that bytecode files as large as 2<sup>32</sup> bytes |
| 663 | are possible. For this reason, the module block (and only the module block) |
| 664 | uses a long format header.</p> |
| 665 | </div> |
| 666 | |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 667 | <!-- _______________________________________________________________________ --> |
| 668 | <div class="doc_subsubsection"><a name="format">Format Information</a></div> |
| 669 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 670 | <p>The format information field is encoded into a <a href="#uint32_vbr">uint32_vbr</a> |
| 671 | as shown in the following table.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 672 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 673 | <tbody> |
| 674 | <tr> |
| 675 | <th><b>Type</b></th> |
| 676 | <th class="td_left"><b>Description</b></th> |
| 677 | </tr> |
| 678 | <tr> |
| 679 | <td><a href="#bit">bit(0)</a></td> |
| 680 | <td class="td_left">Target is big endian?</td> |
| 681 | </tr> |
| 682 | <tr> |
| 683 | <td><a href="#bit">bit(1)</a></td> |
| 684 | <td class="td_left">On target pointers are 64-bit?</td> |
| 685 | </tr> |
| 686 | <tr> |
| 687 | <td><a href="#bit">bit(2)</a></td> |
| 688 | <td class="td_left">Target has no endianess?</td> |
| 689 | </tr> |
| 690 | <tr> |
| 691 | <td><a href="#bit">bit(3)</a></td> |
| 692 | <td class="td_left">Target has no pointer size?</td> |
| 693 | </tr> |
| 694 | <tr> |
| 695 | <td><a href="#bit">bit(4-31)</a></td> |
| 696 | <td class="td_left">Bytecode format version</td> |
| 697 | </tr> |
| 698 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 699 | </table> |
| 700 | <p> |
| 701 | Of particular note, the bytecode format number is simply a 28-bit |
| 702 | monotonically increase integer that identifies the version of the bytecode |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 703 | format (which is not directly related to the LLVM release number). The |
| 704 | bytecode versions defined so far are (note that this document only |
| 705 | describes the latest version, 1.3):</p> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 706 | <ul> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 707 | <li>#0: LLVM 1.0 & 1.1</li> |
| 708 | <li>#1: LLVM 1.2</li> |
| 709 | <li>#2: LLVM 1.2.5 (not released)</li> |
| 710 | <li>#3: LLVM 1.3<br> |
| 711 | </li> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 712 | </ul> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 713 | <p>Note that we plan to eventually expand the target description |
| 714 | capabilities |
| 715 | of bytecode files to <a href="http://llvm.cs.uiuc.edu/PR263">target |
| 716 | triples</a>. |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 717 | </p> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 718 | </div> |
| 719 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 720 | <div class="doc_subsection"><a name="globaltypes">Global Type Pool</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 721 | <div class="doc_text"> |
Chris Lattner | 2b90565 | 2004-05-24 05:35:17 +0000 | [diff] [blame] | 722 | <p>The global type pool consists of type definitions. Their order of appearance |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 723 | in the file determines their slot number (0 based). Slot numbers are |
| 724 | used to replace pointers in the intermediate representation. Each slot number |
| 725 | uniquely identifies one entry in a type plane (a collection of values of the |
| 726 | same type). Since all values have types and are associated with the order in |
| 727 | which the type pool is written, the global type pool <em>must</em> be written |
| 728 | as the first block of a module. If it is not, attempts to read the file will |
| 729 | fail because both forward and backward type resolution will not be possible.</p> |
| 730 | <p>The type pool is simply a list of type definitions, as shown in the |
| 731 | table below.</p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 732 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 733 | <tbody> |
| 734 | <tr> |
| 735 | <th><b>Type</b></th> |
| 736 | <th class="td_left"><b>Field Description</b></th> |
| 737 | </tr> |
| 738 | <tr> |
| 739 | <td><a href="#unsigned">block</a></td> |
| 740 | <td class="td_left">Type Pool Identifier (0x06) + Size<br> |
| 741 | </td> |
| 742 | </tr> |
| 743 | <tr> |
| 744 | <td><a href="#llist">llist</a>(<a href="#type">type</a>)</td> |
| 745 | <td class="td_left">A length list of type definitions.</td> |
| 746 | </tr> |
| 747 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 748 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 749 | </div> |
| 750 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 751 | <div class="doc_subsubsection"><a name="type">Type Definitions</a></div> |
| 752 | <div class="doc_text"> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 753 | <p>Types in the type pool are defined using a different format for each kind |
| 754 | of type, as given in the following sections.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 755 | <h3>Primitive Types</h3> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 756 | <p>The primitive types encompass the basic integer and floating point |
| 757 | types</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 758 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 759 | <tbody> |
| 760 | <tr> |
| 761 | <th><b>Type</b></th> |
| 762 | <th class="td_left"><b>Description</b></th> |
| 763 | </tr> |
| 764 | <tr> |
| 765 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 766 | <td class="td_left">Type ID for the primitive types (values 1 to |
| 767 | 11) <sup>1</sup></td> |
| 768 | </tr> |
| 769 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 770 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 771 | Notes: |
| 772 | <ol> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 773 | <li>The values for the Type IDs for the primitive types are provided |
| 774 | by the definition of the <code>llvm::Type::TypeID</code> enumeration |
| 775 | in <code>include/llvm/Type.h</code>. The enumeration gives the |
| 776 | following mapping: |
| 777 | <ol> |
| 778 | <li>bool</li> |
| 779 | <li>ubyte</li> |
| 780 | <li>sbyte</li> |
| 781 | <li>ushort</li> |
| 782 | <li>short</li> |
| 783 | <li>uint</li> |
| 784 | <li>int</li> |
| 785 | <li>ulong</li> |
| 786 | <li>long</li> |
| 787 | <li>float</li> |
| 788 | <li>double</li> |
| 789 | </ol> |
| 790 | </li> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 791 | </ol> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 792 | <h3>Function Types</h3> |
| 793 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 794 | <tbody> |
| 795 | <tr> |
| 796 | <th><b>Type</b></th> |
| 797 | <th class="td_left"><b>Description</b></th> |
| 798 | </tr> |
| 799 | <tr> |
| 800 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 801 | <td class="td_left">Type ID for function types (13)</td> |
| 802 | </tr> |
| 803 | <tr> |
| 804 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 805 | <td class="td_left">Slot number of function's return type.</td> |
| 806 | </tr> |
| 807 | <tr> |
| 808 | <td><a href="#llist">llist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 809 | <td class="td_left">Slot number of each argument's type.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 810 | </tr> |
| 811 | <tr> |
| 812 | <td><a href="#uint32_vbr">uint32_vbr</a>?</td> |
| 813 | <td class="td_left">Value 0 if this is a varargs function, |
| 814 | missing otherwise.</td> |
| 815 | </tr> |
| 816 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 817 | </table> |
| 818 | <h3>Structure Types</h3> |
| 819 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 820 | <tbody> |
| 821 | <tr> |
| 822 | <th><b>Type</b></th> |
| 823 | <th class="td_left"><b>Description</b></th> |
| 824 | </tr> |
| 825 | <tr> |
| 826 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 827 | <td class="td_left">Type ID for structure types (14)</td> |
| 828 | </tr> |
| 829 | <tr> |
| 830 | <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
| 831 | <td class="td_left">Slot number of each of the element's fields.</td> |
| 832 | </tr> |
| 833 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 834 | </table> |
| 835 | <h3>Array Types</h3> |
| 836 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 837 | <tbody> |
| 838 | <tr> |
| 839 | <th><b>Type</b></th> |
| 840 | <th class="td_left"><b>Description</b></th> |
| 841 | </tr> |
| 842 | <tr> |
| 843 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 844 | <td class="td_left">Type ID for Array Types (15)</td> |
| 845 | </tr> |
| 846 | <tr> |
| 847 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 848 | <td class="td_left">Slot number of array's element type.</td> |
| 849 | </tr> |
| 850 | <tr> |
| 851 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 852 | <td class="td_left">The number of elements in the array.</td> |
| 853 | </tr> |
| 854 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 855 | </table> |
| 856 | <h3>Pointer Types</h3> |
| 857 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 858 | <tbody> |
| 859 | <tr> |
| 860 | <th><b>Type</b></th> |
| 861 | <th class="td_left"><b>Description</b></th> |
| 862 | </tr> |
| 863 | <tr> |
| 864 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 865 | <td class="td_left">Type ID For Pointer Types (16)</td> |
| 866 | </tr> |
| 867 | <tr> |
| 868 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 869 | <td class="td_left">Slot number of pointer's element type.</td> |
| 870 | </tr> |
| 871 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 872 | </table> |
| 873 | <h3>Opaque Types</h3> |
| 874 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 875 | <tbody> |
| 876 | <tr> |
| 877 | <th><b>Type</b></th> |
| 878 | <th class="td_left"><b>Description</b></th> |
| 879 | </tr> |
| 880 | <tr> |
| 881 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 882 | <td class="td_left">Type ID For Opaque Types (17)</td> |
| 883 | </tr> |
| 884 | </tbody> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 885 | </table> |
| 886 | </div> |
| 887 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 888 | <div class="doc_subsection"><a name="globalinfo">Module Global Info</a> |
| 889 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 890 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 891 | <p>The module global info block contains the definitions of all global |
| 892 | variables including their initializers and the <em>declaration</em> of |
| 893 | all functions. The format is shown in the table below:</p> |
| 894 | <table> |
| 895 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 896 | <tr> |
| 897 | <th><b>Type</b></th> |
| 898 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 899 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 900 | <tr> |
| 901 | <td><a href="#block">block</a></td> |
| 902 | <td class="td_left">Module global info identifier (0x05) + size<br> |
| 903 | </td> |
| 904 | </tr> |
| 905 | <tr> |
| 906 | <td><a href="#zlist">zlist</a>(<a href="#globalvar">globalvar</a>)</td> |
| 907 | <td class="td_left">A zero terminated list of global var |
| 908 | definitions occuring in the module.</td> |
| 909 | </tr> |
| 910 | <tr> |
| 911 | <td><a href="#zlist">zlist</a>(<a href="#uint24_vbr">uint24_vbr</a>)</td> |
| 912 | <td class="td_left">A zero terminated list of function types |
| 913 | occuring in the module.</td> |
| 914 | </tr> |
| 915 | <tr> |
| 916 | <td style="vertical-align: top;"><a href="#llist">llist</a>(<a |
| 917 | href="#string">string</a>)<br> |
| 918 | </td> |
| 919 | <td style="vertical-align: top; text-align: left;">A length list |
| 920 | of strings that specify the names of the libraries that this module |
| 921 | depends upon.<br> |
| 922 | </td> |
| 923 | </tr> |
| 924 | <tr> |
| 925 | <td style="vertical-align: top;"><a href="#string">string</a><br> |
| 926 | </td> |
| 927 | <td style="vertical-align: top; text-align: left;">The target |
| 928 | triple for the module (blank means no target triple specified, i.e. a |
| 929 | platform independent module).<br> |
| 930 | </td> |
| 931 | </tr> |
| 932 | </tbody> |
| 933 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 934 | </div> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 935 | <!-- _______________________________________________________________________ --> |
| 936 | <div class="doc_subsubsection"><a name="globalvar">Global Variable Field</a> |
| 937 | </div> |
| 938 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 939 | <p>Global variables are written using an <a href="#uint32_vbr">uint32_vbr</a> |
| 940 | that encodes information about the global variable and a list of the |
| 941 | constant initializers for the global var, if any.</p> |
| 942 | <p>The table below provides the bit layout of the first <a |
| 943 | href="#uint32_vbr">uint32_vbr</a> that describes the global variable.</p> |
| 944 | <table> |
| 945 | <tbody> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 946 | <tr> |
| 947 | <th><b>Type</b></th> |
| 948 | <th class="td_left"><b>Description</b></th> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 949 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 950 | <tr> |
| 951 | <td><a href="#bit">bit(0)</a></td> |
| 952 | <td class="td_left">Is constant?</td> |
| 953 | </tr> |
| 954 | <tr> |
| 955 | <td><a href="#bit">bit(1)</a></td> |
| 956 | <td class="td_left">Has initializer? Note that this bit |
| 957 | determines whether the constant initializer field (described below) |
| 958 | follows. </td> |
| 959 | </tr> |
| 960 | <tr> |
| 961 | <td><a href="#bit">bit(2-4)</a></td> |
| 962 | <td class="td_left">Linkage type: 0=External, 1=Weak, |
| 963 | 2=Appending, 3=Internal, 4=LinkOnce</td> |
| 964 | </tr> |
| 965 | <tr> |
| 966 | <td><a href="#bit">bit(5-31)</a></td> |
| 967 | <td class="td_left">Slot number of type for the global variable.</td> |
| 968 | </tr> |
| 969 | </tbody> |
| 970 | </table> |
| 971 | <p>The table below provides the format of the constant initializers for |
| 972 | the global variable field, if it has one.</p> |
| 973 | <table> |
| 974 | <tbody> |
| 975 | <tr> |
| 976 | <th><b>Type</b></th> |
| 977 | <th class="td_left"><b>Description</b></th> |
| 978 | </tr> |
| 979 | <tr> |
| 980 | <td>(<a href="#zlist">zlist</a>(<a href="#uint32_vbr">uint32_vbr</a>))? |
| 981 | </td> |
| 982 | <td class="td_left">An optional zero-terminated list of slot |
| 983 | numbers of the global variable's constant initializer.</td> |
| 984 | </tr> |
| 985 | </tbody> |
| 986 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 987 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 988 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 989 | <div class="doc_subsection"><a name="constantpool">Constant Pool</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 990 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 991 | <p>A constant pool defines as set of constant values. There are |
| 992 | actually two types of constant pool blocks: one for modules and one for |
| 993 | functions. For modules, the block begins with the constant strings |
| 994 | encountered anywhere in the module. For functions, the block begins |
| 995 | with types only encountered in the function. In both cases the header |
| 996 | is identical. The tables that follow, show the header, module constant |
| 997 | pool preamble, function constant pool preamble, and the part common to |
| 998 | both function and module constant pools.</p> |
| 999 | <p><b>Common Block Header</b></p> |
| 1000 | <table> |
| 1001 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1002 | <tr> |
| 1003 | <th><b>Type</b></th> |
| 1004 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1005 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1006 | <tr> |
| 1007 | <td><a href="#block">block</a></td> |
| 1008 | <td class="td_left">Constant pool identifier (0x03) + size<br> |
| 1009 | </td> |
| 1010 | </tr> |
| 1011 | </tbody> |
| 1012 | </table> |
| 1013 | <p><b>Module Constant Pool Preamble (constant strings)</b></p> |
| 1014 | <table> |
| 1015 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1016 | <tr> |
| 1017 | <th><b>Type</b></th> |
| 1018 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1019 | </tr> |
| 1020 | <tr> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1021 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1022 | <td class="td_left">The number of constant strings that follow.</td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1023 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1024 | <tr> |
| 1025 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1026 | <td class="td_left">Zero. This identifies the following "plane" |
| 1027 | as containing the constant strings. This is needed to identify it |
| 1028 | uniquely from other constant planes that follow. </td> |
| 1029 | </tr> |
| 1030 | <tr> |
| 1031 | <td><a href="#uint24_vbr">uint24_vbr</a>+</td> |
| 1032 | <td class="td_left">Slot number of the constant string's type. |
| 1033 | Note that the constant string's type implicitly defines the length of |
| 1034 | the string. </td> |
| 1035 | </tr> |
| 1036 | </tbody> |
| 1037 | </table> |
| 1038 | <p><b>Function Constant Pool Preamble (function types)</b></p> |
| 1039 | <p>The structure of the types for functions is identical to the <a |
| 1040 | href="#globaltypes">Global Type Pool</a>. Please refer to that section |
| 1041 | for the details. </p> |
| 1042 | <p><b>Common Part (other constants)</b></p> |
| 1043 | <table> |
| 1044 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1045 | <tr> |
| 1046 | <th><b>Type</b></th> |
| 1047 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1048 | </tr> |
| 1049 | <tr> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1050 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1051 | <td class="td_left">Number of entries in this type plane.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1052 | </tr> |
| 1053 | <tr> |
| 1054 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1055 | <td class="td_left">Type slot number of this plane.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1056 | </tr> |
| 1057 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 1058 | <td><a href="#constant">constant</a>+</td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1059 | <td class="td_left">The definition of a constant (see below).</td> |
| 1060 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1061 | </tbody> |
| 1062 | </table> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1063 | </div> |
| 1064 | <!-- _______________________________________________________________________ --> |
| 1065 | <div class="doc_subsubsection"><a name="constant">Constant Field</a></div> |
| 1066 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1067 | <p>Constants come in many shapes and flavors. The sections that followe |
| 1068 | define the format for each of them. All constants start with a <a |
| 1069 | href="#uint32_vbr">uint32_vbr</a> encoded integer that provides the |
| 1070 | number of operands for the constant. For primitive, structure, and |
| 1071 | array constants, this will always be zero since those types of |
| 1072 | constants have no operands. In this case, we have the following field |
| 1073 | definitions:</p> |
| 1074 | <ul> |
| 1075 | <li><b>Bool</b>. This is written as an <a href="#uint32_vbr">uint32_vbr</a> |
| 1076 | of value 1U or 0U.</li> |
| 1077 | <li><b>Signed Integers (sbyte,short,int,long)</b>. These are written |
| 1078 | as an <a href="#int64_vbr">int64_vbr</a> with the corresponding value.</li> |
| 1079 | <li><b>Unsigned Integers (ubyte,ushort,uint,ulong)</b>. These are |
| 1080 | written as an <a href="#uint64_vbr">uint64_vbr</a> with the |
| 1081 | corresponding value. </li> |
| 1082 | <li><b>Floating Point</b>. Both the float and double types are |
| 1083 | written literally in binary format.</li> |
| 1084 | <li><b>Arrays</b>. Arrays are written simply as a list of <a |
| 1085 | href="#uint32_vbr">uint32_vbr</a> encoded slot numbers to the constant |
| 1086 | element values.</li> |
| 1087 | <li><b>Structures</b>. Structures are written simply as a list of <a |
| 1088 | href="#uint32_vbr">uint32_vbr</a> encoded slot numbers to the constant |
| 1089 | field values of the structure.</li> |
| 1090 | </ul> |
| 1091 | <p>When the number of operands to the constant is non-zero, we have a |
| 1092 | constant expression and its field format is provided in the table below.</p> |
| 1093 | <table> |
| 1094 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1095 | <tr> |
| 1096 | <th><b>Type</b></th> |
| 1097 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1098 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1099 | <tr> |
| 1100 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1101 | <td class="td_left">Op code of the instruction for the constant |
| 1102 | expression.</td> |
| 1103 | </tr> |
| 1104 | <tr> |
| 1105 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1106 | <td class="td_left">The slot number of the constant value for an |
| 1107 | operand.<sup>1</sup></td> |
| 1108 | </tr> |
| 1109 | <tr> |
| 1110 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 1111 | <td class="td_left">The slot number for the type of the constant |
| 1112 | value for an operand.<sup>1</sup></td> |
| 1113 | </tr> |
| 1114 | </tbody> |
| 1115 | </table> |
| 1116 | Notes: |
| 1117 | <ol> |
| 1118 | <li>Both these fields are repeatable but only in pairs.</li> |
| 1119 | </ol> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1120 | </div> |
| 1121 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1122 | <div class="doc_subsection"><a name="functiondefs">Function Definition</a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1123 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1124 | <p>Function definitions contain the linkage, constant pool or |
| 1125 | compaction table, instruction list, and symbol table for a function. |
| 1126 | The following table shows the structure of a function definition.</p> |
| 1127 | <table> |
| 1128 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1129 | <tr> |
| 1130 | <th><b>Type</b></th> |
| 1131 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1132 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1133 | <tr> |
| 1134 | <td><a href="#block">block</a><br> |
| 1135 | </td> |
| 1136 | <td class="td_left">Function definition block identifier (0x02) + |
| 1137 | size<br> |
| 1138 | </td> |
| 1139 | </tr> |
| 1140 | <tr> |
| 1141 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1142 | <td class="td_left">The linkage type of the function: 0=External, |
| 1143 | 1=Weak, 2=Appending, 3=Internal, 4=LinkOnce<sup>1</sup></td> |
| 1144 | </tr> |
| 1145 | <tr> |
| 1146 | <td><a href="#block">block</a></td> |
| 1147 | <td class="td_left">The <a href="#constantpool">constant pool</a> |
| 1148 | block for this function.<sup>2</sup></td> |
| 1149 | </tr> |
| 1150 | <tr> |
| 1151 | <td><a href="#block">block</a></td> |
| 1152 | <td class="td_left">The <a href="#compactiontable">compaction |
| 1153 | table</a> block for the function.<sup>2</sup></td> |
| 1154 | </tr> |
| 1155 | <tr> |
| 1156 | <td><a href="#block">block</a></td> |
| 1157 | <td class="td_left">The <a href="#instructionlist">instruction |
| 1158 | list</a> for the function.</td> |
| 1159 | </tr> |
| 1160 | <tr> |
| 1161 | <td><a href="#block">block</a></td> |
| 1162 | <td class="td_left">The function's <a href="#symboltable">symbol |
| 1163 | table</a> containing only those symbols pertinent to the function |
| 1164 | (mostly block labels).</td> |
| 1165 | </tr> |
| 1166 | </tbody> |
| 1167 | </table> |
| 1168 | Notes: |
| 1169 | <ol> |
| 1170 | <li>Note that if the linkage type is "External" then none of the |
| 1171 | other fields will be present as the function is defined elsewhere.</li> |
| 1172 | <li>Note that only one of the constant pool or compaction table will |
| 1173 | be written. Compaction tables are only written if they will actually |
| 1174 | save bytecode space. If not, then a regular constant pool is written.</li> |
| 1175 | </ol> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1176 | </div> |
| 1177 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1178 | <div class="doc_subsection"><a name="compactiontable">Compaction Table</a> |
| 1179 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1180 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1181 | <p>Compaction tables are part of a function definition. They are merely |
| 1182 | a device for reducing the size of bytecode files. The size of a |
| 1183 | bytecode file is dependent on the <em>value</em> of the slot numbers |
| 1184 | used because larger values use more bytes in the variable bit rate |
| 1185 | encoding scheme. Furthermore, the compressed instruction format |
| 1186 | reserves only six bits for the type of the instruction. In large |
| 1187 | modules, declaring hundreds or thousands of types, the values of the |
| 1188 | slot numbers can be quite large. However, functions may use only a |
| 1189 | small fraction of the global types. In such cases a compaction table is |
| 1190 | created that maps the global type and value slot numbers to smaller |
| 1191 | values used by a function. Functions will contain either a |
| 1192 | function-specific constant pool <em>or</em> a compaction table but not |
| 1193 | both. Compaction tables have the format shown in the table below.</p> |
| 1194 | <table> |
| 1195 | <tbody> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1196 | <tr> |
| 1197 | <th><b>Type</b></th> |
| 1198 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1199 | </tr> |
| 1200 | <tr> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1201 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1202 | <td class="td_left">The number of types that follow</td> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1203 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1204 | <tr> |
| 1205 | <td><a href="#uint24_vbr">uint24_vbr</a>+</td> |
| 1206 | <td class="td_left">The slot number in the global type plane of |
| 1207 | the type that will be referenced in the function with the index of this |
| 1208 | entry in the compaction table.</td> |
| 1209 | </tr> |
| 1210 | <tr> |
| 1211 | <td><a href="#type_len">type_len</a></td> |
| 1212 | <td class="td_left">An encoding of the type and number of values |
| 1213 | that follow. This field's encoding varies depending on the size of the |
| 1214 | type plane. See <a href="#type_len">Type and Length</a> for further |
| 1215 | details.</td> |
| 1216 | </tr> |
| 1217 | <tr> |
| 1218 | <td><a href="#uint32_vbr">uint32_vbr</a>+</td> |
| 1219 | <td class="td_left">The slot number in the globals of the value |
| 1220 | that will be referenced in the function with the index of this entry in |
| 1221 | the compaction table</td> |
| 1222 | </tr> |
| 1223 | </tbody> |
| 1224 | </table> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1225 | </div> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1226 | <!-- _______________________________________________________________________ --> |
| 1227 | <div class="doc_subsubsection"><a name="type_len">Type and Length</a></div> |
| 1228 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1229 | <p>The type and length of a compaction table type plane is encoded |
| 1230 | differently depending on the length of the plane. For planes of length |
| 1231 | 1 or 2, the length is encoded into bits 0 and 1 of a <a |
| 1232 | href="#uint32_vbr">uint32_vbr</a> and the type is encoded into bits |
| 1233 | 2-31. Because type numbers are often small, this often saves an extra |
| 1234 | byte per plane. If the length of the plane is greater than 2 then the |
| 1235 | encoding uses a <a href="#uint32_vbr">uint32_vbr</a> for each of the |
| 1236 | length and type, in that order.</p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1237 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1238 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1239 | <div class="doc_subsection"><a name="instructionlist">Instruction List</a> |
| 1240 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1241 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1242 | <p>The instructions in a function are written as a simple list. Basic |
| 1243 | blocks are inferred by the terminating instruction types. The format of |
| 1244 | the block is given in the following table.</p> |
| 1245 | <table> |
| 1246 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1247 | <tr> |
| 1248 | <th><b>Type</b></th> |
| 1249 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1250 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1251 | <tr> |
| 1252 | <td><a href="#block">block</a><br> |
| 1253 | </td> |
| 1254 | <td class="td_left">Instruction list identifier (0x07) + size<br> |
| 1255 | </td> |
| 1256 | </tr> |
| 1257 | <tr> |
| 1258 | <td><a href="#instruction">instruction</a>+</td> |
| 1259 | <td class="td_left">An instruction. Instructions have a variety |
| 1260 | of formats. See <a href="#instruction">Instructions</a> for details.</td> |
| 1261 | </tr> |
| 1262 | </tbody> |
| 1263 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1264 | </div> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1265 | <!-- _______________________________________________________________________ --> |
| 1266 | <div class="doc_subsubsection"><a name="instruction">Instructions</a></div> |
| 1267 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1268 | <p>For brevity, instructions are written in one of four formats, |
| 1269 | depending on the number of operands to the instruction. Each |
| 1270 | instruction begins with a <a href="#uint32_vbr">uint32_vbr</a> that |
| 1271 | encodes the type of the instruction as well as other things. The tables |
| 1272 | that follow describe the format of this first word of each instruction.</p> |
| 1273 | <p><b>Instruction Format 0</b></p> |
| 1274 | <p>This format is used for a few instructions that can't easily be |
| 1275 | optimized because they have large numbers of operands (e.g. PHI Node or |
| 1276 | getelementptr). Each of the opcode, type, and operand fields is as |
| 1277 | successive fields.</p> |
| 1278 | <table> |
| 1279 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1280 | <tr> |
| 1281 | <th><b>Type</b></th> |
| 1282 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1283 | </tr> |
| 1284 | <tr> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1285 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1286 | <td class="td_left">Specifies the opcode of the instruction. Note |
| 1287 | that for compatibility with the other instruction formats, the opcode |
| 1288 | is shifted left by 2 bits. Bits 0 and 1 must have value zero for this |
| 1289 | format.</td> |
| 1290 | </tr> |
| 1291 | <tr> |
| 1292 | <td><a href="#uint24_vbr">uint24_vbr</a></td> |
| 1293 | <td class="td_left">Provides the slot number of the result type |
| 1294 | of the instruction</td> |
| 1295 | </tr> |
| 1296 | <tr> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1297 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1298 | <td class="td_left">The number of operands that follow.</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1299 | </tr> |
| 1300 | <tr> |
Reid Spencer | 82c4671 | 2004-07-07 13:34:26 +0000 | [diff] [blame] | 1301 | <td><a href="#uint32_vbr">uint32_vbr</a>+</td> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1302 | <td class="td_left">The slot number of the value(s) for the |
| 1303 | operand(s). <sup>1</sup></td> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1304 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1305 | </tbody> |
| 1306 | </table> |
| 1307 | Notes: |
| 1308 | <ol> |
| 1309 | <li>Note that if the instruction is a getelementptr and the type of |
| 1310 | the operand is a sequential type (array or pointer) then the slot |
| 1311 | number is shifted up two bits and the low order bits will encode the |
| 1312 | type of index used, as follows: 0=uint, 1=int, 2=ulong, 3=long.</li> |
| 1313 | </ol> |
| 1314 | <p><b>Instruction Format 1</b></p> |
| 1315 | <p>This format encodes the opcode, type and a single operand into a |
| 1316 | single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1317 | <table> |
| 1318 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1319 | <tr> |
| 1320 | <th><b>Bits</b></th> |
| 1321 | <th><b>Type</b></th> |
| 1322 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1323 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1324 | <tr> |
| 1325 | <td>0-1</td> |
| 1326 | <td>constant "1"</td> |
| 1327 | <td class="td_left">These two bits must be the value 1 which |
| 1328 | identifies this as an instruction of format 1.</td> |
| 1329 | </tr> |
| 1330 | <tr> |
| 1331 | <td>2-7</td> |
| 1332 | <td><a href="#opcodes">opcode</a></td> |
| 1333 | <td class="td_left">Specifies the opcode of the instruction. Note |
| 1334 | that the maximum opcode value is 63.</td> |
| 1335 | </tr> |
| 1336 | <tr> |
| 1337 | <td>8-19</td> |
| 1338 | <td><a href="#unsigned">unsigned</a></td> |
| 1339 | <td class="td_left">Specifies the slot number of the type for |
| 1340 | this instruction. Maximum slot number is 2<sup>12</sup>-1=4095.</td> |
| 1341 | </tr> |
| 1342 | <tr> |
| 1343 | <td>20-31</td> |
| 1344 | <td><a href="#unsigned">unsigned</a></td> |
| 1345 | <td class="td_left">Specifies the slot number of the value for |
| 1346 | the first operand. Maximum slot number is 2<sup>12</sup>-1=4095. Note |
| 1347 | that the value 2<sup>12</sup>-1 denotes zero operands.</td> |
| 1348 | </tr> |
| 1349 | </tbody> |
| 1350 | </table> |
| 1351 | <p><b>Instruction Format 2</b></p> |
| 1352 | <p>This format encodes the opcode, type and two operands into a single <a |
| 1353 | href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1354 | <table> |
| 1355 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1356 | <tr> |
| 1357 | <th><b>Bits</b></th> |
| 1358 | <th><b>Type</b></th> |
| 1359 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1360 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1361 | <tr> |
| 1362 | <td>0-1</td> |
| 1363 | <td>constant "2"</td> |
| 1364 | <td class="td_left">These two bits must be the value 2 which |
| 1365 | identifies this as an instruction of format 2.</td> |
| 1366 | </tr> |
| 1367 | <tr> |
| 1368 | <td>2-7</td> |
| 1369 | <td><a href="#opcodes">opcode</a></td> |
| 1370 | <td class="td_left">Specifies the opcode of the instruction. Note |
| 1371 | that the maximum opcode value is 63.</td> |
| 1372 | </tr> |
| 1373 | <tr> |
| 1374 | <td>8-15</td> |
| 1375 | <td><a href="#unsigned">unsigned</a></td> |
| 1376 | <td class="td_left">Specifies the slot number of the type for |
| 1377 | this instruction. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1378 | </tr> |
| 1379 | <tr> |
| 1380 | <td>16-23</td> |
| 1381 | <td><a href="#unsigned">unsigned</a></td> |
| 1382 | <td class="td_left">Specifies the slot number of the value for |
| 1383 | the first operand. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1384 | </tr> |
| 1385 | <tr> |
| 1386 | <td>24-31</td> |
| 1387 | <td><a href="#unsigned">unsigned</a></td> |
| 1388 | <td class="td_left">Specifies the slot number of the value for |
| 1389 | the second operand. Maximum slot number is 2<sup>8</sup>-1=255.</td> |
| 1390 | </tr> |
| 1391 | </tbody> |
| 1392 | </table> |
| 1393 | <p><b>Instruction Format 3</b></p> |
| 1394 | <p>This format encodes the opcode, type and three operands into a |
| 1395 | single <a href="#uint32_vbr">uint32_vbr</a> as follows:</p> |
| 1396 | <table> |
| 1397 | <tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1398 | <tr> |
| 1399 | <th><b>Bits</b></th> |
| 1400 | <th><b>Type</b></th> |
| 1401 | <th class="td_left"><b>Field Description</b></th> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1402 | </tr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1403 | <tr> |
| 1404 | <td>0-1</td> |
| 1405 | <td>constant "3"</td> |
| 1406 | <td class="td_left">These two bits must be the value 3 which |
| 1407 | identifies this as an instruction of format 3.</td> |
| 1408 | </tr> |
| 1409 | <tr> |
| 1410 | <td>2-7</td> |
| 1411 | <td><a href="#opcodes">opcode</a></td> |
| 1412 | <td class="td_left">Specifies the opcode of the instruction. Note |
| 1413 | that the maximum opcode value is 63.</td> |
| 1414 | </tr> |
| 1415 | <tr> |
| 1416 | <td>8-13</td> |
| 1417 | <td><a href="#unsigned">unsigned</a></td> |
| 1418 | <td class="td_left">Specifies the slot number of the type for |
| 1419 | this instruction. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1420 | </tr> |
| 1421 | <tr> |
| 1422 | <td>14-19</td> |
| 1423 | <td><a href="#unsigned">unsigned</a></td> |
| 1424 | <td class="td_left">Specifies the slot number of the value for |
| 1425 | the first operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1426 | </tr> |
| 1427 | <tr> |
| 1428 | <td>20-25</td> |
| 1429 | <td><a href="#unsigned">unsigned</a></td> |
| 1430 | <td class="td_left">Specifies the slot number of the value for |
| 1431 | the second operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1432 | </tr> |
| 1433 | <tr> |
| 1434 | <td>26-31</td> |
| 1435 | <td><a href="#unsigned">unsigned</a></td> |
| 1436 | <td class="td_left">Specifies the slot number of the value for |
| 1437 | the third operand. Maximum slot number is 2<sup>6</sup>-1=63.</td> |
| 1438 | </tr> |
| 1439 | </tbody> |
| 1440 | </table> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1441 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1442 | <!-- _______________________________________________________________________ --> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 1443 | <div class="doc_subsection"><a name="symtab">Symbol Table</a> </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1444 | <div class="doc_text"> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 1445 | <p>A symbol table can be put out in conjunction with a module or a function. |
| 1446 | A symbol table is a list of type planes. Each type plane starts with the number |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1447 | of entries in the plane and the type plane's slot number (so the type |
| 1448 | can be looked up in the global type pool). For each entry in a type |
| 1449 | plane, the slot number of the value and the name associated with that |
| 1450 | value are written. The format is given in the table below. </p> |
Reid Spencer | 2cc3615 | 2004-07-05 19:04:27 +0000 | [diff] [blame] | 1451 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1452 | <tbody> |
| 1453 | <tr> |
| 1454 | <th><b>Type</b></th> |
| 1455 | <th class="td_left"><b>Field Description</b></th> |
| 1456 | </tr> |
| 1457 | <tr> |
| 1458 | <td><a href="#block">block</a><br> |
| 1459 | </td> |
| 1460 | <td class="td_left">Symbol Table Identifier (0x04)</td> |
| 1461 | </tr> |
| 1462 | <tr> |
| 1463 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1464 | <td class="td_left">Number of entries in type plane</td> |
| 1465 | </tr> |
| 1466 | <tr> |
| 1467 | <td><a href="#symtab_entry">symtab_entry</a>*</td> |
| 1468 | <td class="td_left">Provides the slot number of the type and its |
| 1469 | name.</td> |
| 1470 | </tr> |
| 1471 | <tr> |
| 1472 | <td><a href="#symtab_plane">symtab_plane</a>*</td> |
| 1473 | <td class="td_left">A type plane containing value slot number and |
| 1474 | name for all values of the same type.</td> |
| 1475 | </tr> |
| 1476 | </tbody> |
Reid Spencer | b39021b | 2004-05-23 17:05:09 +0000 | [diff] [blame] | 1477 | </table> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1478 | </div> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1479 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1480 | <div class="doc_subsubsection"> <a name="symtab_plane">Symbol Table |
| 1481 | Plane</a> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1482 | </div> |
| 1483 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1484 | <p>A symbol table plane provides the symbol table entries for all |
| 1485 | 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] | 1486 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1487 | <tbody> |
| 1488 | <tr> |
| 1489 | <th><b>Type</b></th> |
| 1490 | <th class="td_left"><b>Field Description</b></th> |
| 1491 | </tr> |
| 1492 | <tr> |
| 1493 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1494 | <td class="td_left">Number of entries in this plane.</td> |
| 1495 | </tr> |
| 1496 | <tr> |
| 1497 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1498 | <td class="td_left">Slot number of type for this plane.</td> |
| 1499 | </tr> |
| 1500 | <tr> |
| 1501 | <td><a href="#symtab_entry">symtab_entry</a>+</td> |
| 1502 | <td class="td_left">The symbol table entries for this plane.</td> |
| 1503 | </tr> |
| 1504 | </tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1505 | </table> |
| 1506 | </div> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1507 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1508 | <div class="doc_subsubsection"> <a name="symtab_entry">Symbol Table |
| 1509 | Entry</a> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1510 | </div> |
| 1511 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1512 | <p>A symbol table entry provides the assocation between a type or |
| 1513 | value's slot number and the name given to that type or value. The |
| 1514 | format is given in the following table:</p> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1515 | <table> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1516 | <tbody> |
| 1517 | <tr> |
| 1518 | <th><b>Type</b></th> |
| 1519 | <th class="td_left"><b>Field Description</b></th> |
| 1520 | </tr> |
| 1521 | <tr> |
| 1522 | <td><a href="#uint32_vbr">uint24_vbr</a></td> |
| 1523 | <td class="td_left">Slot number of the type or value being given |
| 1524 | a name. </td> |
| 1525 | </tr> |
| 1526 | <tr> |
| 1527 | <td><a href="#uint32_vbr">uint32_vbr</a></td> |
| 1528 | <td class="td_left">Length of the character array that follows.</td> |
| 1529 | </tr> |
| 1530 | <tr> |
| 1531 | <td><a href="#char">char</a>+</td> |
| 1532 | <td class="td_left">The characters of the name.</td> |
| 1533 | </tr> |
| 1534 | </tbody> |
Reid Spencer | 51f31e0 | 2004-07-05 22:28:02 +0000 | [diff] [blame] | 1535 | </table> |
| 1536 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1537 | <!-- *********************************************************************** --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1538 | <div class="doc_section"> <a name="versiondiffs">Version Differences</a> |
| 1539 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1540 | <!-- *********************************************************************** --> |
| 1541 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1542 | <p>This section describes the differences in the Bytecode Format across |
| 1543 | LLVM |
| 1544 | versions. The versions are listed in reverse order because it assumes |
| 1545 | the current version is as documented in the previous sections. Each |
| 1546 | section here |
Chris Lattner | 1cc070c | 2004-07-05 18:05:48 +0000 | [diff] [blame] | 1547 | 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] | 1548 | </p> |
| 1549 | </div> |
| 1550 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1551 | <div class="doc_subsection"><a name="vers12">Version 1.2 Differences |
| 1552 | From 1.3</a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1553 | <!-- _______________________________________________________________________ --> |
| 1554 | <div class="doc_subsubsection">Type Derives From Value</div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1555 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1556 | <p>In version 1.2, the Type class in the LLVM IR derives from the Value |
| 1557 | class. This is not the case in version 1.3. Consequently, in version |
| 1558 | 1.2 the notion of a "Type Type" was used to write out values that were |
| 1559 | Types. The types always occuped plane 12 (corresponding to the |
| 1560 | TypeTyID) of any type planed set of values. In 1.3 this representation |
| 1561 | is not convenient because the TypeTyID (12) is not present and its |
| 1562 | value is now used for LabelTyID. Consequently, the data structures |
| 1563 | written that involve types do so by writing all the types first and |
| 1564 | then each of the value planes according to those types. In version 1.2, |
| 1565 | the types would have been written intermingled with the values.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1566 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1567 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1568 | <div class="doc_subsubsection">Restricted getelementptr Types</div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1569 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1570 | <p>In version 1.2, the getelementptr instruction required a ubyte type |
| 1571 | index for accessing a structure field and a long type index for |
| 1572 | accessing an array element. Consequently, it was only possible to |
| 1573 | access structures of 255 or fewer elements. Starting in version 1.3, |
| 1574 | this restriction was lifted. Structures must now be indexed with uint |
| 1575 | constants. Arrays may now be indexed with int, uint, long, or ulong |
| 1576 | typed values. The consequence of this was that the bytecode format had |
| 1577 | 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] | 1578 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1579 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1580 | <div class="doc_subsubsection">Short Block Headers</div> |
| 1581 | <div class="doc_text"> |
| 1582 | <p>In version 1.2, block headers were always 8 bytes being comprised of |
| 1583 | both an unsigned integer type and an unsigned integer size. For very |
| 1584 | small modules, these block headers turn out to be a large fraction of |
| 1585 | the total bytecode file size. In an attempt to make these small files |
| 1586 | smaller, the type and size information was encoded into a single |
| 1587 | unsigned integer (4 bytes) comprised of 5 bits for the block type |
| 1588 | (maximum 31 block types) and 27 bits for the block size (max |
| 1589 | ~134MBytes). These limits seemed sufficient for any blocks or sizes |
| 1590 | forseen in the future. Note that the module block, which encloses all |
| 1591 | the other blocks is still written as 8 bytes since bytecode files |
| 1592 | larger than 134MBytes might be possible.</p> |
| 1593 | </div> |
| 1594 | <!-- _______________________________________________________________________ --> |
| 1595 | <div class="doc_subsubsection">Dependent Libraries and Target Triples</div> |
| 1596 | <div class="doc_text"> |
| 1597 | <p>In version 1.2, the bytecode format does not store module's target |
| 1598 | triple or dependent. These fields have been added to the end of the <a |
| 1599 | href="#globalinfo">module global info block</a>. The purpose of these |
| 1600 | fields is to allow a front end compiler to specifiy that the generated |
| 1601 | module is specific to a particular target triple (operating |
| 1602 | system/manufacturer/processor) which makes it non-portable; and to |
| 1603 | allow front end compilers to specify the list of libraries that the |
| 1604 | module depends on for successful linking.</p> |
| 1605 | </div> |
| 1606 | <!-- _______________________________________________________________________ --> |
| 1607 | <div class="doc_subsubsection">Types Restricted to 24-bits</div> |
| 1608 | <div class="doc_text"> |
| 1609 | <p>In version 1.2, type slot identifiers were written as 32-bit VBR |
| 1610 | quantities. In 1.3 this has been reduced to 24-bits in order to ensure |
| 1611 | that it is not possible to overflow the type field of a global variable |
| 1612 | definition. 24-bits for type slot numbers is deemed sufficient for any |
| 1613 | practical use of LLVM.</p> |
| 1614 | </div> |
| 1615 | <!-- _______________________________________________________________________ --> |
| 1616 | <!-- _______________________________________________________________________ --> |
| 1617 | <div class="doc_subsection"><a name="vers11">Version 1.1 Differences |
| 1618 | From 1.2 </a></div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1619 | <!-- _______________________________________________________________________ --> |
| 1620 | <div class="doc_subsubsection">Explicit Primitive Zeros</div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1621 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1622 | <p>In version 1.1, the zero value for primitives was explicitly encoded |
| 1623 | into the bytecode format. Since these zero values are constant values |
| 1624 | in the LLVM IR and never change, there is no reason to explicitly |
| 1625 | encode them. This explicit encoding was removed in version 1.2.</p> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1626 | </div> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1627 | <!-- _______________________________________________________________________ --> |
| 1628 | <div class="doc_subsubsection">Inconsistent Module Global Info</div> |
| 1629 | <div class="doc_text"> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1630 | <p>In version 1.1, the Module Global Info block was not aligned causing |
| 1631 | the next block to be read in on an unaligned boundary. This problem was |
| 1632 | corrected in version 1.2.<br> |
| 1633 | <br> |
| 1634 | </p> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1635 | </div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1636 | <!-- _______________________________________________________________________ --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1637 | <div class="doc_subsection"><a name="vers10">Version 1.0 Differences |
| 1638 | From 1.1</a></div> |
Reid Spencer | 7c76d33 | 2004-06-08 07:41:41 +0000 | [diff] [blame] | 1639 | <div class="doc_text"> |
Reid Spencer | 1ab929c | 2004-07-05 08:18:07 +0000 | [diff] [blame] | 1640 | <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] | 1641 | </div> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1642 | <!-- *********************************************************************** --> |
| 1643 | <hr> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1644 | <address> <a href="http://jigsaw.w3.org/css-validator/check/referer"><img |
| 1645 | src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a> |
| 1646 | <a href="http://validator.w3.org/check/referer"><img |
| 1647 | src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a> |
| 1648 | <a href="mailto:rspencer@x10sys.com">Reid Spencer</a> and <a |
| 1649 | href="mailto:sabre@nondot.org">Chris Lattner</a><br> |
| 1650 | <a href="http://llvm.cs.uiuc.edu">The LLVM Compiler Infrastructure</a><br> |
| 1651 | Last modified: $Date$ |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1652 | </address> |
Reid Spencer | 5002661 | 2004-05-22 02:28:36 +0000 | [diff] [blame] | 1653 | <!-- vim: sw=2 |
| 1654 | --> |
Reid Spencer | 9bd2be2 | 2004-07-29 00:13:04 +0000 | [diff] [blame] | 1655 | </body> |
| 1656 | </html> |