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