The TYPE_BLOCK_NEW block (17) holds the module’s type table. A module has one such
block, and every other record that names a type uses a number from it. This page gives
each record’s operands as the reader takes them (BitcodeReader::parseTypeTableBody,
lines 2647–2960) and as the writer emits them (writeTypeTable, lines
1175–1351); the codes themselves are on
module blocks.
Numbering and forward references
- Every record that defines a type takes the next type ID, starting at 0. NUMENTRY and STRUCT_NAME define no type.
- NUMENTRY [count] comes first and sizes the table. An empty record is
Invalid numentry record. At the end of the block the number of defining records must equal the count, or the reader reportsMalformed block. More defining records than the count:Invalid TYPE table. - A record may name a type ID that is defined later, but only a named structure
may be referred to before its record. An earlier reference to a slot makes a
placeholder structure; the slot’s own record must then be STRUCT_NAMED or OPAQUE
(which fill the placeholder in). Any other record landing on that slot gives
Invalid TYPE table: Only named structs can be forward referenced. Because of this, a record that names an ID at or beyond the table size is an invalid type for that record. - A second TYPE block is
Invalid multiple blocks. A record code the reader does not know isInvalid value, unlike most blocks, where unknown records are skipped. A sub-block or stream error isMalformed block. - The writer sizes its abbreviations by the number of bits needed for a type index and writes NUMENTRY, then every type in table order.
Records
“Type” in an operand column is a type ID. Operand counts are those the reader requires; fewer gives the message in the last column (all messages are plain errors that end the read).
| Code | Record | Operands | Type made, and the reader’s checks |
|---|---|---|---|
1 | NUMENTRY | [count] | No type. See above. |
2 | VOID | — | void |
3 | FLOAT | — | float (IEEE single) |
4 | DOUBLE | — | double |
5 | LABEL | — | label |
6 | OPAQUE | [ispacked] | An opaque named structure, named by a STRUCT_NAME just before it. Exactly one operand, or Invalid opaque type record. The writer writes the packed flag (0). |
7 | INTEGER | [width] | iwidth. No operand: Invalid integer record; a width outside the range LLVM allows: Bitwidth for integer type out of range. |
8 | POINTER | [pointee type] or [pointee type, address space] | Old typed pointer. The reader makes an opaque ptr in that address space (0 if no second operand) and remembers the pointee type to upgrade old records. No operand, an unknown ID or an invalid element type: Invalid pointer record / Invalid type. |
9 | FUNCTION_OLD | [vararg, attrid, retty, paramty…] | Old function type. At least 3 operands (Invalid function record); the attribute ID is read past and not used; an unknown return or parameter type is Invalid type. |
10 | HALF | — | half |
11 | ARRAY | [numelts, eltty] | [numelts x eltty]. Fewer than 2 operands: Invalid array type record; an element type an array cannot hold: Invalid type. |
12 | VECTOR | [numelts, eltty] or [numelts, eltty, scalable] | <numelts x eltty>, or <vscale x numelts x eltty> when the third operand is non-zero. Fewer than 2: Invalid vector type record; numelts 0: Invalid vector length; an element type that is not valid in a vector: Invalid type. The writer adds the third operand (true) only for a scalable vector. |
13 | X86_FP80 | — | x86_fp80 |
14 | FP128 | — | fp128 (IEEE quad) |
15 | PPC_FP128 | — | ppc_fp128 (pair of doubles) |
16 | METADATA | — | metadata |
17 | X86_MMX | — | Deprecated. The reader decodes it as <1 x i64> (a vector of one 64-bit integer; the x86_mmx type no longer exists). The viewer does the same: it lists the type as <1 x i64> and notes that the file stores type code X86_MMX. The sample newrec-mmx.bc holds one; llvm-dis 22 prints its parameter as <1 x i64>. |
18 | STRUCT_ANON | [ispacked, eltty…] | A literal structure; no operand: Invalid anon struct record; any element type unknown: Invalid type. |
19 | STRUCT_NAME | [chars…] | No type. Holds the name for the next STRUCT_NAMED, OPAQUE or TARGET_TYPE record; the name is used up by that record. A conversion failure: Invalid struct name record. The writer uses an array abbreviation of Char6 characters when every character of the name is a Char6 character, and an unabbreviated record otherwise (writeStringRecord, line 804). |
20 | STRUCT_NAMED | [ispacked, eltty…] | A named structure with a body. Empty: Invalid named struct record. Element types are looked up with forward references allowed; an unknown ID is Invalid named struct record. A body that cannot be set (for example a second body) is the error from setBodyOrError. |
21 | FUNCTION | [vararg, retty, paramty…] | A function type. At least 2 operands (Invalid function record); a parameter that cannot be a function argument (Invalid function argument type); an unknown type (Invalid type). |
22 | TOKEN | — | token |
23 | BFLOAT | — | bfloat |
24 | X86_AMX | — | x86_amx |
25 | OPAQUE_POINTER | [addrspace] | ptr addrspace(n). Exactly one operand: Invalid opaque pointer record. The writer uses an abbreviation with the address space fixed at 0 for the common case. |
26 | TARGET_TYPE | [numtys, ty…, int…] | A target extension type. The name comes from the STRUCT_NAME just before it. The first operand counts the type parameters that follow; the rest are integer parameters (each must fit in 32 bits: Integer parameter too large). An empty record: Invalid target extension type record; a count not smaller than the record length: Too many type parameters; an unknown parameter type: Invalid type; a combination the target type does not accept is the error from TargetExtType::getOrError. |
27 | BYTE | [width] | A byte type bwidth, a recent addition. No operand: Invalid record; a width outside the allowed range: Bitwidth for byte type out of range. |
Code 27 settles the item the other pages marked unconfirmed: it is in
LLVMBitCodes.h (line 186) and the reader handles it (lines 2734–2744).
Codes 28 and up are unknown and rejected.
What the writer emits
- It writes only the current forms:
OPAQUE_POINTERfor every pointer,FUNCTIONwith the return type first, and never POINTER, FUNCTION_OLD or X86_MMX. - A named structure with a body is STRUCT_NAMED, one without is OPAQUE; both are preceded by STRUCT_NAME when the structure has a name. A literal structure is STRUCT_ANON. A target extension type is STRUCT_NAME (its name) then TARGET_TYPE.
- Abbreviations are defined in the block for OPAQUE_POINTER (address space 0), FUNCTION, STRUCT_ANON, STRUCT_NAME, STRUCT_NAMED and ARRAY; the type operands are fixed-width fields of the number of bits the table needs.
Sources
- llvm/lib/Bitcode/Reader/BitcodeReader.cpp – lines 1510–1521 (type lookup and placeholders), 2640–2960 (type table)
- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp – lines 1175–1351
- llvm/include/llvm/Bitcode/LLVMBitCodes.h – lines 139–187
- llvm/docs/BitCodeFormat.md – TYPE_BLOCK Contents