Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1 | .. role:: raw-html(raw) |
| 2 | :format: html |
| 3 | |
| 4 | ======================== |
| 5 | LLVM Bitcode File Format |
| 6 | ======================== |
| 7 | |
| 8 | .. contents:: |
| 9 | :local: |
| 10 | |
| 11 | Abstract |
| 12 | ======== |
| 13 | |
| 14 | This document describes the LLVM bitstream file format and the encoding of the |
| 15 | LLVM IR into it. |
| 16 | |
| 17 | Overview |
| 18 | ======== |
| 19 | |
| 20 | What is commonly known as the LLVM bitcode file format (also, sometimes |
| 21 | anachronistically known as bytecode) is actually two things: a `bitstream |
| 22 | container format`_ and an `encoding of LLVM IR`_ into the container format. |
| 23 | |
| 24 | The bitstream format is an abstract encoding of structured data, very similar to |
| 25 | XML in some ways. Like XML, bitstream files contain tags, and nested |
| 26 | structures, and you can parse the file without having to understand the tags. |
| 27 | Unlike XML, the bitstream format is a binary encoding, and unlike XML it |
| 28 | provides a mechanism for the file to self-describe "abbreviations", which are |
| 29 | effectively size optimizations for the content. |
| 30 | |
Peter Collingbourne | 10039c0 | 2014-09-18 21:28:49 +0000 | [diff] [blame] | 31 | LLVM IR files may be optionally embedded into a `wrapper`_ structure, or in a |
| 32 | `native object file`_. Both of these mechanisms make it easy to embed extra |
| 33 | data along with LLVM IR files. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 34 | |
| 35 | This document first describes the LLVM bitstream format, describes the wrapper |
| 36 | format, then describes the record structure used by LLVM IR files. |
| 37 | |
| 38 | .. _bitstream container format: |
| 39 | |
| 40 | Bitstream Format |
| 41 | ================ |
| 42 | |
| 43 | The bitstream format is literally a stream of bits, with a very simple |
| 44 | structure. This structure consists of the following concepts: |
| 45 | |
| 46 | * A "`magic number`_" that identifies the contents of the stream. |
| 47 | |
| 48 | * Encoding `primitives`_ like variable bit-rate integers. |
| 49 | |
| 50 | * `Blocks`_, which define nested content. |
| 51 | |
| 52 | * `Data Records`_, which describe entities within the file. |
| 53 | |
| 54 | * Abbreviations, which specify compression optimizations for the file. |
| 55 | |
Joe Abbey | 159fac4 | 2012-11-20 18:14:15 +0000 | [diff] [blame] | 56 | Note that the :doc:`llvm-bcanalyzer <CommandGuide/llvm-bcanalyzer>` tool can be |
| 57 | used to dump and inspect arbitrary bitstreams, which is very useful for |
| 58 | understanding the encoding. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 59 | |
| 60 | .. _magic number: |
| 61 | |
| 62 | Magic Numbers |
| 63 | ------------- |
| 64 | |
| 65 | The first two bytes of a bitcode file are 'BC' (``0x42``, ``0x43``). The second |
| 66 | two bytes are an application-specific magic number. Generic bitcode tools can |
| 67 | look at only the first two bytes to verify the file is bitcode, while |
| 68 | application-specific programs will want to look at all four. |
| 69 | |
| 70 | .. _primitives: |
| 71 | |
| 72 | Primitives |
| 73 | ---------- |
| 74 | |
| 75 | A bitstream literally consists of a stream of bits, which are read in order |
| 76 | starting with the least significant bit of each byte. The stream is made up of |
| 77 | a number of primitive values that encode a stream of unsigned integer values. |
| 78 | These integers are encoded in two ways: either as `Fixed Width Integers`_ or as |
| 79 | `Variable Width Integers`_. |
| 80 | |
| 81 | .. _Fixed Width Integers: |
| 82 | .. _fixed-width value: |
| 83 | |
| 84 | Fixed Width Integers |
| 85 | ^^^^^^^^^^^^^^^^^^^^ |
| 86 | |
| 87 | Fixed-width integer values have their low bits emitted directly to the file. |
| 88 | For example, a 3-bit integer value encodes 1 as 001. Fixed width integers are |
| 89 | used when there are a well-known number of options for a field. For example, |
| 90 | boolean values are usually encoded with a 1-bit wide integer. |
| 91 | |
| 92 | .. _Variable Width Integers: |
| 93 | .. _Variable Width Integer: |
| 94 | .. _variable-width value: |
| 95 | |
| 96 | Variable Width Integers |
| 97 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 98 | |
| 99 | Variable-width integer (VBR) values encode values of arbitrary size, optimizing |
| 100 | for the case where the values are small. Given a 4-bit VBR field, any 3-bit |
| 101 | value (0 through 7) is encoded directly, with the high bit set to zero. Values |
| 102 | larger than N-1 bits emit their bits in a series of N-1 bit chunks, where all |
| 103 | but the last set the high bit. |
| 104 | |
| 105 | For example, the value 27 (0x1B) is encoded as 1011 0011 when emitted as a vbr4 |
| 106 | value. The first set of four bits indicates the value 3 (011) with a |
| 107 | continuation piece (indicated by a high bit of 1). The next word indicates a |
| 108 | value of 24 (011 << 3) with no continuation. The sum (3+24) yields the value |
| 109 | 27. |
| 110 | |
| 111 | .. _char6-encoded value: |
| 112 | |
| 113 | 6-bit characters |
| 114 | ^^^^^^^^^^^^^^^^ |
| 115 | |
| 116 | 6-bit characters encode common characters into a fixed 6-bit field. They |
| 117 | represent the following characters with the following 6-bit values: |
| 118 | |
| 119 | :: |
| 120 | |
| 121 | 'a' .. 'z' --- 0 .. 25 |
| 122 | 'A' .. 'Z' --- 26 .. 51 |
| 123 | '0' .. '9' --- 52 .. 61 |
| 124 | '.' --- 62 |
| 125 | '_' --- 63 |
| 126 | |
| 127 | This encoding is only suitable for encoding characters and strings that consist |
| 128 | only of the above characters. It is completely incapable of encoding characters |
| 129 | not in the set. |
| 130 | |
| 131 | Word Alignment |
| 132 | ^^^^^^^^^^^^^^ |
| 133 | |
| 134 | Occasionally, it is useful to emit zero bits until the bitstream is a multiple |
| 135 | of 32 bits. This ensures that the bit position in the stream can be represented |
| 136 | as a multiple of 32-bit words. |
| 137 | |
| 138 | Abbreviation IDs |
| 139 | ---------------- |
| 140 | |
| 141 | A bitstream is a sequential series of `Blocks`_ and `Data Records`_. Both of |
| 142 | these start with an abbreviation ID encoded as a fixed-bitwidth field. The |
| 143 | width is specified by the current block, as described below. The value of the |
| 144 | abbreviation ID specifies either a builtin ID (which have special meanings, |
| 145 | defined below) or one of the abbreviation IDs defined for the current block by |
| 146 | the stream itself. |
| 147 | |
| 148 | The set of builtin abbrev IDs is: |
| 149 | |
| 150 | * 0 - `END_BLOCK`_ --- This abbrev ID marks the end of the current block. |
| 151 | |
| 152 | * 1 - `ENTER_SUBBLOCK`_ --- This abbrev ID marks the beginning of a new |
| 153 | block. |
| 154 | |
| 155 | * 2 - `DEFINE_ABBREV`_ --- This defines a new abbreviation. |
| 156 | |
| 157 | * 3 - `UNABBREV_RECORD`_ --- This ID specifies the definition of an |
| 158 | unabbreviated record. |
| 159 | |
| 160 | Abbreviation IDs 4 and above are defined by the stream itself, and specify an |
| 161 | `abbreviated record encoding`_. |
| 162 | |
| 163 | .. _Blocks: |
| 164 | |
| 165 | Blocks |
| 166 | ------ |
| 167 | |
| 168 | Blocks in a bitstream denote nested regions of the stream, and are identified by |
| 169 | a content-specific id number (for example, LLVM IR uses an ID of 12 to represent |
| 170 | function bodies). Block IDs 0-7 are reserved for `standard blocks`_ whose |
| 171 | meaning is defined by Bitcode; block IDs 8 and greater are application |
| 172 | specific. Nested blocks capture the hierarchical structure of the data encoded |
| 173 | in it, and various properties are associated with blocks as the file is parsed. |
| 174 | Block definitions allow the reader to efficiently skip blocks in constant time |
| 175 | if the reader wants a summary of blocks, or if it wants to efficiently skip data |
| 176 | it does not understand. The LLVM IR reader uses this mechanism to skip function |
| 177 | bodies, lazily reading them on demand. |
| 178 | |
| 179 | When reading and encoding the stream, several properties are maintained for the |
| 180 | block. In particular, each block maintains: |
| 181 | |
| 182 | #. A current abbrev id width. This value starts at 2 at the beginning of the |
| 183 | stream, and is set every time a block record is entered. The block entry |
| 184 | specifies the abbrev id width for the body of the block. |
| 185 | |
| 186 | #. A set of abbreviations. Abbreviations may be defined within a block, in |
| 187 | which case they are only defined in that block (neither subblocks nor |
| 188 | enclosing blocks see the abbreviation). Abbreviations can also be defined |
| 189 | inside a `BLOCKINFO`_ block, in which case they are defined in all blocks |
| 190 | that match the ID that the ``BLOCKINFO`` block is describing. |
| 191 | |
| 192 | As sub blocks are entered, these properties are saved and the new sub-block has |
| 193 | its own set of abbreviations, and its own abbrev id width. When a sub-block is |
| 194 | popped, the saved values are restored. |
| 195 | |
| 196 | .. _ENTER_SUBBLOCK: |
| 197 | |
| 198 | ENTER_SUBBLOCK Encoding |
| 199 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 200 | |
| 201 | :raw-html:`<tt>` |
| 202 | [ENTER_SUBBLOCK, blockid\ :sub:`vbr8`, newabbrevlen\ :sub:`vbr4`, <align32bits>, blocklen_32] |
| 203 | :raw-html:`</tt>` |
| 204 | |
| 205 | The ``ENTER_SUBBLOCK`` abbreviation ID specifies the start of a new block |
| 206 | record. The ``blockid`` value is encoded as an 8-bit VBR identifier, and |
| 207 | indicates the type of block being entered, which can be a `standard block`_ or |
| 208 | an application-specific block. The ``newabbrevlen`` value is a 4-bit VBR, which |
| 209 | specifies the abbrev id width for the sub-block. The ``blocklen`` value is a |
| 210 | 32-bit aligned value that specifies the size of the subblock in 32-bit |
| 211 | words. This value allows the reader to skip over the entire block in one jump. |
| 212 | |
| 213 | .. _END_BLOCK: |
| 214 | |
| 215 | END_BLOCK Encoding |
| 216 | ^^^^^^^^^^^^^^^^^^ |
| 217 | |
| 218 | ``[END_BLOCK, <align32bits>]`` |
| 219 | |
| 220 | The ``END_BLOCK`` abbreviation ID specifies the end of the current block record. |
| 221 | Its end is aligned to 32-bits to ensure that the size of the block is an even |
| 222 | multiple of 32-bits. |
| 223 | |
| 224 | .. _Data Records: |
| 225 | |
| 226 | Data Records |
| 227 | ------------ |
| 228 | |
| 229 | Data records consist of a record code and a number of (up to) 64-bit integer |
| 230 | values. The interpretation of the code and values is application specific and |
| 231 | may vary between different block types. Records can be encoded either using an |
| 232 | unabbrev record, or with an abbreviation. In the LLVM IR format, for example, |
| 233 | there is a record which encodes the target triple of a module. The code is |
| 234 | ``MODULE_CODE_TRIPLE``, and the values of the record are the ASCII codes for the |
| 235 | characters in the string. |
| 236 | |
| 237 | .. _UNABBREV_RECORD: |
| 238 | |
| 239 | UNABBREV_RECORD Encoding |
| 240 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 241 | |
| 242 | :raw-html:`<tt>` |
| 243 | [UNABBREV_RECORD, code\ :sub:`vbr6`, numops\ :sub:`vbr6`, op0\ :sub:`vbr6`, op1\ :sub:`vbr6`, ...] |
| 244 | :raw-html:`</tt>` |
| 245 | |
| 246 | An ``UNABBREV_RECORD`` provides a default fallback encoding, which is both |
| 247 | completely general and extremely inefficient. It can describe an arbitrary |
| 248 | record by emitting the code and operands as VBRs. |
| 249 | |
| 250 | For example, emitting an LLVM IR target triple as an unabbreviated record |
| 251 | requires emitting the ``UNABBREV_RECORD`` abbrevid, a vbr6 for the |
| 252 | ``MODULE_CODE_TRIPLE`` code, a vbr6 for the length of the string, which is equal |
| 253 | to the number of operands, and a vbr6 for each character. Because there are no |
| 254 | letters with values less than 32, each letter would need to be emitted as at |
| 255 | least a two-part VBR, which means that each letter would require at least 12 |
| 256 | bits. This is not an efficient encoding, but it is fully general. |
| 257 | |
| 258 | .. _abbreviated record encoding: |
| 259 | |
| 260 | Abbreviated Record Encoding |
| 261 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 262 | |
| 263 | ``[<abbrevid>, fields...]`` |
| 264 | |
| 265 | An abbreviated record is a abbreviation id followed by a set of fields that are |
| 266 | encoded according to the `abbreviation definition`_. This allows records to be |
| 267 | encoded significantly more densely than records encoded with the |
| 268 | `UNABBREV_RECORD`_ type, and allows the abbreviation types to be specified in |
| 269 | the stream itself, which allows the files to be completely self describing. The |
| 270 | actual encoding of abbreviations is defined below. |
| 271 | |
| 272 | The record code, which is the first field of an abbreviated record, may be |
| 273 | encoded in the abbreviation definition (as a literal operand) or supplied in the |
| 274 | abbreviated record (as a Fixed or VBR operand value). |
| 275 | |
| 276 | .. _abbreviation definition: |
| 277 | |
| 278 | Abbreviations |
| 279 | ------------- |
| 280 | |
| 281 | Abbreviations are an important form of compression for bitstreams. The idea is |
| 282 | to specify a dense encoding for a class of records once, then use that encoding |
| 283 | to emit many records. It takes space to emit the encoding into the file, but |
| 284 | the space is recouped (hopefully plus some) when the records that use it are |
| 285 | emitted. |
| 286 | |
| 287 | Abbreviations can be determined dynamically per client, per file. Because the |
| 288 | abbreviations are stored in the bitstream itself, different streams of the same |
| 289 | format can contain different sets of abbreviations according to the needs of the |
| 290 | specific stream. As a concrete example, LLVM IR files usually emit an |
| 291 | abbreviation for binary operators. If a specific LLVM module contained no or |
| 292 | few binary operators, the abbreviation does not need to be emitted. |
| 293 | |
| 294 | .. _DEFINE_ABBREV: |
| 295 | |
| 296 | DEFINE_ABBREV Encoding |
| 297 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 298 | |
| 299 | :raw-html:`<tt>` |
| 300 | [DEFINE_ABBREV, numabbrevops\ :sub:`vbr5`, abbrevop0, abbrevop1, ...] |
| 301 | :raw-html:`</tt>` |
| 302 | |
| 303 | A ``DEFINE_ABBREV`` record adds an abbreviation to the list of currently defined |
| 304 | abbreviations in the scope of this block. This definition only exists inside |
| 305 | this immediate block --- it is not visible in subblocks or enclosing blocks. |
| 306 | Abbreviations are implicitly assigned IDs sequentially starting from 4 (the |
| 307 | first application-defined abbreviation ID). Any abbreviations defined in a |
| 308 | ``BLOCKINFO`` record for the particular block type receive IDs first, in order, |
| 309 | followed by any abbreviations defined within the block itself. Abbreviated data |
| 310 | records reference this ID to indicate what abbreviation they are invoking. |
| 311 | |
| 312 | An abbreviation definition consists of the ``DEFINE_ABBREV`` abbrevid followed |
| 313 | by a VBR that specifies the number of abbrev operands, then the abbrev operands |
| 314 | themselves. Abbreviation operands come in three forms. They all start with a |
| 315 | single bit that indicates whether the abbrev operand is a literal operand (when |
| 316 | the bit is 1) or an encoding operand (when the bit is 0). |
| 317 | |
| 318 | #. Literal operands --- :raw-html:`<tt>` [1\ :sub:`1`, litvalue\ |
| 319 | :sub:`vbr8`] :raw-html:`</tt>` --- Literal operands specify that the value in |
| 320 | the result is always a single specific value. This specific value is emitted |
| 321 | as a vbr8 after the bit indicating that it is a literal operand. |
| 322 | |
| 323 | #. Encoding info without data --- :raw-html:`<tt>` [0\ :sub:`1`, encoding\ |
| 324 | :sub:`3`] :raw-html:`</tt>` --- Operand encodings that do not have extra data |
| 325 | are just emitted as their code. |
| 326 | |
| 327 | #. Encoding info with data --- :raw-html:`<tt>` [0\ :sub:`1`, encoding\ |
| 328 | :sub:`3`, value\ :sub:`vbr5`] :raw-html:`</tt>` --- Operand encodings that do |
| 329 | have extra data are emitted as their code, followed by the extra data. |
| 330 | |
| 331 | The possible operand encodings are: |
| 332 | |
| 333 | * Fixed (code 1): The field should be emitted as a `fixed-width value`_, whose |
| 334 | width is specified by the operand's extra data. |
| 335 | |
| 336 | * VBR (code 2): The field should be emitted as a `variable-width value`_, whose |
| 337 | width is specified by the operand's extra data. |
| 338 | |
| 339 | * Array (code 3): This field is an array of values. The array operand has no |
| 340 | extra data, but expects another operand to follow it, indicating the element |
| 341 | type of the array. When reading an array in an abbreviated record, the first |
| 342 | integer is a vbr6 that indicates the array length, followed by the encoded |
| 343 | elements of the array. An array may only occur as the last operand of an |
| 344 | abbreviation (except for the one final operand that gives the array's |
| 345 | type). |
| 346 | |
| 347 | * Char6 (code 4): This field should be emitted as a `char6-encoded value`_. |
| 348 | This operand type takes no extra data. Char6 encoding is normally used as an |
| 349 | array element type. |
| 350 | |
| 351 | * Blob (code 5): This field is emitted as a vbr6, followed by padding to a |
| 352 | 32-bit boundary (for alignment) and an array of 8-bit objects. The array of |
| 353 | bytes is further followed by tail padding to ensure that its total length is a |
| 354 | multiple of 4 bytes. This makes it very efficient for the reader to decode |
| 355 | the data without having to make a copy of it: it can use a pointer to the data |
| 356 | in the mapped in file and poke directly at it. A blob may only occur as the |
| 357 | last operand of an abbreviation. |
| 358 | |
| 359 | For example, target triples in LLVM modules are encoded as a record of the form |
| 360 | ``[TRIPLE, 'a', 'b', 'c', 'd']``. Consider if the bitstream emitted the |
| 361 | following abbrev entry: |
| 362 | |
| 363 | :: |
| 364 | |
| 365 | [0, Fixed, 4] |
| 366 | [0, Array] |
| 367 | [0, Char6] |
| 368 | |
| 369 | When emitting a record with this abbreviation, the above entry would be emitted |
| 370 | as: |
| 371 | |
| 372 | :raw-html:`<tt><blockquote>` |
| 373 | [4\ :sub:`abbrevwidth`, 2\ :sub:`4`, 4\ :sub:`vbr6`, 0\ :sub:`6`, 1\ :sub:`6`, 2\ :sub:`6`, 3\ :sub:`6`] |
| 374 | :raw-html:`</blockquote></tt>` |
| 375 | |
| 376 | These values are: |
| 377 | |
| 378 | #. The first value, 4, is the abbreviation ID for this abbreviation. |
| 379 | |
| 380 | #. The second value, 2, is the record code for ``TRIPLE`` records within LLVM IR |
| 381 | file ``MODULE_BLOCK`` blocks. |
| 382 | |
| 383 | #. The third value, 4, is the length of the array. |
| 384 | |
| 385 | #. The rest of the values are the char6 encoded values for ``"abcd"``. |
| 386 | |
| 387 | With this abbreviation, the triple is emitted with only 37 bits (assuming a |
| 388 | abbrev id width of 3). Without the abbreviation, significantly more space would |
| 389 | be required to emit the target triple. Also, because the ``TRIPLE`` value is |
| 390 | not emitted as a literal in the abbreviation, the abbreviation can also be used |
| 391 | for any other string value. |
| 392 | |
| 393 | .. _standard blocks: |
| 394 | .. _standard block: |
| 395 | |
| 396 | Standard Blocks |
| 397 | --------------- |
| 398 | |
| 399 | In addition to the basic block structure and record encodings, the bitstream |
| 400 | also defines specific built-in block types. These block types specify how the |
| 401 | stream is to be decoded or other metadata. In the future, new standard blocks |
| 402 | may be added. Block IDs 0-7 are reserved for standard blocks. |
| 403 | |
| 404 | .. _BLOCKINFO: |
| 405 | |
| 406 | #0 - BLOCKINFO Block |
| 407 | ^^^^^^^^^^^^^^^^^^^^ |
| 408 | |
| 409 | The ``BLOCKINFO`` block allows the description of metadata for other blocks. |
| 410 | The currently specified records are: |
| 411 | |
| 412 | :: |
| 413 | |
| 414 | [SETBID (#1), blockid] |
| 415 | [DEFINE_ABBREV, ...] |
| 416 | [BLOCKNAME, ...name...] |
| 417 | [SETRECORDNAME, RecordID, ...name...] |
| 418 | |
| 419 | The ``SETBID`` record (code 1) indicates which block ID is being described. |
| 420 | ``SETBID`` records can occur multiple times throughout the block to change which |
| 421 | block ID is being described. There must be a ``SETBID`` record prior to any |
| 422 | other records. |
| 423 | |
| 424 | Standard ``DEFINE_ABBREV`` records can occur inside ``BLOCKINFO`` blocks, but |
| 425 | unlike their occurrence in normal blocks, the abbreviation is defined for blocks |
| 426 | matching the block ID we are describing, *not* the ``BLOCKINFO`` block |
| 427 | itself. The abbreviations defined in ``BLOCKINFO`` blocks receive abbreviation |
| 428 | IDs as described in `DEFINE_ABBREV`_. |
| 429 | |
| 430 | The ``BLOCKNAME`` record (code 2) can optionally occur in this block. The |
| 431 | elements of the record are the bytes of the string name of the block. |
| 432 | llvm-bcanalyzer can use this to dump out bitcode files symbolically. |
| 433 | |
| 434 | The ``SETRECORDNAME`` record (code 3) can also optionally occur in this block. |
| 435 | The first operand value is a record ID number, and the rest of the elements of |
| 436 | the record are the bytes for the string name of the record. llvm-bcanalyzer can |
| 437 | use this to dump out bitcode files symbolically. |
| 438 | |
| 439 | Note that although the data in ``BLOCKINFO`` blocks is described as "metadata," |
| 440 | the abbreviations they contain are essential for parsing records from the |
| 441 | corresponding blocks. It is not safe to skip them. |
| 442 | |
| 443 | .. _wrapper: |
| 444 | |
| 445 | Bitcode Wrapper Format |
| 446 | ====================== |
| 447 | |
| 448 | Bitcode files for LLVM IR may optionally be wrapped in a simple wrapper |
| 449 | structure. This structure contains a simple header that indicates the offset |
| 450 | and size of the embedded BC file. This allows additional information to be |
| 451 | stored alongside the BC file. The structure of this file header is: |
| 452 | |
| 453 | :raw-html:`<tt><blockquote>` |
| 454 | [Magic\ :sub:`32`, Version\ :sub:`32`, Offset\ :sub:`32`, Size\ :sub:`32`, CPUType\ :sub:`32`] |
| 455 | :raw-html:`</blockquote></tt>` |
| 456 | |
| 457 | Each of the fields are 32-bit fields stored in little endian form (as with the |
| 458 | rest of the bitcode file fields). The Magic number is always ``0x0B17C0DE`` and |
| 459 | the version is currently always ``0``. The Offset field is the offset in bytes |
| 460 | to the start of the bitcode stream in the file, and the Size field is the size |
| 461 | in bytes of the stream. CPUType is a target-specific value that can be used to |
| 462 | encode the CPU of the target. |
| 463 | |
Peter Collingbourne | 10039c0 | 2014-09-18 21:28:49 +0000 | [diff] [blame] | 464 | .. _native object file: |
| 465 | |
| 466 | Native Object File Wrapper Format |
| 467 | ================================= |
| 468 | |
| 469 | Bitcode files for LLVM IR may also be wrapped in a native object file |
Steven Wu | f2fe014 | 2016-02-29 19:40:10 +0000 | [diff] [blame] | 470 | (i.e. ELF, COFF, Mach-O). The bitcode must be stored in a section of the object |
| 471 | file named ``__LLVM,__bitcode`` for MachO and ``.llvmbc`` for the other object |
| 472 | formats. This wrapper format is useful for accommodating LTO in compilation |
| 473 | pipelines where intermediate objects must be native object files which contain |
| 474 | metadata in other sections. |
Peter Collingbourne | 10039c0 | 2014-09-18 21:28:49 +0000 | [diff] [blame] | 475 | |
| 476 | Not all tools support this format. |
| 477 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 478 | .. _encoding of LLVM IR: |
| 479 | |
| 480 | LLVM IR Encoding |
| 481 | ================ |
| 482 | |
| 483 | LLVM IR is encoded into a bitstream by defining blocks and records. It uses |
| 484 | blocks for things like constant pools, functions, symbol tables, etc. It uses |
| 485 | records for things like instructions, global variable descriptors, type |
| 486 | descriptions, etc. This document does not describe the set of abbreviations |
| 487 | that the writer uses, as these are fully self-described in the file, and the |
| 488 | reader is not allowed to build in any knowledge of this. |
| 489 | |
| 490 | Basics |
| 491 | ------ |
| 492 | |
| 493 | LLVM IR Magic Number |
| 494 | ^^^^^^^^^^^^^^^^^^^^ |
| 495 | |
| 496 | The magic number for LLVM IR files is: |
| 497 | |
| 498 | :raw-html:`<tt><blockquote>` |
| 499 | [0x0\ :sub:`4`, 0xC\ :sub:`4`, 0xE\ :sub:`4`, 0xD\ :sub:`4`] |
| 500 | :raw-html:`</blockquote></tt>` |
| 501 | |
| 502 | When combined with the bitcode magic number and viewed as bytes, this is |
| 503 | ``"BC 0xC0DE"``. |
| 504 | |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 505 | .. _Signed VBRs: |
| 506 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 507 | Signed VBRs |
| 508 | ^^^^^^^^^^^ |
| 509 | |
| 510 | `Variable Width Integer`_ encoding is an efficient way to encode arbitrary sized |
| 511 | unsigned values, but is an extremely inefficient for encoding signed values, as |
| 512 | signed values are otherwise treated as maximally large unsigned values. |
| 513 | |
| 514 | As such, signed VBR values of a specific width are emitted as follows: |
| 515 | |
| 516 | * Positive values are emitted as VBRs of the specified width, but with their |
| 517 | value shifted left by one. |
| 518 | |
| 519 | * Negative values are emitted as VBRs of the specified width, but the negated |
| 520 | value is shifted left by one, and the low bit is set. |
| 521 | |
| 522 | With this encoding, small positive and small negative values can both be emitted |
| 523 | efficiently. Signed VBR encoding is used in ``CST_CODE_INTEGER`` and |
| 524 | ``CST_CODE_WIDE_INTEGER`` records within ``CONSTANTS_BLOCK`` blocks. |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 525 | It is also used for phi instruction operands in `MODULE_CODE_VERSION`_ 1. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 526 | |
| 527 | LLVM IR Blocks |
| 528 | ^^^^^^^^^^^^^^ |
| 529 | |
| 530 | LLVM IR is defined with the following blocks: |
| 531 | |
| 532 | * 8 --- `MODULE_BLOCK`_ --- This is the top-level block that contains the entire |
| 533 | module, and describes a variety of per-module information. |
| 534 | |
| 535 | * 9 --- `PARAMATTR_BLOCK`_ --- This enumerates the parameter attributes. |
| 536 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 537 | * 10 --- `PARAMATTR_GROUP_BLOCK`_ --- This describes the attribute group table. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 538 | |
| 539 | * 11 --- `CONSTANTS_BLOCK`_ --- This describes constants for a module or |
| 540 | function. |
| 541 | |
| 542 | * 12 --- `FUNCTION_BLOCK`_ --- This describes a function body. |
| 543 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 544 | * 14 --- `VALUE_SYMTAB_BLOCK`_ --- This describes a value symbol table. |
| 545 | |
| 546 | * 15 --- `METADATA_BLOCK`_ --- This describes metadata items. |
| 547 | |
| 548 | * 16 --- `METADATA_ATTACHMENT`_ --- This contains records associating metadata |
| 549 | with function instruction values. |
| 550 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 551 | * 17 --- `TYPE_BLOCK`_ --- This describes all of the types in the module. |
| 552 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 553 | * 23 --- `STRTAB_BLOCK`_ --- The bitcode file's string table. |
| 554 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 555 | .. _MODULE_BLOCK: |
| 556 | |
| 557 | MODULE_BLOCK Contents |
| 558 | --------------------- |
| 559 | |
| 560 | The ``MODULE_BLOCK`` block (id 8) is the top-level block for LLVM bitcode files, |
| 561 | and each bitcode file must contain exactly one. In addition to records |
| 562 | (described below) containing information about the module, a ``MODULE_BLOCK`` |
| 563 | block may contain the following sub-blocks: |
| 564 | |
| 565 | * `BLOCKINFO`_ |
| 566 | * `PARAMATTR_BLOCK`_ |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 567 | * `PARAMATTR_GROUP_BLOCK`_ |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 568 | * `TYPE_BLOCK`_ |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 569 | * `VALUE_SYMTAB_BLOCK`_ |
| 570 | * `CONSTANTS_BLOCK`_ |
| 571 | * `FUNCTION_BLOCK`_ |
| 572 | * `METADATA_BLOCK`_ |
| 573 | |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 574 | .. _MODULE_CODE_VERSION: |
| 575 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 576 | MODULE_CODE_VERSION Record |
| 577 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 578 | |
| 579 | ``[VERSION, version#]`` |
| 580 | |
| 581 | The ``VERSION`` record (code 1) contains a single value indicating the format |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 582 | version. Versions 0, 1 and 2 are supported at this time. The difference between |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 583 | version 0 and 1 is in the encoding of instruction operands in |
| 584 | each `FUNCTION_BLOCK`_. |
| 585 | |
| 586 | In version 0, each value defined by an instruction is assigned an ID |
| 587 | unique to the function. Function-level value IDs are assigned starting from |
| 588 | ``NumModuleValues`` since they share the same namespace as module-level |
| 589 | values. The value enumerator resets after each function. When a value is |
| 590 | an operand of an instruction, the value ID is used to represent the operand. |
| 591 | For large functions or large modules, these operand values can be large. |
| 592 | |
| 593 | The encoding in version 1 attempts to avoid large operand values |
| 594 | in common cases. Instead of using the value ID directly, operands are |
| 595 | encoded as relative to the current instruction. Thus, if an operand |
| 596 | is the value defined by the previous instruction, the operand |
| 597 | will be encoded as 1. |
| 598 | |
| 599 | For example, instead of |
| 600 | |
Aaron Ballman | a0c1f40 | 2016-07-19 20:20:03 +0000 | [diff] [blame] | 601 | .. code-block:: none |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 602 | |
| 603 | #n = load #n-1 |
| 604 | #n+1 = icmp eq #n, #const0 |
| 605 | br #n+1, label #(bb1), label #(bb2) |
| 606 | |
| 607 | version 1 will encode the instructions as |
| 608 | |
Aaron Ballman | a0c1f40 | 2016-07-19 20:20:03 +0000 | [diff] [blame] | 609 | .. code-block:: none |
Jan Wen Voung | 77c6c85 | 2012-10-12 18:13:17 +0000 | [diff] [blame] | 610 | |
| 611 | #n = load #1 |
| 612 | #n+1 = icmp eq #1, (#n+1)-#const0 |
| 613 | br #1, label #(bb1), label #(bb2) |
| 614 | |
| 615 | Note in the example that operands which are constants also use |
| 616 | the relative encoding, while operands like basic block labels |
| 617 | do not use the relative encoding. |
| 618 | |
| 619 | Forward references will result in a negative value. |
| 620 | This can be inefficient, as operands are normally encoded |
| 621 | as unsigned VBRs. However, forward references are rare, except in the |
| 622 | case of phi instructions. For phi instructions, operands are encoded as |
| 623 | `Signed VBRs`_ to deal with forward references. |
| 624 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 625 | In version 2, the meaning of module records ``FUNCTION``, ``GLOBALVAR``, |
| 626 | ``ALIAS``, ``IFUNC`` and ``COMDAT`` change such that the first two operands |
| 627 | specify an offset and size of a string in a string table (see `STRTAB_BLOCK |
| 628 | Contents`_), the function name is removed from the ``FNENTRY`` record in the |
| 629 | value symbol table, and the top-level ``VALUE_SYMTAB_BLOCK`` may only contain |
| 630 | ``FNENTRY`` records. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 631 | |
| 632 | MODULE_CODE_TRIPLE Record |
| 633 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 634 | |
| 635 | ``[TRIPLE, ...string...]`` |
| 636 | |
| 637 | The ``TRIPLE`` record (code 2) contains a variable number of values representing |
| 638 | the bytes of the ``target triple`` specification string. |
| 639 | |
| 640 | MODULE_CODE_DATALAYOUT Record |
| 641 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 642 | |
| 643 | ``[DATALAYOUT, ...string...]`` |
| 644 | |
| 645 | The ``DATALAYOUT`` record (code 3) contains a variable number of values |
| 646 | representing the bytes of the ``target datalayout`` specification string. |
| 647 | |
| 648 | MODULE_CODE_ASM Record |
| 649 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 650 | |
| 651 | ``[ASM, ...string...]`` |
| 652 | |
| 653 | The ``ASM`` record (code 4) contains a variable number of values representing |
| 654 | the bytes of ``module asm`` strings, with individual assembly blocks separated |
| 655 | by newline (ASCII 10) characters. |
| 656 | |
| 657 | .. _MODULE_CODE_SECTIONNAME: |
| 658 | |
| 659 | MODULE_CODE_SECTIONNAME Record |
| 660 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 661 | |
| 662 | ``[SECTIONNAME, ...string...]`` |
| 663 | |
| 664 | The ``SECTIONNAME`` record (code 5) contains a variable number of values |
| 665 | representing the bytes of a single section name string. There should be one |
| 666 | ``SECTIONNAME`` record for each section name referenced (e.g., in global |
| 667 | variable or function ``section`` attributes) within the module. These records |
| 668 | can be referenced by the 1-based index in the *section* fields of ``GLOBALVAR`` |
| 669 | or ``FUNCTION`` records. |
| 670 | |
| 671 | MODULE_CODE_DEPLIB Record |
| 672 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 673 | |
| 674 | ``[DEPLIB, ...string...]`` |
| 675 | |
| 676 | The ``DEPLIB`` record (code 6) contains a variable number of values representing |
| 677 | the bytes of a single dependent library name string, one of the libraries |
| 678 | mentioned in a ``deplibs`` declaration. There should be one ``DEPLIB`` record |
| 679 | for each library name referenced. |
| 680 | |
| 681 | MODULE_CODE_GLOBALVAR Record |
| 682 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 683 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 684 | ``[GLOBALVAR, strtab offset, strtab size, pointer type, isconst, initid, linkage, alignment, section, visibility, threadlocal, unnamed_addr, externally_initialized, dllstorageclass, comdat]`` |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 685 | |
| 686 | The ``GLOBALVAR`` record (code 7) marks the declaration or definition of a |
| 687 | global variable. The operand fields are: |
| 688 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 689 | * *strtab offset*, *strtab size*: Specifies the name of the global variable. |
| 690 | See `STRTAB_BLOCK Contents`_. |
| 691 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 692 | * *pointer type*: The type index of the pointer type used to point to this |
| 693 | global variable |
| 694 | |
| 695 | * *isconst*: Non-zero if the variable is treated as constant within the module, |
| 696 | or zero if it is not |
| 697 | |
| 698 | * *initid*: If non-zero, the value index of the initializer for this variable, |
| 699 | plus 1. |
| 700 | |
| 701 | .. _linkage type: |
| 702 | |
| 703 | * *linkage*: An encoding of the linkage type for this variable: |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 704 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 705 | * ``external``: code 0 |
| 706 | * ``weak``: code 1 |
| 707 | * ``appending``: code 2 |
| 708 | * ``internal``: code 3 |
| 709 | * ``linkonce``: code 4 |
| 710 | * ``dllimport``: code 5 |
| 711 | * ``dllexport``: code 6 |
| 712 | * ``extern_weak``: code 7 |
| 713 | * ``common``: code 8 |
| 714 | * ``private``: code 9 |
| 715 | * ``weak_odr``: code 10 |
| 716 | * ``linkonce_odr``: code 11 |
| 717 | * ``available_externally``: code 12 |
Rafael Espindola | 2fb5bc3 | 2014-03-13 23:18:37 +0000 | [diff] [blame] | 718 | * deprecated : code 13 |
| 719 | * deprecated : code 14 |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 720 | |
| 721 | * alignment*: The logarithm base 2 of the variable's requested alignment, plus 1 |
| 722 | |
| 723 | * *section*: If non-zero, the 1-based section index in the table of |
| 724 | `MODULE_CODE_SECTIONNAME`_ entries. |
| 725 | |
| 726 | .. _visibility: |
| 727 | |
| 728 | * *visibility*: If present, an encoding of the visibility of this variable: |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 729 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 730 | * ``default``: code 0 |
| 731 | * ``hidden``: code 1 |
| 732 | * ``protected``: code 2 |
| 733 | |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 734 | .. _bcthreadlocal: |
| 735 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 736 | * *threadlocal*: If present, an encoding of the thread local storage mode of the |
| 737 | variable: |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 738 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 739 | * ``not thread local``: code 0 |
| 740 | * ``thread local; default TLS model``: code 1 |
| 741 | * ``localdynamic``: code 2 |
| 742 | * ``initialexec``: code 3 |
| 743 | * ``localexec``: code 4 |
| 744 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 745 | .. _bcunnamedaddr: |
| 746 | |
| 747 | * *unnamed_addr*: If present, an encoding of the ``unnamed_addr`` attribute of this |
| 748 | variable: |
| 749 | |
| 750 | * not ``unnamed_addr``: code 0 |
| 751 | * ``unnamed_addr``: code 1 |
| 752 | * ``local_unnamed_addr``: code 2 |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 753 | |
Peter Collingbourne | 042b7ff | 2014-09-18 21:54:02 +0000 | [diff] [blame] | 754 | .. _bcdllstorageclass: |
Nico Rieck | 7157bb7 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 755 | |
| 756 | * *dllstorageclass*: If present, an encoding of the DLL storage class of this variable: |
| 757 | |
| 758 | * ``default``: code 0 |
| 759 | * ``dllimport``: code 1 |
| 760 | * ``dllexport``: code 2 |
| 761 | |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 762 | * *comdat*: An encoding of the COMDAT of this function |
| 763 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 764 | .. _FUNCTION: |
| 765 | |
| 766 | MODULE_CODE_FUNCTION Record |
| 767 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 768 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 769 | ``[FUNCTION, strtab offset, strtab size, type, callingconv, isproto, linkage, paramattr, alignment, section, visibility, gc, prologuedata, dllstorageclass, comdat, prefixdata, personalityfn]`` |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 770 | |
| 771 | The ``FUNCTION`` record (code 8) marks the declaration or definition of a |
| 772 | function. The operand fields are: |
| 773 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 774 | * *strtab offset*, *strtab size*: Specifies the name of the function. |
| 775 | See `STRTAB_BLOCK Contents`_. |
| 776 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 777 | * *type*: The type index of the function type describing this function |
| 778 | |
| 779 | * *callingconv*: The calling convention number: |
| 780 | * ``ccc``: code 0 |
| 781 | * ``fastcc``: code 8 |
| 782 | * ``coldcc``: code 9 |
Juergen Ributzka | 976d94b | 2014-01-11 01:00:27 +0000 | [diff] [blame] | 783 | * ``webkit_jscc``: code 12 |
| 784 | * ``anyregcc``: code 13 |
Juergen Ributzka | e625013 | 2014-01-17 19:47:03 +0000 | [diff] [blame] | 785 | * ``preserve_mostcc``: code 14 |
| 786 | * ``preserve_allcc``: code 15 |
Manman Ren | f8bdd88 | 2016-04-05 22:41:47 +0000 | [diff] [blame] | 787 | * ``swiftcc`` : code 16 |
Manman Ren | 19c7bbe | 2015-12-04 17:40:13 +0000 | [diff] [blame] | 788 | * ``cxx_fast_tlscc``: code 17 |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 789 | * ``x86_stdcallcc``: code 64 |
| 790 | * ``x86_fastcallcc``: code 65 |
| 791 | * ``arm_apcscc``: code 66 |
| 792 | * ``arm_aapcscc``: code 67 |
| 793 | * ``arm_aapcs_vfpcc``: code 68 |
| 794 | |
| 795 | * isproto*: Non-zero if this entry represents a declaration rather than a |
| 796 | definition |
| 797 | |
| 798 | * *linkage*: An encoding of the `linkage type`_ for this function |
| 799 | |
| 800 | * *paramattr*: If nonzero, the 1-based parameter attribute index into the table |
| 801 | of `PARAMATTR_CODE_ENTRY`_ entries. |
| 802 | |
| 803 | * *alignment*: The logarithm base 2 of the function's requested alignment, plus |
| 804 | 1 |
| 805 | |
| 806 | * *section*: If non-zero, the 1-based section index in the table of |
| 807 | `MODULE_CODE_SECTIONNAME`_ entries. |
| 808 | |
| 809 | * *visibility*: An encoding of the `visibility`_ of this function |
| 810 | |
| 811 | * *gc*: If present and nonzero, the 1-based garbage collector index in the table |
| 812 | of `MODULE_CODE_GCNAME`_ entries. |
| 813 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 814 | * *unnamed_addr*: If present, an encoding of the |
| 815 | :ref:`unnamed_addr<bcunnamedaddr>` attribute of this function |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 816 | |
Peter Collingbourne | 51d2de7 | 2014-12-03 02:08:38 +0000 | [diff] [blame] | 817 | * *prologuedata*: If non-zero, the value index of the prologue data for this function, |
Peter Collingbourne | 3fa50f9 | 2013-09-16 01:08:15 +0000 | [diff] [blame] | 818 | plus 1. |
| 819 | |
Peter Collingbourne | 042b7ff | 2014-09-18 21:54:02 +0000 | [diff] [blame] | 820 | * *dllstorageclass*: An encoding of the |
| 821 | :ref:`dllstorageclass<bcdllstorageclass>` of this function |
Nico Rieck | 7157bb7 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 822 | |
Peter Collingbourne | 51d2de7 | 2014-12-03 02:08:38 +0000 | [diff] [blame] | 823 | * *comdat*: An encoding of the COMDAT of this function |
| 824 | |
| 825 | * *prefixdata*: If non-zero, the value index of the prefix data for this function, |
| 826 | plus 1. |
| 827 | |
David Majnemer | 7fddecc | 2015-06-17 20:52:32 +0000 | [diff] [blame] | 828 | * *personalityfn*: If non-zero, the value index of the personality function for this function, |
| 829 | plus 1. |
Peter Collingbourne | 51d2de7 | 2014-12-03 02:08:38 +0000 | [diff] [blame] | 830 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 831 | MODULE_CODE_ALIAS Record |
| 832 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 833 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 834 | ``[ALIAS, strtab offset, strtab size, alias type, aliasee val#, linkage, visibility, dllstorageclass, threadlocal, unnamed_addr]`` |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 835 | |
| 836 | The ``ALIAS`` record (code 9) marks the definition of an alias. The operand |
| 837 | fields are |
| 838 | |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 839 | * *strtab offset*, *strtab size*: Specifies the name of the alias. |
| 840 | See `STRTAB_BLOCK Contents`_. |
| 841 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 842 | * *alias type*: The type index of the alias |
| 843 | |
| 844 | * *aliasee val#*: The value index of the aliased value |
| 845 | |
| 846 | * *linkage*: An encoding of the `linkage type`_ for this alias |
| 847 | |
| 848 | * *visibility*: If present, an encoding of the `visibility`_ of the alias |
| 849 | |
Peter Collingbourne | 042b7ff | 2014-09-18 21:54:02 +0000 | [diff] [blame] | 850 | * *dllstorageclass*: If present, an encoding of the |
| 851 | :ref:`dllstorageclass<bcdllstorageclass>` of the alias |
Nico Rieck | 7157bb7 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 852 | |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 853 | * *threadlocal*: If present, an encoding of the |
| 854 | :ref:`thread local property<bcthreadlocal>` of the alias |
| 855 | |
Peter Collingbourne | 96efdd6 | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 856 | * *unnamed_addr*: If present, an encoding of the |
| 857 | :ref:`unnamed_addr<bcunnamedaddr>` attribute of this alias |
Peter Collingbourne | 62b5b73 | 2016-05-17 22:30:58 +0000 | [diff] [blame] | 858 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 859 | .. _MODULE_CODE_GCNAME: |
| 860 | |
| 861 | MODULE_CODE_GCNAME Record |
| 862 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 863 | |
| 864 | ``[GCNAME, ...string...]`` |
| 865 | |
| 866 | The ``GCNAME`` record (code 11) contains a variable number of values |
| 867 | representing the bytes of a single garbage collector name string. There should |
| 868 | be one ``GCNAME`` record for each garbage collector name referenced in function |
| 869 | ``gc`` attributes within the module. These records can be referenced by 1-based |
| 870 | index in the *gc* fields of ``FUNCTION`` records. |
| 871 | |
| 872 | .. _PARAMATTR_BLOCK: |
| 873 | |
| 874 | PARAMATTR_BLOCK Contents |
| 875 | ------------------------ |
| 876 | |
| 877 | The ``PARAMATTR_BLOCK`` block (id 9) contains a table of entries describing the |
| 878 | attributes of function parameters. These entries are referenced by 1-based index |
| 879 | in the *paramattr* field of module block `FUNCTION`_ records, or within the |
| 880 | *attr* field of function block ``INST_INVOKE`` and ``INST_CALL`` records. |
| 881 | |
| 882 | Entries within ``PARAMATTR_BLOCK`` are constructed to ensure that each is unique |
Bruce Mitchener | e9ffb45 | 2015-09-12 01:17:08 +0000 | [diff] [blame] | 883 | (i.e., no two indices represent equivalent attribute lists). |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 884 | |
| 885 | .. _PARAMATTR_CODE_ENTRY: |
| 886 | |
| 887 | PARAMATTR_CODE_ENTRY Record |
| 888 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 889 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 890 | ``[ENTRY, attrgrp0, attrgrp1, ...]`` |
| 891 | |
| 892 | The ``ENTRY`` record (code 2) contains a variable number of values describing a |
| 893 | unique set of function parameter attributes. Each *attrgrp* value is used as a |
| 894 | key with which to look up an entry in the the attribute group table described |
| 895 | in the ``PARAMATTR_GROUP_BLOCK`` block. |
| 896 | |
| 897 | .. _PARAMATTR_CODE_ENTRY_OLD: |
| 898 | |
| 899 | PARAMATTR_CODE_ENTRY_OLD Record |
| 900 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 901 | |
| 902 | .. note:: |
| 903 | This is a legacy encoding for attributes, produced by LLVM versions 3.2 and |
| 904 | earlier. It is guaranteed to be understood by the current LLVM version, as |
| 905 | specified in the :ref:`IR backwards compatibility` policy. |
| 906 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 907 | ``[ENTRY, paramidx0, attr0, paramidx1, attr1...]`` |
| 908 | |
| 909 | The ``ENTRY`` record (code 1) contains an even number of values describing a |
| 910 | unique set of function parameter attributes. Each *paramidx* value indicates |
| 911 | which set of attributes is represented, with 0 representing the return value |
| 912 | attributes, 0xFFFFFFFF representing function attributes, and other values |
| 913 | representing 1-based function parameters. Each *attr* value is a bitmap with the |
| 914 | following interpretation: |
| 915 | |
| 916 | * bit 0: ``zeroext`` |
| 917 | * bit 1: ``signext`` |
| 918 | * bit 2: ``noreturn`` |
| 919 | * bit 3: ``inreg`` |
| 920 | * bit 4: ``sret`` |
| 921 | * bit 5: ``nounwind`` |
| 922 | * bit 6: ``noalias`` |
| 923 | * bit 7: ``byval`` |
| 924 | * bit 8: ``nest`` |
| 925 | * bit 9: ``readnone`` |
| 926 | * bit 10: ``readonly`` |
| 927 | * bit 11: ``noinline`` |
| 928 | * bit 12: ``alwaysinline`` |
| 929 | * bit 13: ``optsize`` |
| 930 | * bit 14: ``ssp`` |
| 931 | * bit 15: ``sspreq`` |
| 932 | * bits 16-31: ``align n`` |
| 933 | * bit 32: ``nocapture`` |
| 934 | * bit 33: ``noredzone`` |
| 935 | * bit 34: ``noimplicitfloat`` |
| 936 | * bit 35: ``naked`` |
| 937 | * bit 36: ``inlinehint`` |
| 938 | * bits 37-39: ``alignstack n``, represented as the logarithm |
| 939 | base 2 of the requested alignment, plus 1 |
| 940 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 941 | .. _PARAMATTR_GROUP_BLOCK: |
| 942 | |
| 943 | PARAMATTR_GROUP_BLOCK Contents |
| 944 | ------------------------------ |
| 945 | |
| 946 | The ``PARAMATTR_GROUP_BLOCK`` block (id 10) contains a table of entries |
| 947 | describing the attribute groups present in the module. These entries can be |
| 948 | referenced within ``PARAMATTR_CODE_ENTRY`` entries. |
| 949 | |
| 950 | .. _PARAMATTR_GRP_CODE_ENTRY: |
| 951 | |
| 952 | PARAMATTR_GRP_CODE_ENTRY Record |
| 953 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 954 | |
| 955 | ``[ENTRY, grpid, paramidx, attr0, attr1, ...]`` |
| 956 | |
| 957 | The ``ENTRY`` record (code 3) contains *grpid* and *paramidx* values, followed |
| 958 | by a variable number of values describing a unique group of attributes. The |
| 959 | *grpid* value is a unique key for the attribute group, which can be referenced |
| 960 | within ``PARAMATTR_CODE_ENTRY`` entries. The *paramidx* value indicates which |
| 961 | set of attributes is represented, with 0 representing the return value |
| 962 | attributes, 0xFFFFFFFF representing function attributes, and other values |
| 963 | representing 1-based function parameters. |
| 964 | |
| 965 | Each *attr* is itself represented as a variable number of values: |
| 966 | |
| 967 | ``kind, key [, ...], [value [, ...]]`` |
| 968 | |
| 969 | Each attribute is either a well-known LLVM attribute (possibly with an integer |
| 970 | value associated with it), or an arbitrary string (possibly with an arbitrary |
| 971 | string value associated with it). The *kind* value is an integer code |
| 972 | distinguishing between these possibilities: |
| 973 | |
| 974 | * code 0: well-known attribute |
| 975 | * code 1: well-known attribute with an integer value |
| 976 | * code 3: string attribute |
| 977 | * code 4: string attribute with a string value |
| 978 | |
| 979 | For well-known attributes (code 0 or 1), the *key* value is an integer code |
| 980 | identifying the attribute. For attributes with an integer argument (code 1), |
| 981 | the *value* value indicates the argument. |
| 982 | |
| 983 | For string attributes (code 3 or 4), the *key* value is actually a variable |
| 984 | number of values representing the bytes of a null-terminated string. For |
| 985 | attributes with a string argument (code 4), the *value* value is similarly a |
| 986 | variable number of values representing the bytes of a null-terminated string. |
| 987 | |
| 988 | The integer codes are mapped to well-known attributes as follows. |
| 989 | |
| 990 | * code 1: ``align(<n>)`` |
| 991 | * code 2: ``alwaysinline`` |
| 992 | * code 3: ``byval`` |
| 993 | * code 4: ``inlinehint`` |
| 994 | * code 5: ``inreg`` |
| 995 | * code 6: ``minsize`` |
| 996 | * code 7: ``naked`` |
| 997 | * code 8: ``nest`` |
| 998 | * code 9: ``noalias`` |
| 999 | * code 10: ``nobuiltin`` |
| 1000 | * code 11: ``nocapture`` |
| 1001 | * code 12: ``noduplicates`` |
| 1002 | * code 13: ``noimplicitfloat`` |
| 1003 | * code 14: ``noinline`` |
| 1004 | * code 15: ``nonlazybind`` |
| 1005 | * code 16: ``noredzone`` |
| 1006 | * code 17: ``noreturn`` |
| 1007 | * code 18: ``nounwind`` |
| 1008 | * code 19: ``optsize`` |
| 1009 | * code 20: ``readnone`` |
| 1010 | * code 21: ``readonly`` |
| 1011 | * code 22: ``returned`` |
| 1012 | * code 23: ``returns_twice`` |
| 1013 | * code 24: ``signext`` |
| 1014 | * code 25: ``alignstack(<n>)`` |
| 1015 | * code 26: ``ssp`` |
| 1016 | * code 27: ``sspreq`` |
| 1017 | * code 28: ``sspstrong`` |
| 1018 | * code 29: ``sret`` |
| 1019 | * code 30: ``sanitize_address`` |
| 1020 | * code 31: ``sanitize_thread`` |
| 1021 | * code 32: ``sanitize_memory`` |
| 1022 | * code 33: ``uwtable`` |
| 1023 | * code 34: ``zeroext`` |
| 1024 | * code 35: ``builtin`` |
| 1025 | * code 36: ``cold`` |
| 1026 | * code 37: ``optnone`` |
| 1027 | * code 38: ``inalloca`` |
| 1028 | * code 39: ``nonnull`` |
| 1029 | * code 40: ``jumptable`` |
| 1030 | * code 41: ``dereferenceable(<n>)`` |
| 1031 | * code 42: ``dereferenceable_or_null(<n>)`` |
| 1032 | * code 43: ``convergent`` |
| 1033 | * code 44: ``safestack`` |
| 1034 | * code 45: ``argmemonly`` |
| 1035 | * code 46: ``swiftself`` |
| 1036 | * code 47: ``swifterror`` |
| 1037 | * code 48: ``norecurse`` |
| 1038 | * code 49: ``inaccessiblememonly`` |
| 1039 | * code 50: ``inaccessiblememonly_or_argmemonly`` |
| 1040 | * code 51: ``allocsize(<EltSizeParam>[, <NumEltsParam>])`` |
| 1041 | * code 52: ``writeonly`` |
| 1042 | |
| 1043 | .. note:: |
| 1044 | The ``allocsize`` attribute has a special encoding for its arguments. Its two |
| 1045 | arguments, which are 32-bit integers, are packed into one 64-bit integer value |
| 1046 | (i.e. ``(EltSizeParam << 32) | NumEltsParam``), with ``NumEltsParam`` taking on |
| 1047 | the sentinel value -1 if it is not specified. |
| 1048 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1049 | .. _TYPE_BLOCK: |
| 1050 | |
| 1051 | TYPE_BLOCK Contents |
| 1052 | ------------------- |
| 1053 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1054 | The ``TYPE_BLOCK`` block (id 17) contains records which constitute a table of |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1055 | type operator entries used to represent types referenced within an LLVM |
| 1056 | module. Each record (with the exception of `NUMENTRY`_) generates a single type |
| 1057 | table entry, which may be referenced by 0-based index from instructions, |
| 1058 | constants, metadata, type symbol table entries, or other type operator records. |
| 1059 | |
| 1060 | Entries within ``TYPE_BLOCK`` are constructed to ensure that each entry is |
Bruce Mitchener | e9ffb45 | 2015-09-12 01:17:08 +0000 | [diff] [blame] | 1061 | unique (i.e., no two indices represent structurally equivalent types). |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1062 | |
| 1063 | .. _TYPE_CODE_NUMENTRY: |
| 1064 | .. _NUMENTRY: |
| 1065 | |
| 1066 | TYPE_CODE_NUMENTRY Record |
| 1067 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1068 | |
| 1069 | ``[NUMENTRY, numentries]`` |
| 1070 | |
| 1071 | The ``NUMENTRY`` record (code 1) contains a single value which indicates the |
| 1072 | total number of type code entries in the type table of the module. If present, |
| 1073 | ``NUMENTRY`` should be the first record in the block. |
| 1074 | |
| 1075 | TYPE_CODE_VOID Record |
| 1076 | ^^^^^^^^^^^^^^^^^^^^^ |
| 1077 | |
| 1078 | ``[VOID]`` |
| 1079 | |
| 1080 | The ``VOID`` record (code 2) adds a ``void`` type to the type table. |
| 1081 | |
| 1082 | TYPE_CODE_HALF Record |
| 1083 | ^^^^^^^^^^^^^^^^^^^^^ |
| 1084 | |
| 1085 | ``[HALF]`` |
| 1086 | |
| 1087 | The ``HALF`` record (code 10) adds a ``half`` (16-bit floating point) type to |
| 1088 | the type table. |
| 1089 | |
| 1090 | TYPE_CODE_FLOAT Record |
| 1091 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 1092 | |
| 1093 | ``[FLOAT]`` |
| 1094 | |
| 1095 | The ``FLOAT`` record (code 3) adds a ``float`` (32-bit floating point) type to |
| 1096 | the type table. |
| 1097 | |
| 1098 | TYPE_CODE_DOUBLE Record |
| 1099 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 1100 | |
| 1101 | ``[DOUBLE]`` |
| 1102 | |
| 1103 | The ``DOUBLE`` record (code 4) adds a ``double`` (64-bit floating point) type to |
| 1104 | the type table. |
| 1105 | |
| 1106 | TYPE_CODE_LABEL Record |
| 1107 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 1108 | |
| 1109 | ``[LABEL]`` |
| 1110 | |
| 1111 | The ``LABEL`` record (code 5) adds a ``label`` type to the type table. |
| 1112 | |
| 1113 | TYPE_CODE_OPAQUE Record |
| 1114 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 1115 | |
| 1116 | ``[OPAQUE]`` |
| 1117 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1118 | The ``OPAQUE`` record (code 6) adds an ``opaque`` type to the type table, with |
| 1119 | a name defined by a previously encountered ``STRUCT_NAME`` record. Note that |
| 1120 | distinct ``opaque`` types are not unified. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1121 | |
| 1122 | TYPE_CODE_INTEGER Record |
| 1123 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1124 | |
| 1125 | ``[INTEGER, width]`` |
| 1126 | |
| 1127 | The ``INTEGER`` record (code 7) adds an integer type to the type table. The |
| 1128 | single *width* field indicates the width of the integer type. |
| 1129 | |
| 1130 | TYPE_CODE_POINTER Record |
| 1131 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1132 | |
| 1133 | ``[POINTER, pointee type, address space]`` |
| 1134 | |
| 1135 | The ``POINTER`` record (code 8) adds a pointer type to the type table. The |
| 1136 | operand fields are |
| 1137 | |
| 1138 | * *pointee type*: The type index of the pointed-to type |
| 1139 | |
| 1140 | * *address space*: If supplied, the target-specific numbered address space where |
| 1141 | the pointed-to object resides. Otherwise, the default address space is zero. |
| 1142 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1143 | TYPE_CODE_FUNCTION_OLD Record |
| 1144 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1145 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1146 | .. note:: |
| 1147 | This is a legacy encoding for functions, produced by LLVM versions 3.0 and |
| 1148 | earlier. It is guaranteed to be understood by the current LLVM version, as |
| 1149 | specified in the :ref:`IR backwards compatibility` policy. |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1150 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1151 | ``[FUNCTION_OLD, vararg, ignored, retty, ...paramty... ]`` |
| 1152 | |
| 1153 | The ``FUNCTION_OLD`` record (code 9) adds a function type to the type table. |
| 1154 | The operand fields are |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1155 | |
| 1156 | * *vararg*: Non-zero if the type represents a varargs function |
| 1157 | |
| 1158 | * *ignored*: This value field is present for backward compatibility only, and is |
| 1159 | ignored |
| 1160 | |
| 1161 | * *retty*: The type index of the function's return type |
| 1162 | |
| 1163 | * *paramty*: Zero or more type indices representing the parameter types of the |
| 1164 | function |
| 1165 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1166 | TYPE_CODE_ARRAY Record |
| 1167 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 1168 | |
| 1169 | ``[ARRAY, numelts, eltty]`` |
| 1170 | |
| 1171 | The ``ARRAY`` record (code 11) adds an array type to the type table. The |
| 1172 | operand fields are |
| 1173 | |
| 1174 | * *numelts*: The number of elements in arrays of this type |
| 1175 | |
| 1176 | * *eltty*: The type index of the array element type |
| 1177 | |
| 1178 | TYPE_CODE_VECTOR Record |
| 1179 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 1180 | |
| 1181 | ``[VECTOR, numelts, eltty]`` |
| 1182 | |
| 1183 | The ``VECTOR`` record (code 12) adds a vector type to the type table. The |
| 1184 | operand fields are |
| 1185 | |
| 1186 | * *numelts*: The number of elements in vectors of this type |
| 1187 | |
| 1188 | * *eltty*: The type index of the vector element type |
| 1189 | |
| 1190 | TYPE_CODE_X86_FP80 Record |
| 1191 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1192 | |
| 1193 | ``[X86_FP80]`` |
| 1194 | |
| 1195 | The ``X86_FP80`` record (code 13) adds an ``x86_fp80`` (80-bit floating point) |
| 1196 | type to the type table. |
| 1197 | |
| 1198 | TYPE_CODE_FP128 Record |
| 1199 | ^^^^^^^^^^^^^^^^^^^^^^ |
| 1200 | |
| 1201 | ``[FP128]`` |
| 1202 | |
| 1203 | The ``FP128`` record (code 14) adds an ``fp128`` (128-bit floating point) type |
| 1204 | to the type table. |
| 1205 | |
| 1206 | TYPE_CODE_PPC_FP128 Record |
| 1207 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1208 | |
| 1209 | ``[PPC_FP128]`` |
| 1210 | |
| 1211 | The ``PPC_FP128`` record (code 15) adds a ``ppc_fp128`` (128-bit floating point) |
| 1212 | type to the type table. |
| 1213 | |
| 1214 | TYPE_CODE_METADATA Record |
| 1215 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1216 | |
| 1217 | ``[METADATA]`` |
| 1218 | |
| 1219 | The ``METADATA`` record (code 16) adds a ``metadata`` type to the type table. |
| 1220 | |
Mehdi Amini | 472a141 | 2016-10-14 16:23:09 +0000 | [diff] [blame] | 1221 | TYPE_CODE_X86_MMX Record |
| 1222 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1223 | |
| 1224 | ``[X86_MMX]`` |
| 1225 | |
| 1226 | The ``X86_MMX`` record (code 17) adds an ``x86_mmx`` type to the type table. |
| 1227 | |
| 1228 | TYPE_CODE_STRUCT_ANON Record |
| 1229 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1230 | |
| 1231 | ``[STRUCT_ANON, ispacked, ...eltty...]`` |
| 1232 | |
| 1233 | The ``STRUCT_ANON`` record (code 18) adds a literal struct type to the type |
| 1234 | table. The operand fields are |
| 1235 | |
| 1236 | * *ispacked*: Non-zero if the type represents a packed structure |
| 1237 | |
| 1238 | * *eltty*: Zero or more type indices representing the element types of the |
| 1239 | structure |
| 1240 | |
| 1241 | TYPE_CODE_STRUCT_NAME Record |
| 1242 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1243 | |
| 1244 | ``[STRUCT_NAME, ...string...]`` |
| 1245 | |
| 1246 | The ``STRUCT_NAME`` record (code 19) contains a variable number of values |
| 1247 | representing the bytes of a struct name. The next ``OPAQUE`` or |
| 1248 | ``STRUCT_NAMED`` record will use this name. |
| 1249 | |
| 1250 | TYPE_CODE_STRUCT_NAMED Record |
| 1251 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1252 | |
| 1253 | ``[STRUCT_NAMED, ispacked, ...eltty...]`` |
| 1254 | |
| 1255 | The ``STRUCT_NAMED`` record (code 20) adds an identified struct type to the |
| 1256 | type table, with a name defined by a previously encountered ``STRUCT_NAME`` |
| 1257 | record. The operand fields are |
| 1258 | |
| 1259 | * *ispacked*: Non-zero if the type represents a packed structure |
| 1260 | |
| 1261 | * *eltty*: Zero or more type indices representing the element types of the |
| 1262 | structure |
| 1263 | |
| 1264 | TYPE_CODE_FUNCTION Record |
| 1265 | ^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 1266 | |
| 1267 | ``[FUNCTION, vararg, retty, ...paramty... ]`` |
| 1268 | |
| 1269 | The ``FUNCTION`` record (code 21) adds a function type to the type table. The |
| 1270 | operand fields are |
| 1271 | |
| 1272 | * *vararg*: Non-zero if the type represents a varargs function |
| 1273 | |
| 1274 | * *retty*: The type index of the function's return type |
| 1275 | |
| 1276 | * *paramty*: Zero or more type indices representing the parameter types of the |
| 1277 | function |
| 1278 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1279 | .. _CONSTANTS_BLOCK: |
| 1280 | |
| 1281 | CONSTANTS_BLOCK Contents |
| 1282 | ------------------------ |
| 1283 | |
| 1284 | The ``CONSTANTS_BLOCK`` block (id 11) ... |
| 1285 | |
| 1286 | .. _FUNCTION_BLOCK: |
| 1287 | |
| 1288 | FUNCTION_BLOCK Contents |
| 1289 | ----------------------- |
| 1290 | |
| 1291 | The ``FUNCTION_BLOCK`` block (id 12) ... |
| 1292 | |
| 1293 | In addition to the record types described below, a ``FUNCTION_BLOCK`` block may |
| 1294 | contain the following sub-blocks: |
| 1295 | |
| 1296 | * `CONSTANTS_BLOCK`_ |
| 1297 | * `VALUE_SYMTAB_BLOCK`_ |
| 1298 | * `METADATA_ATTACHMENT`_ |
| 1299 | |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1300 | .. _VALUE_SYMTAB_BLOCK: |
| 1301 | |
| 1302 | VALUE_SYMTAB_BLOCK Contents |
| 1303 | --------------------------- |
| 1304 | |
Stephan Tolksdorf | e649335 | 2014-03-13 19:07:39 +0000 | [diff] [blame] | 1305 | The ``VALUE_SYMTAB_BLOCK`` block (id 14) ... |
Bill Wendling | e28d50a | 2012-06-28 08:43:12 +0000 | [diff] [blame] | 1306 | |
| 1307 | .. _METADATA_BLOCK: |
| 1308 | |
| 1309 | METADATA_BLOCK Contents |
| 1310 | ----------------------- |
| 1311 | |
| 1312 | The ``METADATA_BLOCK`` block (id 15) ... |
| 1313 | |
| 1314 | .. _METADATA_ATTACHMENT: |
| 1315 | |
| 1316 | METADATA_ATTACHMENT Contents |
| 1317 | ---------------------------- |
| 1318 | |
| 1319 | The ``METADATA_ATTACHMENT`` block (id 16) ... |
Peter Collingbourne | a0f371a | 2017-04-17 17:51:36 +0000 | [diff] [blame] | 1320 | |
| 1321 | .. _STRTAB_BLOCK: |
| 1322 | |
| 1323 | STRTAB_BLOCK Contents |
| 1324 | --------------------- |
| 1325 | |
| 1326 | The ``STRTAB`` block (id 23) contains a single record (``STRTAB_BLOB``, id 1) |
| 1327 | with a single blob operand containing the bitcode file's string table. |
| 1328 | |
| 1329 | Strings in the string table are not null terminated. A record's *strtab |
| 1330 | offset* and *strtab size* operands specify the byte offset and size of a |
| 1331 | string within the string table. |
| 1332 | |
| 1333 | The string table is used by all preceding blocks in the bitcode file that are |
| 1334 | not succeeded by another intervening ``STRTAB`` block. Normally a bitcode |
| 1335 | file will have a single string table, but it may have more than one if it |
| 1336 | was created by binary concatenation of multiple bitcode files. |