From bb7425fafb3ec90895f45e4bb26d135bcf6126ab Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sat, 4 Apr 2009 22:27:03 +0000 Subject: [PATCH] General clean-up of the bitcode format documentation. Having the paragraphs formatted the same, putting words in tags, adding —s, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@68426 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/BitCodeFormat.html | 355 +++++++++++++++++++++++----------------- 1 file changed, 206 insertions(+), 149 deletions(-) diff --git a/docs/BitCodeFormat.html b/docs/BitCodeFormat.html index d808cf6eeb8..1c87b888969 100644 --- a/docs/BitCodeFormat.html +++ b/docs/BitCodeFormat.html @@ -180,13 +180,15 @@ value of 24 (011 << 3) with no continuation. The sum (3+24) yields the value

6-bit characters encode common characters into a fixed 6-bit field. They represent the following characters with the following 6-bit values:

- +
+
+'a' .. 'z' —  0 .. 25
+'A' .. 'Z' — 26 .. 51
+'0' .. '9' — 52 .. 61
+       '.' — 62
+       '_' — 63
+
+

This encoding is only suitable for encoding characters and strings that consist only of the above characters. It is completely incapable of encoding @@ -226,14 +228,14 @@ The set of builtin abbrev IDs is:

Abbreviation IDs 4 and above are defined by the stream itself, and specify @@ -273,14 +275,17 @@ block. In particular, each block maintains:

  • A set of abbreviations. Abbreviations may be defined within a block, in which case they are only defined in that block (neither subblocks nor enclosing blocks see the abbreviation). Abbreviations can also be defined - inside a BLOCKINFO block, in which case they are - defined in all blocks that match the ID that the BLOCKINFO block is describing. + inside a BLOCKINFO block, in which case + they are defined in all blocks that match the ID that the BLOCKINFO block is + describing.
  • -

    As sub blocks are entered, these properties are saved and the new sub-block -has its own set of abbreviations, and its own abbrev id width. When a sub-block -is popped, the saved values are restored.

    +

    +As sub blocks are entered, these properties are saved and the new sub-block has +its own set of abbreviations, and its own abbrev id width. When a sub-block is +popped, the saved values are restored. +

    @@ -294,14 +299,14 @@ Encoding <align32bits>, blocklen32]

    -The ENTER_SUBBLOCK abbreviation ID specifies the start of a new block record. -The blockid value is encoded as a 8-bit VBR identifier, and indicates -the type of block being entered (which can be a standard -block or an application-specific block). The -newabbrevlen value is a 4-bit VBR which specifies the -abbrev id width for the sub-block. The blocklen is a 32-bit aligned -value that specifies the size of the subblock, in 32-bit words. This value -allows the reader to skip over the entire block in one jump. +The ENTER_SUBBLOCK abbreviation ID specifies the start of a new block +record. The blockid value is encoded as an 8-bit VBR identifier, and +indicates the type of block being entered, which can be +a standard block or an application-specific block. +The newabbrevlen value is a 4-bit VBR, which specifies the abbrev id +width for the sub-block. The blocklen value is a 32-bit aligned value +that specifies the size of the subblock in 32-bit words. This value allows the +reader to skip over the entire block in one jump.

    @@ -315,9 +320,10 @@ Encoding

    [END_BLOCK, <align32bits>]

    -The END_BLOCK abbreviation ID specifies the end of the current block record. -Its end is aligned to 32-bits to ensure that the size of the block is an even -multiple of 32-bits.

    +The END_BLOCK abbreviation ID specifies the end of the current block +record. Its end is aligned to 32-bits to ensure that the size of the block is +an even multiple of 32-bits. +

    @@ -331,11 +337,12 @@ multiple of 32-bits.

    Data records consist of a record code and a number of (up to) 64-bit integer values. The interpretation of the code and values is application specific and -there are multiple different ways to encode a record (with an unabbrev record -or with an abbreviation). In the LLVM IR format, for example, there is a record -which encodes the target triple of a module. The code is MODULE_CODE_TRIPLE, -and the values of the record are the ascii codes for the characters in the -string.

    +there are multiple different ways to encode a record (with an unabbrev record or +with an abbreviation). In the LLVM IR format, for example, there is a record +which encodes the target triple of a module. The code is +MODULE_CODE_TRIPLE, and the values of the record are the ASCII codes +for the characters in the string. +

    @@ -348,17 +355,21 @@ Encoding

    [UNABBREV_RECORD, codevbr6, numopsvbr6, op0vbr6, op1vbr6, ...]

    -

    An UNABBREV_RECORD provides a default fallback encoding, which is both -completely general and also extremely inefficient. It can describe an arbitrary -record, by emitting the code and operands as vbrs.

    +

    +An UNABBREV_RECORD provides a default fallback encoding, which is both +completely general and extremely inefficient. It can describe an arbitrary +record by emitting the code and operands as vbrs. +

    -

    For example, emitting an LLVM IR target triple as an unabbreviated record -requires emitting the UNABBREV_RECORD abbrevid, a vbr6 for the -MODULE_CODE_TRIPLE code, a vbr6 for the length of the string (which is equal to -the number of operands), and a vbr6 for each character. Since there are no -letters with value less than 32, each letter would need to be emitted as at -least a two-part VBR, which means that each letter would require at least 12 -bits. This is not an efficient encoding, but it is fully general.

    +

    +For example, emitting an LLVM IR target triple as an unabbreviated record +requires emitting the UNABBREV_RECORD abbrevid, a vbr6 for the +MODULE_CODE_TRIPLE code, a vbr6 for the length of the string, which is +equal to the number of operands, and a vbr6 for each character. Because there +are no letters with values less than 32, each letter would need to be emitted as +at least a two-part VBR, which means that each letter would require at least 12 +bits. This is not an efficient encoding, but it is fully general. +

    @@ -370,13 +381,14 @@ Encoding

    [<abbrevid>, fields...]

    -

    An abbreviated record is a abbreviation id followed by a set of fields that -are encoded according to the abbreviation -definition. This allows records to be encoded significantly more densely -than records encoded with the UNABBREV_RECORD -type, and allows the abbreviation types to be specified in the stream itself, -which allows the files to be completely self describing. The actual encoding -of abbreviations is defined below. +

    +An abbreviated record is a abbreviation id followed by a set of fields that are +encoded according to the abbreviation definition. +This allows records to be encoded significantly more densely than records +encoded with the UNABBREV_RECORD type, +and allows the abbreviation types to be specified in the stream itself, which +allows the files to be completely self describing. The actual encoding of +abbreviations is defined below.

    @@ -395,7 +407,7 @@ emitted.

    -Abbreviations can be determined dynamically per client, per file. Since the +Abbreviations can be determined dynamically per client, per file. Because the abbreviations are stored in the bitstream itself, different streams of the same format can contain different sets of abbreviations if the specific stream does not need it. As a concrete example, LLVM IR files usually emit an abbreviation @@ -413,33 +425,36 @@ operators, the abbreviation does not need to be emitted.

    [DEFINE_ABBREV, numabbrevopsvbr5, abbrevop0, abbrevop1, ...]

    -

    A DEFINE_ABBREV record adds an abbreviation to the list of currently -defined abbreviations in the scope of this block. This definition only -exists inside this immediate block -- it is not visible in subblocks or -enclosing blocks. -Abbreviations are implicitly assigned IDs -sequentially starting from 4 (the first application-defined abbreviation ID). -Any abbreviations defined in a BLOCKINFO record receive IDs first, in order, -followed by any abbreviations defined within the block itself. -Abbreviated data records reference this ID to indicate what abbreviation -they are invoking.

    +

    +A DEFINE_ABBREV record adds an abbreviation to the list of currently +defined abbreviations in the scope of this block. This definition only exists +inside this immediate block — it is not visible in subblocks or enclosing +blocks. Abbreviations are implicitly assigned IDs sequentially starting from 4 +(the first application-defined abbreviation ID). Any abbreviations defined in a +BLOCKINFO record receive IDs first, in order, followed by any +abbreviations defined within the block itself. Abbreviated data records +reference this ID to indicate what abbreviation they are invoking. +

    -

    An abbreviation definition consists of the DEFINE_ABBREV abbrevid followed -by a VBR that specifies the number of abbrev operands, then the abbrev +

    +An abbreviation definition consists of the DEFINE_ABBREV abbrevid +followed by a VBR that specifies the number of abbrev operands, then the abbrev operands themselves. Abbreviation operands come in three forms. They all start with a single bit that indicates whether the abbrev operand is a literal operand -(when the bit is 1) or an encoding operand (when the bit is 0).

    +(when the bit is 1) or an encoding operand (when the bit is 0). +

      -
    1. Literal operands - [11, litvaluevbr8] - -Literal operands specify that the value in the result -is always a single specific value. This specific value is emitted as a vbr8 -after the bit indicating that it is a literal operand.
    2. -
    3. Encoding info without data - [01, encoding3] - - Operand encodings that do not have extra data are just emitted as their code. +
    4. Literal operands — [11, litvaluevbr8] +— Literal operands specify that the value in the result is always a single +specific value. This specific value is emitted as a vbr8 after the bit +indicating that it is a literal operand.
    5. +
    6. Encoding info without data — [01, + encoding3] — Operand encodings that do not have extra + data are just emitted as their code.
    7. -
    8. Encoding info with data - [01, encoding3, -valuevbr5] - Operand encodings that do have extra data are +
    9. Encoding info with data — [01, encoding3, +valuevbr5] — Operand encodings that do have extra data are emitted as their code, followed by the extra data.
    @@ -447,53 +462,65 @@ emitted as their code, followed by the extra data.

    The possible operand encodings are:

    -

    For example, target triples in LLVM modules are encoded as a record of the +

    +For example, target triples in LLVM modules are encoded as a record of the form [TRIPLE, 'a', 'b', 'c', 'd']. Consider if the bitstream emitted -the following abbrev entry:

    +the following abbrev entry: +

    - +
    +
    +[0, Fixed, 4]
    +[0, Array]
    +[0, Char6]
    +
    +
    -

    When emitting a record with this abbreviation, the above entry would be -emitted as:

    +

    +When emitting a record with this abbreviation, the above entry would be emitted +as: +

    -

    [4abbrevwidth, 24, 4vbr6, - 06, 16, 26, 36]

    +
    +
    +[4abbrevwidth, 24, 4vbr6, 06, 16, 26, 36]
    +
    +

    These values are:

    1. The first value, 4, is the abbreviation ID for this abbreviation.
    2. -
    3. The second value, 2, is the code for TRIPLE in LLVM IR files.
    4. +
    5. The second value, 2, is the code for TRIPLE in LLVM IR files.
    6. The third value, 4, is the length of the array.
    7. -
    8. The rest of the values are the char6 encoded values for "abcd".
    9. +
    10. The rest of the values are the char6 encoded values + for "abcd".
    -

    With this abbreviation, the triple is emitted with only 37 bits (assuming a +

    +With this abbreviation, the triple is emitted with only 37 bits (assuming a abbrev id width of 3). Without the abbreviation, significantly more space would -be required to emit the target triple. Also, since the TRIPLE value is not -emitted as a literal in the abbreviation, the abbreviation can also be used for -any other string value. +be required to emit the target triple. Also, because the TRIPLE value +is not emitted as a literal in the abbreviation, the abbreviation can also be +used for any other string value.

    @@ -519,33 +546,38 @@ Block
    -

    The BLOCKINFO block allows the description of metadata for other blocks. The - currently specified records are:

    - - +

    +The BLOCKINFO block allows the description of metadata for other +blocks. The currently specified records are: +

    + +
    +
    +[SETBID (#1), blockid]
    +[DEFINE_ABBREV, ...]
    +
    +

    -The SETBID record indicates which block ID is being described. SETBID -records can occur multiple times throughout the block to change which -block ID is being described. There must be a SETBID record prior to -any other records. +The SETBID record indicates which block ID is being +described. SETBID records can occur multiple times throughout the +block to change which block ID is being described. There must be +a SETBID record prior to any other records.

    -Standard DEFINE_ABBREV records can occur inside BLOCKINFO blocks, but unlike -their occurrence in normal blocks, the abbreviation is defined for blocks -matching the block ID we are describing, not the BLOCKINFO block itself. -The abbreviations defined in BLOCKINFO blocks receive abbreviation ids -as described in DEFINE_ABBREV. +Standard DEFINE_ABBREV records can occur inside BLOCKINFO +blocks, but unlike their occurrence in normal blocks, the abbreviation is +defined for blocks matching the block ID we are describing, not the +BLOCKINFO block itself. The abbreviations defined +in BLOCKINFO blocks receive abbreviation IDs as described +in DEFINE_ABBREV.

    -Note that although the data in BLOCKINFO blocks is described as "metadata," the -abbreviations they contain are essential for parsing records from the -corresponding blocks. It is not safe to skip them. +Note that although the data in BLOCKINFO blocks is described as +"metadata," the abbreviations they contain are essential for parsing records +from the corresponding blocks. It is not safe to skip them.

    @@ -556,24 +588,29 @@ corresponding blocks. It is not safe to skip them.
    -

    Bitcode files for LLVM IR may optionally be wrapped in a simple wrapper +

    +Bitcode files for LLVM IR may optionally be wrapped in a simple wrapper structure. This structure contains a simple header that indicates the offset and size of the embedded BC file. This allows additional information to be stored alongside the BC file. The structure of this file header is:

    -

    -[Magic32, Version32, Offset32, - Size32, CPUType32]

    +
    +
    +[Magic32, Version32, Offset32, Size32, CPUType32]
    +
    +
    -

    Each of the fields are 32-bit fields stored in little endian form (as with +

    +Each of the fields are 32-bit fields stored in little endian form (as with the rest of the bitcode file fields). The Magic number is always 0x0B17C0DE and the version is currently always 0. The Offset field is the offset in bytes to the start of the bitcode stream in the file, and the Size field is a size in bytes of the stream. CPUType is a target-specific value that can be used to encode the CPU of the target. -

    +

    +
    LLVM IR Encoding
    @@ -581,12 +618,14 @@ value that can be used to encode the CPU of the target.
    -

    LLVM IR is encoded into a bitstream by defining blocks and records. It uses +

    +LLVM IR is encoded into a bitstream by defining blocks and records. It uses blocks for things like constant pools, functions, symbol tables, etc. It uses records for things like instructions, global variable descriptors, type descriptions, etc. This document does not describe the set of abbreviations that the writer uses, as these are fully self-described in the file, and the -reader is not allowed to build in any knowledge of this.

    +reader is not allowed to build in any knowledge of this. +

    @@ -603,9 +642,16 @@ reader is not allowed to build in any knowledge of this.

    The magic number for LLVM IR files is:

    -

    [0x04, 0xC4, 0xE4, 0xD4]

    +
    +
    +[0x04, 0xC4, 0xE4, 0xD4]
    +
    +
    -

    When combined with the bitcode magic number and viewed as bytes, this is "BC 0xC0DE".

    +

    +When combined with the bitcode magic number and viewed as bytes, this is +"BC 0xC0DE". +

    @@ -618,9 +664,12 @@ The magic number for LLVM IR files is: Variable Width Integers are an efficient way to encode arbitrary sized unsigned values, but is an extremely inefficient way to encode signed values (as signed values are otherwise treated as maximally large -unsigned values).

    +unsigned values). +

    -

    As such, signed vbr values of a specific width are emitted as follows:

    +

    +As such, signed vbr values of a specific width are emitted as follows: +

    -

    With this encoding, small positive and small negative values can both be -emitted efficiently.

    +

    +With this encoding, small positive and small negative values can both be emitted +efficiently. +

    @@ -645,15 +696,21 @@ LLVM IR is defined with the following blocks: