From 2cc361555bc4f9da77eea67e9aa0728c94164b13 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Mon, 5 Jul 2004 19:04:27 +0000 Subject: [PATCH] Added sections for Constant Pool, Module Global Info, and Compaction Tables. Two more sections to go. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14631 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/BytecodeFormat.html | 318 ++++++++++++++++++++++++++++++++++----- 1 file changed, 280 insertions(+), 38 deletions(-) diff --git a/docs/BytecodeFormat.html b/docs/BytecodeFormat.html index 0ed48e1db6e..d9657750cea 100644 --- a/docs/BytecodeFormat.html +++ b/docs/BytecodeFormat.html @@ -5,11 +5,11 @@ LLVM Bytecode File Format @@ -161,7 +161,7 @@ also contributes to the value. For the final byte (byte & 0x80) is false 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:

- +
@@ -222,9 +222,9 @@ variable bit rate encoding as described above.

- + - -
Byte # Significant Bits A single bit within some larger integer field.
stringA uint_vbr indicating the length of the character string - immediately followed by the characters of the string. There is no - terminating null byte in the string.A uint_vbr indicating the type of the character string + which also includes its length, immediately followed by the characters of + the string. There is no terminating null byte in the string.
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. - +
@@ -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
+
- + - + - + - -
Type Field Description
unsignedType Pool Identifier (0x13)Type Pool Identifier (0x15)
unsignedSize in bytes of the symbol table block.Size in bytes of the type pool block.
uint32_vbrNumber of entries in type planeNumber of type definitions that follow in the next + field.
type Each of the type definitions (see below)1
- 1Repeated field.
-
+Notes: +
    +
  1. Repeated field.
  2. +
@@ -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: +
    +
  1. See the definition of Type::TypeID in Type.h for the numeric equivalents + of the primitive type ids.
  2. +

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: +
    +
  1. Repeated field.
  2. +
  3. Optional field.
  4. +

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: +
    +
  1. Repeatable field.
  2. +

Array Types

@@ -669,12 +670,200 @@ basic type of type as given in the following sections.

Module Global Info
-

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

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
TypeField Description
unsignedModule global info identifier (0x14)
unsignedSize in bytes of the module global info block.
globalvarDefinition of the global variable (see below). + 1 +
uint32_vbrSlot number of the global variable's constant + initializer.1,2 +
uint32_vbrZero. This terminates the list of global variables. +
uint32_vbrType slot number of a function defined in this + bytecode file.3 +
uint32_vbrZero. This terminates the list of function + declarations. +
+ Notes:
    +
  1. Both these fields are repeatable but in pairs.
  2. +
  3. Optional field.
  4. +
  5. Repeatable field.
  6. +
+ + +
Global Variable 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)TypeDescription
0bitIs constant?
1bitHas initializer?1
2-4enumerationLinkage type: 0=External, 1=Weak, 2=Appending, + 3=Internal, 4=LinkOnce
5-31type slotSlot number of type for the global variable.
+ Notes: +
    +
  1. This bit determines whether the constant initializer field follows + immediately after this field
  2. +
+
+
Constant Pool
-

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

+ + + + + + + + +
TypeField Description
unsignedConstant pool identifier (0x12)
+

Module Constant Pool Preamble (constant strings)

+ + + + + + + + + + + + + + +
TypeField Description
uint32_vbrThe number of constant strings that follow.
uint32_vbrZero. This identifies the following "plane" as + containing the constant strings. +
stringSlot number of the constant string's type which + includes the length of the string.1 +
+ Notes: +
    +
  1. Repeated field.
  2. +
+

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)

+ + + + + + + + + + + + + + +
TypeField Description
uint32_vbrNumber of entries in this type plane.
uint32_vbrType slot number of this plane.
constantThe definition of a constant (see below).
+
+ +
Constant Field
+
+

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:

+ +

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.

+ + + + + + + + + + + + + + +
TypeField Description
uint32_vbrOp code of the instruction for the constant + expression.
uint32_vbrThe slot number of the constant value for an + operand.1
uint32_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. +
Function Definition
@@ -684,8 +873,59 @@ basic type of type as given in the following sections.

Compaction Table
-

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.

+ + + + + + + + + + + + + + + + + +
TypeField Description
uint32_vbrThe number of types that follow
uint32_vbrThe 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_lenAn encoding of the type and number of values that + follow.2
uint32_vbrThe 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:
    +
  1. Repeated field.
  2. +
  3. This field's encoding varies depending on the size of the type plane. + See Type and Length for further details. +
+ + +
Type and Length
+
+

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.

+
+
Instruction List
@@ -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.

- +
@@ -726,11 +966,13 @@ format is given in the table below.

- -
Byte(s) Bit(s) variable1,2-Nostring Name of the value in the symbol table.
1Maximum length shown, - may be smaller
2Repeated field.
+Notes: +
    +
  1. Maximum length shown, may be smaller
  2. +
  3. Repeated field.
  4. +
Version Differences