data |
An arbitrarily long segment of data to which no
@@ -419,7 +419,7 @@ 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.
-
+
Type |
Field Description |
@@ -447,7 +447,7 @@ the file. The table below shows the structure of the module block. Note that it
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.
-
+
Type |
Field Description |
@@ -535,28 +535,29 @@ 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.
-
+
Type |
Field Description |
unsigned |
- Type Pool Identifier (0x13) |
+ Type Pool Identifier (0x15) |
unsigned |
- Size in bytes of the symbol table block. |
+ Size in bytes of the type pool block. |
uint32_vbr |
- Number of entries in type plane |
+ Number of type definitions that follow in the next
+ field. |
type |
Each of the type definitions (see below)1 |
-
-
- 1Repeated field.
- |
+Notes:
+
+ - Repeated field.
+
@@ -572,13 +573,13 @@ basic type of type as given in the following sections.
uint32_vbr |
Type ID For The Primitive (1-11)1 |
-
-
- 1See the definition of Type::TypeID in Type.h for the numeric
- equivalents of the primitive type ids.
- |
+Notes:
+
+ - See the definition of Type::TypeID in Type.h for the numeric equivalents
+ of the primitive type ids.
+
Function Types
@@ -599,13 +600,13 @@ basic type of type as given in the following sections.
uint32_vbr |
Value 0 if this is a varargs function.2 |
-
-
- 1Repeated field.
- 2Optional field.
- |
+Notes:
+
+ - Repeated field.
+ - Optional field.
+
Structure Types
@@ -620,12 +621,12 @@ basic type of type as given in the following sections.
uint32_vbr |
Null Terminator (VoidTy type id) |
-
-
- 1Repeated field.
- |
+Notes:
+
+ - Repeatable field.
+
Array Types
@@ -669,12 +670,200 @@ basic type of type as given in the following sections.
- To be determined.
+ 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 |
+
+ unsigned |
+ Module global info identifier (0x14) |
+
+ unsigned |
+ Size in bytes of the module global info block. |
+
+ globalvar |
+ Definition of the global variable (see below).
+ 1
+ |
+
+ uint32_vbr |
+ Slot number of the global variable's constant
+ initializer.1,2
+ |
+
+ uint32_vbr |
+ Zero. This terminates the list of global variables.
+ |
+
+ uint32_vbr |
+ Type slot number of a function defined in this
+ bytecode file.3
+ |
+
+ uint32_vbr |
+ Zero. This terminates the list of function
+ declarations.
+ |
+
+ Notes:
+ - Both these fields are repeatable but in pairs.
+ - Optional field.
+ - Repeatable field.
+
+
+
+
+
+ Global variables are written using a single
+ uint32_vbr that encodes information about the global
+ variable. The table below provides the bit layout of the value written for
+ each global variable.
+
+
+ Bit(s) |
+ Type |
+ Description |
+
+ 0 | bit |
+ Is constant? |
+
+ 1 | bit |
+ Has initializer?1 |
+
+ 2-4 | enumeration |
+ Linkage type: 0=External, 1=Weak, 2=Appending,
+ 3=Internal, 4=LinkOnce |
+
+ 5-31 | type slot |
+ Slot number of type for the global variable. |
+
+
+ Notes:
+
+ - This bit determines whether the constant initializer field follows
+ immediately after this field
+
+
+
- To be determined.
+ 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 the 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 |
+
+ unsigned |
+ Constant pool identifier (0x12) |
+
+
+ Module Constant Pool Preamble (constant strings)
+
+
+ Type |
+ Field Description |
+
+ uint32_vbr |
+ The number of constant strings that follow. |
+
+ uint32_vbr |
+ Zero. This identifies the following "plane" as
+ containing the constant strings.
+ |
+
+ string |
+ Slot number of the constant string's type which
+ includes the length of the string.1
+ |
+
+
+ Notes:
+
+ - Repeated field.
+
+ 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 |
+ 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.
+
+
+ Type |
+ Field Description |
+
+ uint32_vbr |
+ Op code of the instruction for the constant
+ expression. |
+
+ uint32_vbr |
+ The slot number of the constant value for an
+ operand.1 |
+
+ uint32_vbr |
+ The slot number for the type of the constant value
+ for an operand.1 |
+
+
+ Notes:
+ - Both these fields are repeatable but only in pairs.
+
@@ -684,8 +873,59 @@ basic type of type as given in the following sections.
- To be determined.
+ 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 compresses 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. 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.1 |
+
+ type_len |
+ An encoding of the type and number of values that
+ follow.2 |
+
+ 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 table1 |
+
+
+ Notes:
+ - Repeated field.
+ - This field's encoding varies depending on the size of the type plane.
+ See Type and Length for further details.
+
+
+
+
+
+ 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.
+
+
@@ -700,7 +940,7 @@ 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.
-
+
Byte(s) |
Bit(s) |
@@ -726,11 +966,13 @@ format is given in the table below.
variable1,2 | - | No | string |
Name of the value in the symbol table. |
-
- 1Maximum length shown,
- may be smaller 2Repeated field.
|
+Notes:
+
+ - Maximum length shown, may be smaller
+ - Repeated field.
+
|