From: Reid Spencer Date: Thu, 29 Jul 2004 00:13:04 +0000 (+0000) Subject: Updates to reflect most recent changes to bytecode file format: X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=9bd2be2dcd4aa68f3eaf99353ee65335ef4e884b;p=oota-llvm.git Updates to reflect most recent changes to bytecode file format: * Dependent libraries & target triple * Short block headers * 24-bit type slot ids. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15314 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/BytecodeFormat.html b/docs/BytecodeFormat.html index 68f724309c6..78b3976a8a3 100644 --- a/docs/BytecodeFormat.html +++ b/docs/BytecodeFormat.html @@ -1,5 +1,4 @@ - + LLVM Bytecode File Format @@ -13,7 +12,7 @@ -
LLVM Bytecode File Format
+
LLVM Bytecode File Format
  1. Abstract
  2. Concepts @@ -53,385 +52,518 @@

    Written by Reid Spencer

    -
    -

    This document describes the LLVM bytecode file format. It specifies the - binary encoding rules of the bytecode file format so that equivalent systems - can encode bytecode files correctly. The LLVM bytecode representation is - used to store the intermediate representation on disk in compacted form.

    -

    The LLVM bytecode format may change in the future, but LLVM will always be - backwards compatible with older formats. This document will only describe - the most current version of the bytecode format. See - Version Differences for the details on how the - current version is different from previous versions.

    -

    +

    This document describes the LLVM bytecode file format. It specifies +the binary encoding rules of the bytecode file format so that +equivalent systems can encode bytecode files correctly. The LLVM +bytecode representation is used to store the intermediate +representation on disk in compacted form.

    +

    The LLVM bytecode format may change in the future, but LLVM will +always be backwards compatible with older formats. This document will +only describe the most current version of the bytecode format. See Version Differences for the details on how +the current version is different from previous versions.

    -
    -

    This section describes the general concepts of the bytecode file format - without getting into specific layout details. It is recommended that you read - this section thoroughly before interpreting the detailed descriptions.

    +

    This section describes the general concepts of the bytecode file +format without getting into specific layout details. It is recommended +that you read this section thoroughly before interpreting the detailed +descriptions.

    -
    -

    LLVM bytecode files consist simply of a sequence of blocks of bytes using - a binary encoding Each block begins with an header of two unsigned integers. - The first value identifies the type of block and the second value provides - the size of the block in bytes. The block identifier is used because it is - possible for entire blocks to be omitted from the file if they are empty. - The block identifier helps the reader determine which kind of block is next - in the file. Note that blocks can be nested within other blocks.

    -

    All blocks are variable length, and the block header specifies the size - of the block. All blocks begin on a byte index that is aligned to an even - 32-bit boundary. That is, the first block is 32-bit aligned because it - starts at offset 0. Each block is padded with zero fill bytes to ensure that - the next block also starts on a 32-bit boundary.

    +

    LLVM bytecode files consist simply of a sequence of blocks of bytes +using a binary encoding Each block begins with an header of two +unsigned integers. The first value identifies the type of block and the +second value provides the size of the block in bytes. The block +identifier is used because it is possible for entire blocks to be +omitted from the file if they are empty. The block identifier helps the +reader determine which kind of block is next in the file. Note that +blocks can be nested within other blocks.

    +

    All blocks are variable length, and the block header specifies the +size of the block. All blocks begin on a byte index that is aligned to +an even 32-bit boundary. That is, the first block is 32-bit aligned +because it starts at offset 0. Each block is padded with zero fill +bytes to ensure that the next block also starts on a 32-bit boundary.

    -
    -

    LLVM Bytecode blocks often contain lists of things of a similar type. For - example, a function contains a list of instructions and a function type - contains a list of argument types. There are two basic types of lists: - length lists (llist), and null terminated lists - (zlist), as described below in the - Encoding Primitives.

    +

    LLVM Bytecode blocks often contain lists of things of a similar +type. For example, a function contains a list of instructions and a +function type contains a list of argument types. There are two basic +types of lists: length lists (llist), and null +terminated lists (zlist), as described below in +the Encoding Primitives.

    -
    -

    Fields are units of information that LLVM knows how to write atomically. -Most fields have a uniform length or some kind of length indication built into -their encoding. For example, a constant string (array of bytes) is -written simply as the length followed by the characters. Although this is -similar to a list, constant strings are treated atomically and are thus -fields.

    +

    Fields are units of information that LLVM knows how to write atomically. Most +fields have a uniform length or some kind of length indication built into their +encoding. For example, a constant string (array of bytes) is written simply as +the length followed by the characters. Although this is similar to a list, +constant strings are treated atomically and are thus fields.

    Fields use a condensed bit format specific to the type of information they must contain. As few bits as possible are written for each field. The -sections that follow will provide the details on how these fields are +sections that follow will provide the details on how these fields are written and how the bits are to be interpreted.

    -
    -

    To support cross-platform differences, the bytecode file is aligned on - certain boundaries. This means that a small amount of padding (at most 3 - bytes) will be added to ensure that the next entry is aligned to a 32-bit - boundary.

    +

    To support cross-platform differences, the bytecode file is aligned +on certain boundaries. This means that a small amount of padding (at +most 3 bytes) will be added to ensure that the next entry is aligned to +a 32-bit boundary.

    - - +
    -

    Most of the values written to LLVM bytecode files are small integers. To -minimize the number of bytes written for these quantities, an encoding -scheme similar to UTF-8 is used to write integer data. The scheme is known as -variable bit rate (vbr) encoding. In this encoding, the high bit of each -byte is used to indicate if more bytes follow. If (byte & 0x80) is non-zero -in any given byte, it means there is another byte immediately following that -also contributes to the value. For the final byte (byte & 0x80) is false -(the high bit is not set). In each byte only the low seven bits contribute to -the value. Consequently 32-bit quantities can take from one to five -bytes to encode. In general, smaller quantities will encode in fewer bytes, -as follows:

    +

    Most of the values written to LLVM bytecode files are small integers. To +minimize the number of bytes written for these quantities, an encoding scheme +similar to UTF-8 is used to write integer data. The scheme is known as +variable bit rate (vbr) encoding. In this encoding, the high bit of +each byte is used to indicate if more bytes follow. If (byte & +0x80) is non-zero in any given byte, it means there is another byte +immediately following that also contributes to the value. For the final +byte (byte & 0x80) is false (the high bit is not set). In each byte +only the low seven bits contribute to the value. Consequently 32-bit +quantities can take from one to five bytes to encode. In +general, smaller quantities will encode in fewer bytes, as follows:

    - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Byte #Significant BitsMaximum Value
    10-6127
    27-1316,383
    314-202,097,151
    421-27268,435,455
    528-3434,359,738,367
    635-414,398,046,511,103
    742-48562,949,953,421,311
    849-5572,057,594,037,927,935
    956-629,223,372,036,854,775,807
    1063-691,180,591,620,717,411,303,423
    Byte #Significant BitsMaximum Value
    10-6127
    27-1316,383
    314-202,097,151
    421-27268,435,455
    528-3434,359,738,367
    635-414,398,046,511,103
    742-48562,949,953,421,311
    849-5572,057,594,037,927,935
    956-629,223,372,036,854,775,807
    1063-691,180,591,620,717,411,303,423
    -

    Note that in practice, the tenth byte could only encode bit 63 -since the maximum quantity to use this encoding is a 64-bit integer.

    - -

    Signed VBR values are encoded with the standard vbr encoding, but -with the sign bit as the low order bit instead of the high order bit. This -allows small negative quantities to be encoded efficiently. For example, -3 -is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << 1) | -0)", emitted with the standard vbr encoding above.

    +

    Note that in practice, the tenth byte could only encode bit 63 since +the maximum quantity to use this encoding is a 64-bit integer.

    +

    Signed VBR values are encoded with the standard vbr +encoding, but with the sign bit as the low order bit instead of the +high order bit. This allows small negative quantities to be encoded +efficiently. For example, -3 +is encoded as "((3 << 1) | 1)" and 3 is encoded as "(3 << +1) | 0)", emitted with the standard vbr encoding above.

    -
    -

    Each field in the bytecode format is encoded into the file using a small - set of primitive formats. The table below defines the encoding rules for the - various primitives used and gives them each a type name. The type names used - in the descriptions of blocks and fields in the Detailed - Layoutnext section. Any type name with the suffix _vbr indicates - a quantity that is encoded using variable bit rate encoding as described - above.

    - - - - - - - - +
    TypeRule
    unsignedA 32-bit unsigned integer that always occupies four +

    Each field in the bytecode format is encoded into the file using a +small set of primitive formats. The table below defines the encoding +rules for the various primitives used and gives them each a type name. +The type names used in the descriptions of blocks and fields in the Detailed Layoutnext section. Any type name with +the suffix _vbr indicates a quantity that is encoded using +variable bit rate encoding as described above.

    + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeRule
    unsignedA 32-bit unsigned integer that always occupies four consecutive bytes. The unsigned integer is encoded using LSB first ordering. That is bits 20 through 27 are in the byte with the lowest file offset (little endian).
    uint32_vbrA 32-bit unsigned integer that occupies from one to five - bytes using variable bit rate encoding.
    uint64_vbrA 64-bit unsigned integer that occupies from one to ten - bytes using variable bit rate encoding.
    int64_vbrA 64-bit signed integer that occupies from one to ten - bytes using the signed variable bit rate encoding.
    charA single unsigned character encoded into one byte
    bit(n-m)A set of bit within some larger integer field. The - values of n and m specify the inclusive range - of bits that define the subfield. The value for m may be - omitted if its the same as n.
    stringA uint32_vbr indicating the type of the constant string - which also includes its length, immediately followed by the characters of - the string. There is no terminating null byte in the string.
    dataAn arbitrarily long segment of data to which no - interpretation is implied. This is used for float, double, and constant - initializers.
    llist(x)A length list of x. This means the list is encoded as - an uint32_vbr providing the length of the list, - followed by a sequence of that many "x" items. This implies that the reader - should iterate the number of times provided by the length.
    zlist(x)A zero-terminated list of x. This means the list is encoded - as a sequence of an indeterminate number of "x" items, followed by an - uint32_vbr terminating value. This implies that none - of the "x" items can have a zero value (or else the list terminates).
    blockA block of data that is logically related. A block - begins with an unsigned that provides the block - identifier (constant value) and an unsigned that - provides the length of the block. Blocks may compose other blocks. -
    uint24_vbrA 24-bit unsigned + integer that occupies from one to four bytes using variable bit rate + encoding.
    uint32_vbrA 32-bit unsigned integer that occupies from +one to five bytes using variable bit rate encoding.
    uint64_vbrA 64-bit unsigned integer that occupies from +one to ten bytes using variable bit rate encoding.
    int64_vbrA 64-bit signed integer that occupies from +one to ten bytes using the signed variable bit rate encoding.
    charA single unsigned character encoded into one +byte
    bit(n-m)A set of bit within some larger integer +field. The values of n and m specify the +inclusive range of bits that define the subfield. The value for m +may be omitted if its the same as n.
    floatA floating +point value encoded as a 32-bit IEEE value written in little-endian +form.
    +
    doubleA floating +point value encoded as a64-bit IEEE value written in little-endian form
    stringA uint32_vbr indicating the type of the +constant string which also includes its length, immediately followed by +the characters of the string. There is no terminating null byte in the +string.
    dataAn arbitrarily long segment of data to which +no interpretation is implied. This is used for constant initializers.
    +
    llist(x)A length list of x. This means the list is +encoded as an uint32_vbr providing the +length of the list, followed by a sequence of that many "x" items. This +implies that the reader should iterate the number of times provided by +the length.
    zlist(x)A zero-terminated list of x. This means the +list is encoded as a sequence of an indeterminate number of "x" items, +followed by an uint32_vbr terminating value. +This implies that none of the "x" items can have a zero value (or else +the list terminates).
    blockA block of data that is logically related. A +block is an unsigned 32-bit integer that encodes the type of the block +in the low 5 bits and the size of the block in the high 27 bits. The +length does not include the block header or any alignment bytes at the +end of the block. Blocks may compose other blocks.
    -
    -

    In the detailed block and field descriptions that follow, a regex like - notation is used to describe optional and repeated fields. A very limited - subset of regex is used to describe these, as given in the following table: -

    - +

    In the detailed block and field descriptions that follow, a regex +like notation is used to describe optional and repeated fields. A very +limited subset of regex is used to describe these, as given in the +following table:

    +
    + - + + - - + + + - - + + + - - + + + - + + - + -
    Character Meaning
    ?The question mark indicates 0 or 1 occurrences of - the thing preceding it.
    The question mark indicates 0 or 1 +occurrences of the thing preceding it.
    *The asterisk indicates 0 or more occurrences of the - thing preceding it.
    The asterisk indicates 0 or more occurrences +of the thing preceding it.
    +The plus sign indicates 1 or more occurrences of the - thing preceding it.
    The plus sign indicates 1 or more occurrences +of the thing preceding it.
    () Parentheses are used for grouping.
    ,The comma separates sequential fields.The comma separates sequential fields.
    -

    So, for example, consider the following specifications:

    -
    -
      -
    1. string?
    2. -
    3. (uint32_vbr,uin32_vbr)+
    4. -
    5. (unsigned?,uint32_vbr)*
    6. -
    7. (llist(unsigned))?
    8. -
    -
    -

    with the following interpretations:

    -
      -
    1. An optional string. Matches either nothing or a single string
    2. -
    3. One or more pairs of uint32_vbr.
    4. -
    5. Zero or more occurrences of either an unsigned followed by a uint32_vbr - or just a uint32_vbr.
    6. -
    7. An optional length list of unsigned values.
    8. -
    +
    +

    So, for example, consider the following specifications:

    +
    +
      +
    1. string?
    2. +
    3. (uint32_vbr,uin32_vbr)+
    4. +
    5. (unsigned?,uint32_vbr)*
    6. +
    7. (llist(unsigned))?
    8. +
    +
    +

    with the following interpretations:

    +
      +
    1. An optional string. Matches either nothing or a single string
    2. +
    3. One or more pairs of uint32_vbr.
    4. +
    5. Zero or more occurrences of either an unsigned followed by a +uint32_vbr or just a uint32_vbr.
    6. +
    7. An optional length list of unsigned values.
    8. +
    -
    -

    The bytecode format uses the notion of a "slot" to reference Types and -Values. Since the bytecode file is a direct representation of LLVM's -intermediate representation, there is a need to represent pointers in the file. -Slots are used for this purpose. For example, if one has the following assembly: +

    The bytecode format uses the notion of a "slot" to reference Types +and Values. Since the bytecode file is a direct representation of +LLVM's intermediate representation, there is a need to represent pointers in +the file. Slots are used for this purpose. For example, if one has the following +assembly:

    -
    - %MyType = type { int, sbyte }
    - %MyVar = external global %MyType +
    %MyType = type { int, sbyte }
    +%MyVar = external global %MyType
    -

    there are two definitions. The definition of %MyVar uses -%MyType. In the C++ IR this linkage between %MyVar and -%MyType is -explicit through the use of C++ pointers. In bytecode, however, there's no -ability to store memory addresses. Instead, we compute and write out slot -numbers for every Type and Value written to the file.

    +

    there are two definitions. The definition of %MyVar uses %MyType. +In the C++ IR this linkage between %MyVar and %MyType +is explicit through the use of C++ pointers. In bytecode, however, there's no +ability to store memory addresses. Instead, we compute and write out +slot numbers for every Type and Value written to the file.

    A slot number is simply an unsigned 32-bit integer encoded in the variable bit rate scheme (see encoding). This ensures that low slot numbers are encoded in one byte. Through various bits of magic LLVM attempts to always keep the slot numbers low. The first attempt is to associate -slot numbers with their "type plane". That is, Values of the same type are -written to the bytecode file in a list (sequentially). Their order in that list -determines their slot number. This means that slot #1 doesn't mean anything -unless you also specify for which type you want slot #1. Types are handled -specially and are always written to the file first (in the -Global Type Pool) and -in such a way that both forward and backward references of the types can often be -resolved with a single pass through the type pool.

    -

    Slot numbers are also kept small by rearranging their order. Because of the -structure of LLVM, certain values are much more likely to be used frequently -in the body of a function. For this reason, a compaction table is provided in -the body of a function if its use would make the function body smaller. -Suppose you have a function body that uses just the types "int*" and "{double}" -but uses them thousands of time. Its worthwhile to ensure that the slot number -for these types are low so they can be encoded in a single byte (via vbr). -This is exactly what the compaction table does.

    +slot numbers with their "type plane". That is, Values of the same type +are written to the bytecode file in a list (sequentially). Their order in +that list determines their slot number. This means that slot #1 doesn't mean +anything unless you also specify for which type you want slot #1. Types are +handled specially and are always written to the file first (in the Global Type Pool) and in such a way that both forward +and backward references of the types can often be resolved with a single pass +through the type pool.

    +

    Slot numbers are also kept small by rearranging their order. Because +of the structure of LLVM, certain values are much more likely to be used +frequently in the body of a function. For this reason, a compaction table is +provided in the body of a function if its use would make the function body +smaller. Suppose you have a function body that uses just the types "int*" and +"{double}" but uses them thousands of time. Its worthwhile to ensure that the +slot number for these types are low so they can be encoded in a single byte +(via vbr). This is exactly what the compaction table does.

    -
    -

    This section provides the general structure of the LLVM bytecode file - format. The bytecode file format requires blocks to be in a certain order and - nested in a particular way so that an LLVM module can be constructed - efficiently from the contents of the file. This ordering defines a general - structure for bytecode files as shown below. The table below shows the order - in which all block types may appear. Please note that some of the blocks are - optional and some may be repeated. The structure is fairly loose because - optional blocks, if empty, are completely omitted from the file.

    +

    This section provides the general structure of the LLVM bytecode +file format. The bytecode file format requires blocks to be in a +certain order and nested in a particular way so that an LLVM module can +be constructed efficiently from the contents of the file. This ordering +defines a general structure for bytecode files as shown below. The +table below shows the order in which all block types may appear. Please +note that some of the blocks are optional and some may be repeated. The +structure is fairly loose because optional blocks, if empty, are +completely omitted from the file.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    IDParentOptional?Repeated?LevelBlock TypeDescription
    N/AFileNoNo0SignatureThis contains the file signature (magic number) - that identifies the file as LLVM bytecode.
    0x01FileNoNo0ModuleThis is the top level block in a bytecode file. It - contains all the other blocks. -
    0x15ModuleNoNo1   Global Type PoolThis block contains all the global (module) level - types.
    0x14ModuleNoNo1   Module Globals InfoThis block contains the type, constness, and linkage - for each of the global variables in the module. It also contains the - type of the functions and the constant initializers.
    0x12ModuleYesNo1   Module Constant PoolThis block contains all the global constants - except function arguments, global values and constant strings.
    0x11ModuleYesYes1   Function Definitions*One function block is written for each function in - the module. The function block contains the instructions, compaction - table, type constant pool, and symbol table for the function.
    0x12FunctionYesNo2      Function Constant PoolAny constants (including types) used solely - within the function are emitted here in the function constant pool. -
    0x33FunctionYesNo2      Compaction TableThis table reduces bytecode size by providing a - funtion-local mapping of type and value slot numbers to their - global slot numbers
    0x32FunctionNoNo2      Instruction ListThis block contains all the instructions of the - function. The basic blocks are inferred by terminating instructions. -
    0x13FunctionYesNo2      Function Symbol TableThis symbol table provides the names for the - function specific values used (basic block labels mostly).
    0x13ModuleYesNo1   Module Symbol TableThis symbol table provides the names for the various - entries in the file that are not function specific (global vars, and - functions mostly).
    IDParentOptional?Repeated?LevelBlock TypeDescription
    N/AFileNoNo0SignatureThis contains the file signature (magic +number) that identifies the file as LLVM bytecode.
    0x01FileNoNo0ModuleThis is the top level block in a bytecode +file. It contains all the other blocks.
    0x06ModuleNoNo1   Global Type PoolThis block contains all the global (module) +level types.
    0x05ModuleNoNo1   Module Globals InfoThis block contains the type, constness, and +linkage for each of the global variables in the module. It also +contains the type of the functions and the constant initializers.
    0x03ModuleYesNo1   Module Constant PoolThis block contains all the global constants +except function arguments, global values and constant strings.
    0x02ModuleYesYes1   Function Definitions*One function block is written for each +function in the module. The function block contains the instructions, +compaction table, type constant pool, and symbol table for the function.
    0x03FunctionYesNo2      Function Constant PoolAny constants (including types) used solely +within the function are emitted here in the function constant pool.
    0x08FunctionYesNo2      Compaction TableThis table reduces bytecode size by providing +a funtion-local mapping of type and value slot numbers to their global +slot numbers
    0x07FunctionNoNo2      Instruction ListThis block contains all the instructions of +the function. The basic blocks are inferred by terminating +instructions.
    0x04FunctionYesNo2      Function Symbol TableThis symbol table provides the names for the +function specific values used (basic block labels mostly).
    0x04ModuleYesNo1   Module Symbol TableThis symbol table provides the names for the +various entries in the file that are not function specific (global +vars, and functions mostly).
    -

    Use the links in the table for details about the contents of each of the block types.

    +

    Use the links in the table for details about the contents of each of +the block types.

    -
    -

    This section provides the detailed layout of the individual block types - in the LLVM bytecode file format.

    +

    This section provides the detailed layout of the individual block +types in the LLVM bytecode file format.

    -
    @@ -440,26 +572,32 @@ It simply provides a few bytes of data to identify the file as being an LLVM bytecode file. This block is always four bytes in length and differs from the other blocks because there is no identifier and no block length at the start of the block. Essentially, this block is just the "magic number" for the file. +

    - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    TypeField Description
    charConstant "l" (0x6C)
    charConstant "l" (0x6C)
    charConstant "v" (0x76)
    charConstant "m" (0x6D)
    TypeField Description
    charConstant "l" (0x6C)
    charConstant "l" (0x6C)
    charConstant "v" (0x76)
    charConstant "m" (0x6D)
    -
    @@ -469,106 +607,125 @@ only provides the module identifier, size of the module block, and the format information. Everything else is contained in other blocks, described in other sections.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeField Description
    unsignedModule Identifier (0x01)
    unsignedSize of the module block in bytes
    uint32_vbrFormat Information
    blockGlobal Type Pool
    blockModule Globals Info
    blockModule Constant Pool
    block*Function Definitions
    blockModule Symbol Table
    TypeField Description
    block
    +
    Module Block Identifier (0x01) and Size
    +
    uint32_vbrFormat Information
    blockGlobal Type Pool
    blockModule Globals Info
    blockModule Constant Pool
    block*Function Definitions
    blockModule Symbol Table
    -
    -

    The format information field is encoded into a - uint32_vbr as shown in the following table.

    +

    The format information field is encoded into a uint32_vbr +as shown in the following table.

    - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeDescription
    bit(0)Target is big endian?
    bit(1)On target pointers are 64-bit?
    bit(2)Target has no endianess?
    bit(3)Target has no pointer size?
    bit(4-31)Bytecode format version
    TypeDescription
    bit(0)Target is big endian?
    bit(1)On target pointers are 64-bit?
    bit(2)Target has no endianess?
    bit(3)Target has no pointer size?
    bit(4-31)Bytecode format version

    Of particular note, the bytecode format number is simply a 28-bit monotonically increase integer that identifies the version of the bytecode -format (which is not directly related to the LLVM release number). The -bytecode versions defined so far are (note that this document only describes -the latest version, 1.3):

    +format (which is not directly related to the LLVM release number). The +bytecode versions defined so far are (note that this document only +describes the latest version, 1.3):

      -
    • #0: LLVM 1.0 & 1.1
    • -
    • #1: LLVM 1.2
    • -
    • #2: LLVM 1.3
    • +
    • #0: LLVM 1.0 & 1.1
    • +
    • #1: LLVM 1.2
    • +
    • #2: LLVM 1.2.5 (not released)
    • +
    • #3: LLVM 1.3
      +
    -

    Note that we plan to eventually expand the target description capabilities -of bytecode files to target triples. +

    Note that we plan to eventually expand the target description +capabilities +of bytecode files to target +triples.

    -

    The global type pool consists of type definitions. Their order of appearance -in the file determines their slot number (0 based). Slot numbers are used to -replace pointers in the intermediate representation. Each slot number uniquely -identifies one entry in a type plane (a collection of values of the same type). -Since all values have types and are associated with the order in which the type -pool is written, the global type pool must be written as the first -block of a module. If it is not, attempts to read the file will fail because -both forward and backward type resolution will not be possible.

    -

    The type pool is simply a list of type definitions, as shown in the table -below.

    +in the file determines their slot number (0 based). Slot numbers are +used to replace pointers in the intermediate representation. Each slot number +uniquely identifies one entry in a type plane (a collection of values of the +same type). Since all values have types and are associated with the order in +which the type pool is written, the global type pool must be written +as the first block of a module. If it is not, attempts to read the file will +fail because both forward and backward type resolution will not be possible.

    +

    The type pool is simply a list of type definitions, as shown in the +table below.

    - - - - - - - - - - - - - + + + + + + + + + + + + + +
    TypeField Description
    unsignedType Pool Identifier (0x15)
    unsignedSize in bytes of the type pool block.
    llist(type)A length list of type definitions.
    TypeField Description
    blockType Pool Identifier (0x06) + Size
    +
    llist(type)A length list of type definitions.
    @@ -577,722 +734,904 @@ below.

    Types in the type pool are defined using a different format for each kind of type, as given in the following sections.

    Primitive Types

    -

    The primitive types encompass the basic integer and floating point types

    +

    The primitive types encompass the basic integer and floating point +types

    - - - - - - - + + + + + + + + + +
    TypeDescription
    uint32_vbrType ID for the primitive types (values 1 to 11) - 1
    TypeDescription
    uint24_vbrType ID for the primitive types (values 1 to +11) 1
    Notes:
      -
    1. The values for the Type IDs for the primitive types are provided by the - definition of the llvm::Type::TypeID enumeration in - include/llvm/Type.h. The enumeration gives the following - mapping:
        -
      1. bool
      2. -
      3. ubyte
      4. -
      5. sbyte
      6. -
      7. ushort
      8. -
      9. short
      10. -
      11. uint
      12. -
      13. int
      14. -
      15. ulong
      16. -
      17. long
      18. -
      19. float
      20. -
      21. double
      22. -
    2. +
    3. The values for the Type IDs for the primitive types are provided +by the definition of the llvm::Type::TypeID enumeration +in include/llvm/Type.h. The enumeration gives the +following mapping: +
        +
      1. bool
      2. +
      3. ubyte
      4. +
      5. sbyte
      6. +
      7. ushort
      8. +
      9. short
      10. +
      11. uint
      12. +
      13. int
      14. +
      15. ulong
      16. +
      17. long
      18. +
      19. float
      20. +
      21. double
      22. +
      +

    Function Types

    - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - + + + + + +
    TypeDescription
    uint32_vbrType ID for function types (13)
    uint32_vbrSlot number of function's return type.
    llist(uint32_vbr)
    TypeDescription
    uint24_vbrType ID for function types (13)
    uint24_vbrSlot number of function's return type.
    llist(uint24_vbr) Slot number of each argument's type.
    uint32_vbr?Value 0 if this is a varargs function, missing otherwise.
    uint32_vbr?Value 0 if this is a varargs function, +missing otherwise.

    Structure Types

    - - - - - - - - - - + + + + + + + + + + + + + +
    TypeDescription
    uint32_vbrType ID for structure types (14)
    zlist(uint32_vbr)Slot number of each of the element's fields.
    TypeDescription
    uint24_vbrType ID for structure types (14)
    zlist(uint24_vbr)Slot number of each of the element's fields.

    Array Types

    - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
    TypeDescription
    uint32_vbrType ID for Array Types (15)
    uint32_vbrSlot number of array's element type.
    uint32_vbrThe number of elements in the array.
    TypeDescription
    uint24_vbrType ID for Array Types (15)
    uint24_vbrSlot number of array's element type.
    uint32_vbrThe number of elements in the array.

    Pointer Types

    - - - - - - - - - - + + + + + + + + + + + + + +
    TypeDescription
    uint32_vbrType ID For Pointer Types (16)
    uint32_vbrSlot number of pointer's element type.
    TypeDescription
    uint24_vbrType ID For Pointer Types (16)
    uint24_vbrSlot number of pointer's element type.

    Opaque Types

    - - - - - - - + + + + + + + + + +
    TypeDescription
    uint32_vbrType ID For Opaque Types (17)
    TypeDescription
    uint24_vbrType ID For Opaque Types (17)
    - +
    -

    The module global info block contains the definitions of all global - variables including their initializers and the declaration of all - functions. The format is shown in the table below:

    - +

    The module global info block contains the definitions of all global +variables including their initializers and the declaration of +all functions. The format is shown in the table below:

    +
    + - - - - - - - + + + + + + - - - - - -
    Type Field Description
    unsignedModule global info identifier (0x14)
    unsignedSize in bytes of the module global info block.
    blockModule global info identifier (0x05) + size
    +
    zlist(globalvar)A zero terminated list of global var definitions - occuring in the module.
    zlist(uint32_vbr)A zero terminated list of function types occuring in - the module.
    + A zero terminated list of global var +definitions occuring in the module. + + + zlist(uint24_vbr) + A zero terminated list of function types +occuring in the module. + + + llist(string)
    + + A length list +of strings that specify the names of the libraries that this module +depends upon.
    + + + + string
    + + The target +triple for the module (blank means no target triple specified, i.e. a +platform independent module).
    + + + +
    -
    -

    Global variables are written using an uint32_vbr - that encodes information about the global variable and a list of the constant - initializers for the global var, if any.

    -

    The table below provides the bit layout of the first - uint32_vbr that describes the global variable.

    - - - - - - - - - - - - - - - - -
    TypeDescription
    bit(0)Is constant?
    bit(1)Has initializer? Note that this bit determines whether - the constant initializer field (described below) follows. -
    bit(2-4)Linkage type: 0=External, 1=Weak, 2=Appending, - 3=Internal, 4=LinkOnce
    bit(5-31)Slot number of type for the global variable.
    -

    The table below provides the format of the constant initializers for the - global variable field, if it has one.

    - +

    Global variables are written using an uint32_vbr +that encodes information about the global variable and a list of the +constant initializers for the global var, if any.

    +

    The table below provides the bit layout of the first uint32_vbr that describes the global variable.

    +
    + - + + + + + + + + + + + + + + + + + + +
    Type Description
    bit(0)Is constant?
    bit(1)Has initializer? Note that this bit +determines whether the constant initializer field (described below) +follows.
    bit(2-4)Linkage type: 0=External, 1=Weak, +2=Appending, 3=Internal, 4=LinkOnce
    bit(5-31)Slot number of type for the global variable.
    +

    The table below provides the format of the constant initializers for +the global variable field, if it has one.

    + + + + + + + - + -
    TypeDescription
    (zlist(uint32_vbr))? - An optional zero-terminated list of slot numbers of - the global variable's constant initializer.An optional zero-terminated list of slot +numbers of the global variable's constant initializer.
    + +
    -
    -

    A constant pool defines as set of constant values. There are actually two - types of constant pool blocks: one for modules and one for functions. For - modules, the block begins with the constant strings encountered anywhere in - the module. For functions, the block begins with types only encountered in - the function. In both cases the header is identical. The tables that follow, - show the header, module constant pool preamble, function constant pool - preamble, and the part common to both function and module constant pools.

    -

    Common Block Header

    - +

    A constant pool defines as set of constant values. There are +actually two types of constant pool blocks: one for modules and one for +functions. For modules, the block begins with the constant strings +encountered anywhere in the module. For functions, the block begins +with types only encountered in the function. In both cases the header +is identical. The tables that follow, show the header, module constant +pool preamble, function constant pool preamble, and the part common to +both function and module constant pools.

    +

    Common Block Header

    +
    + - - - - - - -
    Type Field Description
    unsignedConstant pool identifier (0x12)
    unsignedSize in bytes of the constant pool block.
    -

    Module Constant Pool Preamble (constant strings)

    - + + + + + +
    blockConstant pool identifier (0x03) + size
    +
    +

    Module Constant Pool Preamble (constant strings)

    + + - + + - + + - - - - + -
    Type Field Description
    uint32_vbr The number of constant strings that follow.
    uint32_vbrZero. This identifies the following "plane" as - containing the constant strings. This is needed to identify it - uniquely from other constant planes that follow. -
    uint32_vbr+Slot number of the constant string's type. Note - that the constant string's type implicitly defines the length of - the string. - Zero. This identifies the following "plane" +as containing the constant strings. This is needed to identify it +uniquely from other constant planes that follow.
    -

    Function Constant Pool Preamble (function types)

    -

    The structure of the types for functions is identical to the - Global Type Pool. Please refer to that section - for the details. -

    Common Part (other constants)

    - + + + + + +
    uint24_vbr+Slot number of the constant string's type. +Note that the constant string's type implicitly defines the length of +the string.
    +

    Function Constant Pool Preamble (function types)

    +

    The structure of the types for functions is identical to the Global Type Pool. Please refer to that section +for the details.

    +

    Common Part (other constants)

    + + - + + - - + + + - + + -
    Type Field Description
    uint32_vbr Number of entries in this type plane.
    uint32_vbr
    uint24_vbr Type slot number of this plane.
    constant+ The definition of a constant (see below).
    + +
    -

    Constants come in many shapes and flavors. The sections that followe define - the format for each of them. All constants start with a - uint32_vbr encoded integer that provides the number - of operands for the constant. For primitive, structure, and array constants, - this will always be zero since those types of constants have no operands. - In this case, we have the following field definitions:

    -
      -
    • Bool. This is written as an uint32_vbr - of value 1U or 0U.
    • -
    • Signed Integers (sbyte,short,int,long). These are written as - an int64_vbr with the corresponding value.
    • -
    • Unsigned Integers (ubyte,ushort,uint,ulong). These are written - as an uint64_vbr with the corresponding value. -
    • -
    • Floating Point. Both the float and double types are written - literally in binary format.
    • -
    • Arrays. Arrays are written simply as a list of - uint32_vbr encoded slot numbers to the constant - element values.
    • -
    • Structures. Structures are written simply as a list of - uint32_vbr encoded slot numbers to the constant - field values of the structure.
    • -
    -

    When the number of operands to the constant is non-zero, we have a - constant expression and its field format is provided in the table below.

    - +

    Constants come in many shapes and flavors. The sections that followe +define the format for each of them. All constants start with a uint32_vbr encoded integer that provides the +number of operands for the constant. For primitive, structure, and +array constants, this will always be zero since those types of +constants have no operands. In this case, we have the following field +definitions:

    +
      +
    • Bool. This is written as an uint32_vbr +of value 1U or 0U.
    • +
    • Signed Integers (sbyte,short,int,long). These are written +as an int64_vbr with the corresponding value.
    • +
    • Unsigned Integers (ubyte,ushort,uint,ulong). These are +written as an uint64_vbr with the +corresponding value.
    • +
    • Floating Point. Both the float and double types are +written literally in binary format.
    • +
    • Arrays. Arrays are written simply as a list of uint32_vbr encoded slot numbers to the constant +element values.
    • +
    • Structures. Structures are written simply as a list of uint32_vbr encoded slot numbers to the constant +field values of the structure.
    • +
    +

    When the number of operands to the constant is non-zero, we have a +constant expression and its field format is provided in the table below.

    +
    + - - - - + + - - + + + - + + + + + -
    Type Field Description
    uint32_vbrOp code of the instruction for the constant - expression.
    uint32_vbrThe slot number of the constant value for an - operand.1
    Op code of the instruction for the constant +expression.
    uint32_vbrThe slot number for the type of the constant value - for an operand.1The slot number of the constant value for an +operand.1
    uint24_vbrThe slot number for the type of the constant +value for an operand.1
    - Notes:
      -
    1. Both these fields are repeatable but only in pairs.
    2. -
    + + +Notes: +
      +
    1. Both these fields are repeatable but only in pairs.
    2. +
    -

    Function definitions contain the linkage, constant pool or compaction - table, instruction list, and symbol table for a function. The following table - shows the structure of a function definition.

    - +

    Function definitions contain the linkage, constant pool or +compaction table, instruction list, and symbol table for a function. +The following table shows the structure of a function definition.

    +
    + - - - - - - - + + + + + + - - - - - - - - - - - + + + + + + + + + + + - - -
    Type Field Description
    unsignedFunction definition block identifier (0x11)
    unsignedSize in bytes of the function definition block.
    block
    +
    Function definition block identifier (0x02) + +size
    +
    uint32_vbrThe linkage type of the function: 0=External, 1=Weak, - 2=Appending, 3=Internal, 4=LinkOnce1
    blockThe constant pool block - for this function.2
    blockThe compaction table - block for the function.2
    blockThe instruction list - for the function.
    The linkage type of the function: 0=External, +1=Weak, 2=Appending, 3=Internal, 4=LinkOnce1
    blockThe constant pool +block for this function.2
    blockThe compaction +table block for the function.2
    blockThe function's symbol table - containing only those symbols pertinent to the function (mostly - block labels).
    - Notes:
      -
    1. Note that if the linkage type is "External" then none of the other - fields will be present as the function is defined elsewhere.
    2. -
    3. Note that only one of the constant pool or compaction table will be - written. Compaction tables are only written if they will actually save - bytecode space. If not, then a regular constant pool is written.
    4. -
    + The instruction +list for the function. + + + block + The function's symbol +table containing only those symbols pertinent to the function +(mostly block labels). + + + +Notes: +
      +
    1. Note that if the linkage type is "External" then none of the +other fields will be present as the function is defined elsewhere.
    2. +
    3. Note that only one of the constant pool or compaction table will +be written. Compaction tables are only written if they will actually +save bytecode space. If not, then a regular constant pool is written.
    4. +
    - +
    -

    Compaction tables are part of a function definition. They are merely a - device for reducing the size of bytecode files. The size of a bytecode - file is dependent on the value of the slot numbers used because - larger values use more bytes in the variable bit rate encoding scheme. - Furthermore, the compressed instruction format reserves only six bits for - the type of the instruction. In large modules, declaring hundreds or thousands - of types, the values of the slot numbers can be quite large. However, - functions may use only a small fraction of the global types. In such cases - a compaction table is created that maps the global type and value slot - numbers to smaller values used by a function. Functions will contain either - a function-specific constant pool or a compaction table but not - both. Compaction tables have the format shown in the table below.

    - +

    Compaction tables are part of a function definition. They are merely +a device for reducing the size of bytecode files. The size of a +bytecode file is dependent on the value of the slot numbers +used because larger values use more bytes in the variable bit rate +encoding scheme. Furthermore, the compressed instruction format +reserves only six bits for the type of the instruction. In large +modules, declaring hundreds or thousands of types, the values of the +slot numbers can be quite large. However, functions may use only a +small fraction of the global types. In such cases a compaction table is +created that maps the global type and value slot numbers to smaller +values used by a function. Functions will contain either a +function-specific constant pool or a compaction table but not +both. Compaction tables have the format shown in the table below.

    +
    + - + + - - - - + + + + + + - - + + + - + -
    Type Field Description
    uint32_vbr The number of types that follow
    uint32_vbr+The slot number in the global type plane of the - type that will be referenced in the function with the index of - this entry in the compaction table.
    uint24_vbr+The slot number in the global type plane of +the type that will be referenced in the function with the index of this +entry in the compaction table.
    type_lenAn encoding of the type and number of values that - follow. This field's encoding varies depending on the size of - the type plane. See Type and Length for - further details.
    An encoding of the type and number of values +that follow. This field's encoding varies depending on the size of the +type plane. See Type and Length for further +details.
    uint32_vbr+The slot number in the globals of the value that - will be referenced in the function with the index of this entry in - the compaction tableThe slot number in the globals of the value +that will be referenced in the function with the index of this entry in +the compaction table
    + +
    -
    -

    The type and length of a compaction table type plane is encoded differently - depending on the length of the plane. For planes of length 1 or 2, the length - is encoded into bits 0 and 1 of a uint32_vbr and the - type is encoded into bits 2-31. Because type numbers are often small, this - often saves an extra byte per plane. If the length of the plane is greater - than 2 then the encoding uses a uint32_vbr for each - of the length and type, in that order.

    +

    The type and length of a compaction table type plane is encoded +differently depending on the length of the plane. For planes of length +1 or 2, the length is encoded into bits 0 and 1 of a uint32_vbr and the type is encoded into bits +2-31. Because type numbers are often small, this often saves an extra +byte per plane. If the length of the plane is greater than 2 then the +encoding uses a uint32_vbr for each of the +length and type, in that order.

    - - +
    -

    The instructions in a function are written as a simple list. Basic blocks - are inferred by the terminating instruction types. The format of the block - is given in the following table.

    - +

    The instructions in a function are written as a simple list. Basic +blocks are inferred by the terminating instruction types. The format of +the block is given in the following table.

    +
    + - - - - - - - + + + + + + - + -
    Type Field Description
    unsignedInstruction list identifier (0x33).
    unsignedSize in bytes of the instruction list.
    block
    +
    Instruction list identifier (0x07) + size
    +
    instruction+An instruction. Instructions have a variety of formats. - See Instructions for details.An instruction. Instructions have a variety +of formats. See Instructions for details.
    + +
    -
    -

    For brevity, instructions are written in one of four formats, depending on - the number of operands to the instruction. Each instruction begins with a - uint32_vbr that encodes the type of the instruction - as well as other things. The tables that follow describe the format of this - first word of each instruction.

    -

    Instruction Format 0

    -

    This format is used for a few instructions that can't easily be optimized - because they have large numbers of operands (e.g. PHI Node or getelementptr). - Each of the opcode, type, and operand fields is as successive fields.

    - +

    For brevity, instructions are written in one of four formats, +depending on the number of operands to the instruction. Each +instruction begins with a uint32_vbr that +encodes the type of the instruction as well as other things. The tables +that follow describe the format of this first word of each instruction.

    +

    Instruction Format 0

    +

    This format is used for a few instructions that can't easily be +optimized because they have large numbers of operands (e.g. PHI Node or +getelementptr). Each of the opcode, type, and operand fields is as +successive fields.

    +
    + - - - - + + - - + + + + + + + - + + - - -
    Type Field Description
    uint32_vbrSpecifies the opcode of the instruction. Note that for - compatibility with the other instruction formats, the opcode is shifted - left by 2 bits. Bits 0 and 1 must have value zero for this format.
    uint32_vbrProvides the slot number of the result type of the - instruction
    Specifies the opcode of the instruction. Note +that for compatibility with the other instruction formats, the opcode +is shifted left by 2 bits. Bits 0 and 1 must have value zero for this +format.
    uint24_vbrProvides the slot number of the result type +of the instruction
    uint32_vbr The number of operands that follow.
    uint32_vbr+The slot number of the value(s) for the operand(s). - 1
    - Notes:
      -
    1. Note that if the instruction is a getelementptr and the type of the - operand is a sequential type (array or pointer) then the slot number is - shifted up two bits and the low order bits will encode the type of index - used, as follows: 0=uint, 1=int, 2=ulong, 3=long.
    2. -
    -

    Instruction Format 1

    -

    This format encodes the opcode, type and a single operand into a single - uint32_vbr as follows:

    - + + + +
    The slot number of the value(s) for the +operand(s). 1
    +Notes: +
      +
    1. Note that if the instruction is a getelementptr and the type of +the operand is a sequential type (array or pointer) then the slot +number is shifted up two bits and the low order bits will encode the +type of index used, as follows: 0=uint, 1=int, 2=ulong, 3=long.
    2. +
    +

    Instruction Format 1

    +

    This format encodes the opcode, type and a single operand into a +single uint32_vbr as follows:

    + + - - - - - - - - - - - - - - -
    Bits Type Field Description
    0-1constant "1"These two bits must be the value 1 which identifies - this as an instruction of format 1.
    2-7opcodeSpecifies the opcode of the instruction. Note that - the maximum opcode value is 63.
    8-19unsignedSpecifies the slot number of the type for this - instruction. Maximum slot number is 212-1=4095.
    20-31unsignedSpecifies the slot number of the value for the - first operand. Maximum slot number is 212-1=4095. Note - that the value 212-1 denotes zero operands.
    -

    Instruction Format 2

    -

    This format encodes the opcode, type and two operands into a single - uint32_vbr as follows:

    - + + + + + + + + + + + + + + + + + + + + + + +
    0-1constant "1"These two bits must be the value 1 which +identifies this as an instruction of format 1.
    2-7opcodeSpecifies the opcode of the instruction. Note +that the maximum opcode value is 63.
    8-19unsignedSpecifies the slot number of the type for +this instruction. Maximum slot number is 212-1=4095.
    20-31unsignedSpecifies the slot number of the value for +the first operand. Maximum slot number is 212-1=4095. Note +that the value 212-1 denotes zero operands.
    +

    Instruction Format 2

    +

    This format encodes the opcode, type and two operands into a single uint32_vbr as follows:

    + + - - - - - - - - - - - - - - - - - -
    Bits Type Field Description
    0-1constant "2"These two bits must be the value 2 which identifies - this as an instruction of format 2.
    2-7opcodeSpecifies the opcode of the instruction. Note that - the maximum opcode value is 63.
    8-15unsignedSpecifies the slot number of the type for this - instruction. Maximum slot number is 28-1=255.
    16-23unsignedSpecifies the slot number of the value for the - first operand. Maximum slot number is 28-1=255.
    24-31unsignedSpecifies the slot number of the value for the - second operand. Maximum slot number is 28-1=255.
    -

    Instruction Format 3

    -

    This format encodes the opcode, type and three operands into a single - uint32_vbr as follows:

    - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    0-1constant "2"These two bits must be the value 2 which +identifies this as an instruction of format 2.
    2-7opcodeSpecifies the opcode of the instruction. Note +that the maximum opcode value is 63.
    8-15unsignedSpecifies the slot number of the type for +this instruction. Maximum slot number is 28-1=255.
    16-23unsignedSpecifies the slot number of the value for +the first operand. Maximum slot number is 28-1=255.
    24-31unsignedSpecifies the slot number of the value for +the second operand. Maximum slot number is 28-1=255.
    +

    Instruction Format 3

    +

    This format encodes the opcode, type and three operands into a +single uint32_vbr as follows:

    + + - - - - - - - - - - - - - - - - - - - - -
    Bits Type Field Description
    0-1constant "3"These two bits must be the value 3 which identifies - this as an instruction of format 3.
    2-7opcodeSpecifies the opcode of the instruction. Note that - the maximum opcode value is 63.
    8-13unsignedSpecifies the slot number of the type for this - instruction. Maximum slot number is 26-1=63.
    14-19unsignedSpecifies the slot number of the value for the - first operand. Maximum slot number is 26-1=63.
    20-25unsignedSpecifies the slot number of the value for the - second operand. Maximum slot number is 26-1=63.
    26-31unsignedSpecifies the slot number of the value for the - third operand. Maximum slot number is 26-1=63.
    + + + 0-1 + constant "3" + These two bits must be the value 3 which +identifies this as an instruction of format 3. + + + 2-7 + opcode + Specifies the opcode of the instruction. Note +that the maximum opcode value is 63. + + + 8-13 + unsigned + Specifies the slot number of the type for +this instruction. Maximum slot number is 26-1=63. + + + 14-19 + unsigned + Specifies the slot number of the value for +the first operand. Maximum slot number is 26-1=63. + + + 20-25 + unsigned + Specifies the slot number of the value for +the second operand. Maximum slot number is 26-1=63. + + + 26-31 + unsigned + Specifies the slot number of the value for +the third operand. Maximum slot number is 26-1=63. + + +
    -

    A symbol table can be put out in conjunction with a module or a function. A symbol table is a list of type planes. Each type plane starts with the number -of entries in the plane and the type plane's slot number (so the type can be -looked up in the global type pool). For each entry in a type plane, the slot -number of the value and the name associated with that value are written. The -format is given in the table below.

    +of entries in the plane and the type plane's slot number (so the type +can be looked up in the global type pool). For each entry in a type +plane, the slot number of the value and the name associated with that +value are written. The format is given in the table below.

    - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
    TypeField Description
    unsignedSymbol Table Identifier (0x13)
    unsignedSize in bytes of the symbol table block.
    uint32_vbrNumber of entries in type plane
    symtab_entry*Provides the slot number of the type and its name.
    symtab_plane*A type plane containing value slot number and name - for all values of the same type.
    TypeField Description
    block
    +
    Symbol Table Identifier (0x04)
    uint32_vbrNumber of entries in type plane
    symtab_entry*Provides the slot number of the type and its +name.
    symtab_plane*A type plane containing value slot number and +name for all values of the same type.
    - -
    Symbol Table Plane +
    -

    A symbol table plane provides the symbol table entries for all values of - a common type. The encoding is given in the following table:

    +

    A symbol table plane provides the symbol table entries for all +values of a common type. The encoding is given in the following table:

    - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
    TypeField Description
    uint32_vbrNumber of entries in this plane.
    uint32_vbrSlot number of type for this plane.
    symtab_entry+The symbol table entries for this plane.
    TypeField Description
    uint32_vbrNumber of entries in this plane.
    uint32_vbrSlot number of type for this plane.
    symtab_entry+The symbol table entries for this plane.
    - -
    Symbol Table Entry +
    -

    A symbol table entry provides the assocation between a type or value's - slot number and the name given to that type or value. The format is given - in the following table:

    +

    A symbol table entry provides the assocation between a type or +value's slot number and the name given to that type or value. The +format is given in the following table:

    - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
    TypeField Description
    uint32_vbrSlot number of the type or value being given a name. -
    uint32_vbrLength of the character array that follows.
    char+The characters of the name.
    TypeField Description
    uint24_vbrSlot number of the type or value being given +a name.
    uint32_vbrLength of the character array that follows.
    char+The characters of the name.
    - - +
    -

    This section describes the differences in the Bytecode Format across LLVM -versions. The versions are listed in reverse order because it assumes the -current version is as documented in the previous sections. Each section here +

    This section describes the differences in the Bytecode Format across +LLVM +versions. The versions are listed in reverse order because it assumes +the current version is as documented in the previous sections. Each +section here describes the differences between that version and the one that follows.

    - - +
    Type Derives From Value
    -

    In version 1.2, the Type class in the LLVM IR derives from the Value class. - This is not the case in version 1.3. Consequently, in version 1.2 the notion - of a "Type Type" was used to write out values that were Types. The types - always occuped plane 12 (corresponding to the TypeTyID) of any type planed - set of values. In 1.3 this representation is not convenient because the - TypeTyID (12) is not present and its value is now used for LabelTyID. - Consequently, the data structures written that involve types do so by writing - all the types first and then each of the value planes according to those - types. In version 1.2, the types would have been written intermingled with - the values.

    +

    In version 1.2, the Type class in the LLVM IR derives from the Value +class. This is not the case in version 1.3. Consequently, in version +1.2 the notion of a "Type Type" was used to write out values that were +Types. The types always occuped plane 12 (corresponding to the +TypeTyID) of any type planed set of values. In 1.3 this representation +is not convenient because the TypeTyID (12) is not present and its +value is now used for LabelTyID. Consequently, the data structures +written that involve types do so by writing all the types first and +then each of the value planes according to those types. In version 1.2, +the types would have been written intermingled with the values.

    - -
    Restricted getelementptr Types
    +
    Restricted getelementptr Types
    -

    In version 1.2, the getelementptr instruction required a ubyte type index - for accessing a structure field and a long type index for accessing an array - element. Consequently, it was only possible to access structures of 255 or - fewer elements. Starting in version 1.3, this restriction was lifted. - Structures must now be indexed with uint constants. Arrays may now be - indexed with int, uint, long, or ulong typed values. - The consequence of this was that the bytecode format had to - change in order to accommodate the larger range of structure indices.

    +

    In version 1.2, the getelementptr instruction required a ubyte type +index for accessing a structure field and a long type index for +accessing an array element. Consequently, it was only possible to +access structures of 255 or fewer elements. Starting in version 1.3, +this restriction was lifted. Structures must now be indexed with uint +constants. Arrays may now be indexed with int, uint, long, or ulong +typed values. The consequence of this was that the bytecode format had +to change in order to accommodate the larger range of structure indices.

    - - +
    Short Block Headers
    +
    +

    In version 1.2, block headers were always 8 bytes being comprised of +both an unsigned integer type and an unsigned integer size. For very +small modules, these block headers turn out to be a large fraction of +the total bytecode file size. In an attempt to make these small files +smaller, the type and size information was encoded into a single +unsigned integer (4 bytes) comprised of 5 bits for the block type +(maximum 31 block types) and 27 bits for the block size (max +~134MBytes). These limits seemed sufficient for any blocks or sizes +forseen in the future. Note that the module block, which encloses all +the other blocks is still written as 8 bytes since bytecode files +larger than 134MBytes might be possible.

    +
    + +
    Dependent Libraries and Target Triples
    +
    +

    In version 1.2, the bytecode format does not store module's target +triple or dependent. These fields have been added to the end of the module global info block. The purpose of these +fields is to allow a front end compiler to specifiy that the generated +module is specific to a particular target triple (operating +system/manufacturer/processor) which makes it non-portable; and to +allow front end compilers to specify the list of libraries that the +module depends on for successful linking.

    +
    + +
    Types Restricted to 24-bits
    +
    +

    In version 1.2, type slot identifiers were written as 32-bit VBR +quantities. In 1.3 this has been reduced to 24-bits in order to ensure +that it is not possible to overflow the type field of a global variable +definition. 24-bits for type slot numbers is deemed sufficient for any +practical use of LLVM.

    +
    + + +
    Explicit Primitive Zeros
    -

    In version 1.1, the zero value for primitives was explicitly encoded into - the bytecode format. Since these zero values are constant values in the - LLVM IR and never change, there is no reason to explicitly encode them. This - explicit encoding was removed in version 1.2.

    +

    In version 1.1, the zero value for primitives was explicitly encoded +into the bytecode format. Since these zero values are constant values +in the LLVM IR and never change, there is no reason to explicitly +encode them. This explicit encoding was removed in version 1.2.

    -
    Inconsistent Module Global Info
    -

    In version 1.1, the Module Global Info block was not aligned causing the - next block to be read in on an unaligned boundary. This problem was corrected - in version 1.2.

    +

    In version 1.1, the Module Global Info block was not aligned causing +the next block to be read in on an unaligned boundary. This problem was +corrected in version 1.2.
    +
    +

    - - +

    None. Version 1.0 and 1.1 bytecode formats are identical.

    -
    -
    - Valid CSS! - Valid HTML 4.01! - - Reid Spencer and - Chris Lattner
    - The LLVM Compiler Infrastructure
    - Last modified: $Date$ +
    Valid CSS! +Valid HTML 4.01! +Reid Spencer and Chris Lattner
    +The LLVM Compiler Infrastructure
    +Last modified: $Date$
    - - + +