From: Reid Spencer
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.
-In summary then, a slot number can be though of as just a vbr encoded index +
In summary then, a slot number can be thought of as just a vbr encoded index into a list of Type* or Value*. To keep slot numbers low, Value* are indexed by two slot numbers: the "type plane index" (type slot) and the "value index" (value slot).
@@ -500,7 +491,7 @@ except function arguments, global values and constant strings.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, instruction list, +and symbol table for a function. The following table shows the structure of +a function definition.
block | The constant pool block for this function.2 | -
block | -The compaction -table block for the function.2 |
block | @@ -1442,9 +1416,6 @@ Notes:|
bit(19-31) | -Currently unassigned. |
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 values 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 | -
uint24_vbr+ | -The type slot number in the global types of -the type that will be referenced in the function with the index of this -entry in the compaction table. | -
type_len | -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 value slot number in the global values -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.
-