The CONSTANTS block (11) and the FUNCTION block (12) hold the values and instructions
of a module. LLVM’s Bitcode File Format document leaves both as placeholders, so the
codes below come from LLVM’s LLVMBitCodes.h, with the operand lists from
its comments, and from the current writer where noted (see
sources). Records marked old are no longer written.
Operands
From module version 1, instruction operands that refer to values are relative value
IDs, and PHI operands are signed VBRs. The current writer writes most value operands
either as the value alone or as the value followed by its type (its
pushValue and pushValueAndType helpers). The constants’
integer records use signed VBRs.
CONSTANTS block (11)
| Code | Record | Operands |
|---|---|---|
1 | SETTYPE | [typeid]: the type of the following constants |
2 | NULL | — |
3 | UNDEF | — |
4 | INTEGER | [intval], a signed VBR |
5 | WIDE_INTEGER | [n × intval], signed VBRs |
6 | FLOAT | [fpval] |
7 | AGGREGATE | [n × value number] |
8 | STRING | [values] |
9 | CSTRING | [values] |
10 | CE_BINOP | [opcode, opval, opval]: a binary operator expression |
11 | CE_CAST | [opcode, opty, opval]: a cast expression |
12 | CE_GEP_OLD | [n × operands] (old) |
13 | CE_SELECT | [opval, opval, opval] |
14 | CE_EXTRACTELT | [opty, opval, opval] |
15 | CE_INSERTELT | [opval, opval, opval] |
16 | CE_SHUFFLEVEC | [opval, opval, opval] |
17 | CE_CMP | [opty, opval, opval, pred]; predicates |
18 | INLINEASM_OLD | [sideeffect|alignstack, asmstr, conststr] (old) |
19 | CE_SHUFVEC_EX | [opty, opval, opval, opval] |
20 | CE_INBOUNDS_GEP | [n × operands] |
21 | BLOCKADDRESS | [fnty, fnval, bb#] |
22 | DATA | [n × elements] |
23 | INLINEASM_OLD2 | [sideeffect|alignstack|asmdialect, asmstr, conststr] (old) |
24 | CE_GEP_WITH_INRANGE_INDEX_OLD | [opty, flags, n × operands] (old) |
25 | CE_UNOP | [opcode, opval] |
26 | POISON | — |
27 | DSO_LOCAL_EQUIVALENT | [gvty, gv] |
28 | INLINEASM_OLD3 | [sideeffect|alignstack|asmdialect|unwind, asmstr, conststr] (old) |
29 | NO_CFI_VALUE | [fty, f] |
30 | INLINEASM | [fnty, sideeffect|alignstack|asmdialect|unwind, asmstr, conststr] |
31 | CE_GEP_WITH_INRANGE | [opty, flags, range, n × operands] |
32 | CE_GEP | [opty, flags, n × operands]; GEP flags |
33 | PTRAUTH | [ptr, key, disc, addrdisc] |
34 | PTRAUTH2 | [ptr, key, disc, addrdisc, deactivation_symbol] |
35 | BYTE | [intval], sign-rotated; see constants |
36 | WIDE_BYTE | [n × intval], sign-rotated words; see constants |
FUNCTION block (12)
A FUNCTION block holds one function body and may contain CONSTANTS, VALUE_SYMTAB and METADATA_ATTACHMENT blocks as well as these records.
| Code | Record | Operands (header comment) |
|---|---|---|
1 | DECLAREBLOCKS | [n] |
2 | INST_BINOP | [opcode, ty, opval, opval] |
3 | INST_CAST | [opcode, ty, opty, opval] |
4 | INST_GEP_OLD | [n × operands] (old) |
5 | INST_SELECT | [ty, opval, opval, opval] |
6 | INST_EXTRACTELT | [opty, opval, opval] |
7 | INST_INSERTELT | [ty, opval, opval, opval] |
8 | INST_SHUFFLEVEC | [ty, opval, opval, opval] |
9 | INST_CMP | [opty, opval, opval, pred] |
10 | INST_RET | [opty, opval], both optional |
11 | INST_BR | [bb#, bb#, cond] or [bb#] |
12 | INST_SWITCH | [opty, op0, op1, …] |
13 | INST_INVOKE | [attr, fnty, op0, op1, …] |
14 | — | unused |
15 | INST_UNREACHABLE | — |
16 | INST_PHI | [ty, val0, bb0, …] |
17, 18 | — | unused |
19 | INST_ALLOCA | [instty, opty, op, align] |
20 | INST_LOAD | [opty, op, align, vol] |
21, 22 | — | unused |
23 | INST_VAARG | [valistty, valist, instty] |
24 | INST_STORE_OLD | [ptrty, ptr, val, align, vol] (old) |
25 | — | unused |
26 | INST_EXTRACTVAL | [n × operands] |
27 | INST_INSERTVAL | [n × operands] |
28 | INST_CMP2 | [opty, opval, opval, pred] |
29 | INST_VSELECT | [ty, opval, opval, predty, pred] |
30 | INST_INBOUNDS_GEP_OLD | [n × operands] (old) |
31 | INST_INDIRECTBR | [opty, op0, op1, …] |
32 | — | unused |
33 | DEBUG_LOC_AGAIN | — (same debug location as before) |
34 | INST_CALL | [attr, cc, fnty, fnid, args…] |
35 | DEBUG_LOC | [Line, Col, ScopeVal, IAVal] |
36 | INST_FENCE | [ordering, syncscope] |
37 | INST_CMPXCHG_OLD | [ptrty, ptr, cmp, val, vol, ordering, syncscope, failure_ordering?, weak?] (old) |
38 | INST_ATOMICRMW_OLD | [ptrty, ptr, val, operation, align, vol, ordering, syncscope] (old) |
39 | INST_RESUME | [opval] |
40 | INST_LANDINGPAD_OLD | [ty, val, val, num, id0, val0, …] (old) |
41 | INST_LOADATOMIC | [opty, op, align, vol, ordering, syncscope] |
42 | INST_STOREATOMIC_OLD | [ptrty, ptr, val, align, vol, ordering, syncscope] (old) |
43 | INST_GEP | [inbounds, n × operands] |
44 | INST_STORE | [ptrty, ptr, valty, val, align, vol] |
45 | INST_STOREATOMIC | [ptrty, ptr, val, align, vol, …] |
46 | INST_CMPXCHG | [ptrty, ptr, cmp, val, vol, success_ordering, syncscope, failure_ordering, weak] |
47 | INST_LANDINGPAD | [ty, val, num, id0, val0, …] |
48 | INST_CLEANUPRET | [val] or [val, bb#] |
49 | INST_CATCHRET | [val, bb#] |
50 | INST_CATCHPAD | [bb#, bb#, num, args…] |
51 | INST_CLEANUPPAD | [num, args…] |
52 | INST_CATCHSWITCH | [num, args…] or [num, args…, bb] |
53, 54 | — | unused |
55 | OPERAND_BUNDLE | [tag#, value…] |
56 | INST_UNOP | [opcode, ty, opval] |
57 | INST_CALLBR | [attr, cc, norm, transfs, fnty, fnid, args…] |
58 | INST_FREEZE | [opty, opval] |
59 | INST_ATOMICRMW | [ptrty, ptr, valty, val, operation, align, vol, ordering, syncscope] |
60 | BLOCKADDR_USERS | [value…] |
61 | DEBUG_RECORD_VALUE | [DILocation, DILocalVariable, DIExpression, ValueAsMetadata] |
62 | DEBUG_RECORD_DECLARE | [DILocation, DILocalVariable, DIExpression, ValueAsMetadata] |
63 | DEBUG_RECORD_ASSIGN | [DILocation, DILocalVariable, DIExpression, ValueAsMetadata, DIAssignID, DIExpression (addr), ValueAsMetadata (addr)] |
64 | DEBUG_RECORD_VALUE_SIMPLE | [DILocation, DILocalVariable, DIExpression, Value] |
65 | DEBUG_RECORD_LABEL | [DILocation, DILabel] |
66 | DEBUG_RECORD_DECLARE_VALUE | [DILocation, DILocalVariable, DIExpression, ValueAsMetadata]; read by LLVM’s reader like code 62 |
67 | INST_BITINSERT | [opval, opval, opval]: base, value, offset, each value and type; see instructions |
68 | INST_BITEXTRACT | [ty, opval, opval]: result type, source and offset, each value and type; see instructions |
What the current writer emits
For these records LLVM’s current writer uses a different order from the header comments:
| Record | Operands as written |
|---|---|
INST_BINOP | left operand (value and type), right operand (value), opcode, flags if any |
INST_CAST | operand (value and type), destination type, opcode, flags if any |
INST_LOAD | pointer (value and type), loaded type, encoded alignment, volatile; atomic loads add ordering and sync scope |
INST_STORE | pointer and value (each value and type), encoded alignment, volatile; atomic stores add ordering and sync scope |
INST_GEP | GEP flags, source element type, then each operand (value and type) |
INST_CALL | attribute list, call flags word, fast-math flags (only if any), function type, callee (value and type), fixed arguments (values), variable arguments (value and type) |
INST_ALLOCA | allocated type, size type, size value (an absolute ID), a packed word holding the alignment and the in-alloca, explicit-type and swifterror flags; an address space if not the default |
DEBUG_LOC | line, column, scope, inlined-at (both metadata ID plus 1), implicit-code flag, atom group, atom rank, and, when the location has IR layers, a metadata ID plus 1 for them. The reader (BitcodeReader.cpp, main branch) takes 4 operands at least; the 5th is the implicit-code flag, operands 6 and 7 the atom group and rank (read together: only when there are 7 or more), the 8th the IR layers (0 for none). The viewer shows the whole location as llvm-dis writes it: !DILocation(line: 20, column: 5, scope: !11, atomGroup: 3, atomRank: 1, irlayers: !10). Atom groups come from clang -gkey-instructions (debug-keyinstr-O1-linux.bc); the IR layers only from the hand-made newrec-layers.bc. |
The alloca word: bits 0 to 4 and 8 to 10 hold the alignment exponent plus 1 (low and high
part), bit 5 is inalloca, bit 6 “explicit type” and bit 7 swifterror
(BitcodeCommon.h). Every record’s operands, as the reader takes them, are on
instructions and
constants.
Operation codes
Cast opcodes
| Code | Cast | Code | Cast |
|---|---|---|---|
0 | TRUNC | 7 | FPTRUNC |
1 | ZEXT | 8 | FPEXT |
2 | SEXT | 9 | PTRTOINT |
3 | FPTOUI | 10 | INTTOPTR |
4 | FPTOSI | 11 | BITCAST |
5 | UITOFP | 12 | ADDRSPACECAST |
6 | SITOFP | 13 | PTRTOADDR |
Unary opcodes
0: FNEG.
Binary opcodes
| Code | Operator | Code | Operator |
|---|---|---|---|
0 | ADD | 7 | SHL |
1 | SUB | 8 | LSHR |
2 | MUL | 9 | ASHR |
3 | UDIV | 10 | AND |
4 | SDIV (also used for floating point) | 11 | OR |
5 | UREM | 12 | XOR |
6 | SREM (also used for floating point) |
Optional flags
Enum in LLVMBitCodes.h | Bit | Flag |
|---|---|---|
OverflowingBinaryOperatorOptionalFlags | 0 | OBO_NO_UNSIGNED_WRAP |
| 1 | OBO_NO_SIGNED_WRAP | |
PossiblyExactOperatorOptionalFlags | 0 | PEO_EXACT |
PossiblyDisjointInstOptionalFlags | 0 | PDI_DISJOINT |
TruncInstOptionalFlags | 0 | TIO_NO_UNSIGNED_WRAP |
| 1 | TIO_NO_SIGNED_WRAP |
Fast-math flags
| Bit | Value | Flag |
|---|---|---|
| 0 | 0x01 | UnsafeAlgebra (legacy) |
| 1 | 0x02 | NoNaNs |
| 2 | 0x04 | NoInfs |
| 3 | 0x08 | NoSignedZeros |
| 4 | 0x10 | AllowReciprocal |
| 5 | 0x20 | AllowContract |
| 6 | 0x40 | ApproxFunc |
| 7 | 0x80 | AllowReassoc |
GEP flags
| Bit | Flag |
|---|---|
| 0 | GEP_INBOUNDS |
| 1 | GEP_NUSW |
| 2 | GEP_NUW |
Call flags
| Bit | Name | Meaning |
|---|---|---|
| 0 | CALL_TAIL | tail call |
| 1–10 | CALL_CCONV | the calling convention, shifted left by 1; the reader takes (flags & 0x7ff) >> 1. INVOKE uses bits 0 to 9 and bit 13 for “explicit type” instead; see instructions |
| 14 | CALL_MUSTTAIL | must be a tail call |
| 15 | CALL_EXPLICIT_TYPE | the function type is given |
| 16 | CALL_NOTAIL | must not be a tail call |
| 17 | CALL_FMF | fast-math flags follow |
atomicrmw operations
| Code | Operation | Code | Operation |
|---|---|---|---|
0 | RMW_XCHG | 12 | RMW_FSUB |
1 | RMW_ADD | 13 | RMW_FMAX |
2 | RMW_SUB | 14 | RMW_FMIN |
3 | RMW_AND | 15 | RMW_UINC_WRAP |
4 | RMW_NAND | 16 | RMW_UDEC_WRAP |
5 | RMW_OR | 17 | RMW_USUB_COND |
6 | RMW_XOR | 18 | RMW_USUB_SAT |
7 | RMW_MAX | 19 | RMW_FMAXIMUM |
8 | RMW_MIN | 20 | RMW_FMINIMUM |
9 | RMW_UMAX | 21 | RMW_FMAXIMUMNUM |
10 | RMW_UMIN | 22 | RMW_FMINIMUMNUM |
11 | RMW_FADD |
The operation word also has a flag: bit 5 (RMW_ELEMENTWISE_FLAG, value 32)
marks an elementwise operation, and the operation itself is the word with that bit
cleared (LLVMBitCodes.h lines 535–537, getDecodedRMWOperation).
Atomic ordering
| Code | Ordering |
|---|---|
0 | ORDERING_NOTATOMIC |
1 | ORDERING_UNORDERED |
2 | ORDERING_MONOTONIC |
3 | ORDERING_ACQUIRE |
4 | ORDERING_RELEASE |
5 | ORDERING_ACQREL |
6 | ORDERING_SEQCST |
Comparison predicates
| Code | Predicate | Code | Predicate |
|---|---|---|---|
0 | FCMP_FALSE: always false | 8 | FCMP_UNO: unordered (either is NaN) |
1 | FCMP_OEQ: ordered and equal | 9 | FCMP_UEQ: unordered or equal |
2 | FCMP_OGT: ordered and greater than | 10 | FCMP_UGT: unordered or greater than |
3 | FCMP_OGE: ordered and greater or equal | 11 | FCMP_UGE: unordered, greater or equal |
4 | FCMP_OLT: ordered and less than | 12 | FCMP_ULT: unordered or less than |
5 | FCMP_OLE: ordered and less or equal | 13 | FCMP_ULE: unordered, less or equal |
6 | FCMP_ONE: ordered and unequal | 14 | FCMP_UNE: unordered or not equal |
7 | FCMP_ORD: ordered (no NaNs) | 15 | FCMP_TRUE: always true |
32 | ICMP_EQ: equal | 37 | ICMP_ULE: unsigned less or equal |
33 | ICMP_NE: not equal | 38 | ICMP_SGT: signed greater than |
34 | ICMP_UGT: unsigned greater than | 39 | ICMP_SGE: signed greater or equal |
35 | ICMP_UGE: unsigned greater or equal | 40 | ICMP_SLT: signed less than |
36 | ICMP_ULT: unsigned less than | 41 | ICMP_SLE: signed less or equal |
USELIST block (18)
In a function block, or in the module block for values of the module. It keeps the
order of a value’s uses when that is not the order the reader would build, so that
reading the file back gives the same use lists. Two records, from
parseUseLists in LLVM 22’s BitcodeReader.cpp:
USELIST_CODE_DEFAULT (1) and USELIST_CODE_BB (2), each
[index…, id]. The last operand is the number of the value (code 1, a
number in the function’s value numbering, so a global, an argument or an instruction)
or of the basic block (code 2); each operand before it is a position: the first
index belongs to the first use in the order the reader creates them, and the use is
put at that position in the list. A record has at least two indexes and they are a
permutation of 0 to n − 1. opt -S --preserve-ll-uselistorder prints the
same permutations as uselistorder lines.
What the reader does with a record
BitcodeReader::parseUseLists (main branch, BitcodeReader.cpp
lines 3948 to 4020, read 2026-11-19):
- The block is entered, and each record is read until the block ends. A sub-block or a
stream error is
Malformed block(line 3964). A record code other than 1 and 2 is skipped. - A record with fewer than 3 operands is
Invalid uselist record(line 3988): it needs the ID and at least two indexes. - The last operand is taken off as the ID. For code 2 it is an index into the function’s basic blocks, for code 1 an index into the value list. Neither index is range-checked by the reader (an out-of-range ID is an assertion in a build with assertions and an invalid access otherwise).
- A value that keeps no use list (
hasUseListfalse: constants and the like) is left alone. - The reader walks the value’s uses in the order it created them and pairs the n-th use with the n-th index. When the value has more or fewer uses than the record has indexes, the record is dropped without an error: the comment in the source says this happens when functions are materialised out of order or a value was upgraded.
- Otherwise the use list is sorted by the paired index.
The reader does not check that the indexes are a permutation: equal or out-of-range
indexes give an arbitrary order (the writer always writes a permutation). The writer
side is predictUseListOrder in ValueEnumerator.cpp; the
enumerator is not described on this page.
Sources
- LLVM Bitcode File Format – “Signed VBRs”, “MODULE_CODE_VERSION” (relative operands), CONSTANTS_BLOCK and FUNCTION_BLOCK placeholders
- LLVMBitCodes.h – ConstantsCodes, FunctionCodes, CastOpcodes, UnaryOpcodes, BinaryOpcodes, flag enums, FastMathMap, GetElementPtrOptionalFlags, CallMarkersFlags, RMWOperations, AtomicOrderingCodes (main branch, November 2026)
- InstrTypes.h –
CmpInst::Predicatevalues - BitcodeWriter.cpp – the operand orders in “What the current writer emits”