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