llvm_support/
bitcodes.rs

1//! Enum constants for `llvm-constants`.
2
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4
5use crate::FIRST_APPLICATION_BLOCK_ID;
6
7/// Block IDs that are reserved by LLVM.
8// NOTE(ww): Block IDs 0 through 7 are reserved, but only 0 (BLOCKINFO)
9// is actually currently used.
10#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, TryFromPrimitive)]
11#[repr(u64)]
12pub enum ReservedBlockId {
13    /// The `BLOCKINFO` block ID.
14    BlockInfo = 0,
15    /// Reserved; no semantics.
16    Reserved1 = 1,
17    /// Reserved; no semantics.
18    Reserved2 = 2,
19    /// Reserved; no semantics.
20    Reserved3 = 3,
21    /// Reserved; no semantics.
22    Reserved4 = 4,
23    /// Reserved; no semantics.
24    Reserved5 = 5,
25    /// Reserved; no semantics.
26    Reserved6 = 6,
27    /// Reserved; no semantics.
28    Reserved7 = 7,
29}
30
31/// Block IDs that are used by LLVM for bitcode (i.e., IR bitstreams).
32/// See: `enum BlockIDs` in `Bitcode/LLVMBitCodes.h`,
33#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, TryFromPrimitive)]
34#[repr(u64)]
35pub enum IrBlockId {
36    /// `MODULE_BLOCK_ID`
37    Module = FIRST_APPLICATION_BLOCK_ID,
38    /// `PARAM_ATTR_BLOCK_ID`
39    ParamAttr,
40    /// `PARAM_ATTR_GROUP_BLOCK_ID`
41    ParamAttrGroup,
42    /// `CONSTANTS_BLOCK_ID`
43    Constants,
44    /// `FUNCTION_BLOCK_ID`
45    Function,
46    /// `IDENTIFICATION_BLOCK_ID`.
47    Identification,
48    /// `VALUE_SYMTAB_BLOCK_ID`.
49    ValueSymtab,
50    /// `METADATA_BLOCK_ID`.
51    Metadata,
52    /// `METADATA_ATTACHMENT_BLOCK_ID`.
53    MetadataAttachment,
54    /// `TYPE_BLOCK_ID_NEW`.
55    Type,
56    /// `USELIST_BLOCK_ID`.
57    Uselist,
58    /// `MODULE_STRTAB_BLOCK_ID`.
59    ModuleStrtab,
60    /// `GLOBAL_VAL_SUMMARY_BLOCK_ID`.
61    GlobalValSummary,
62    /// `OPERAND_BUNDLE_TAGS_BLOCK_ID`.
63    OperandBundleTags,
64    /// `METADATA_KIND_BLOCK_ID`.
65    MetadataKind,
66    /// `STRTAB_BLOCK_ID`.
67    Strtab,
68    /// `FULL_LTO_GLOBAL_VAL_SUMMARY_BLOCK_ID`.
69    FullLtoGlobalValSummary,
70    /// `SYMTAB_BLOCK_ID`.
71    Symtab,
72    /// `SYNC_SCOPE_NAMES_BLOCK_ID`.
73    SyncScopeNames,
74}
75
76/// Abbreviation IDs that are reserved by LLVM.
77#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive)]
78#[repr(u64)]
79pub enum ReservedAbbrevId {
80    /// Identifies an `END_BLOCK` record.
81    EndBlock = 0,
82    /// Identifies an `ENTER_SUBBLOCK` record.
83    EnterSubBlock,
84    /// Identifies a `DEFINE_ABBREV` record.
85    DefineAbbrev,
86    /// Identifies an `UNABBREV_RECORD` record.
87    UnabbrevRecord,
88}
89
90/// Codes for each operand encoding type supported by `DEFINE_ABBREV`.
91#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive)]
92#[repr(u64)]
93pub enum AbbrevOpEnc {
94    /// A fixed-length, unsigned operand.
95    Fixed = 1,
96    /// A variable-length, unsigned operand.
97    Vbr,
98    /// An array of values.
99    Array,
100    /// A single 6-bit-encoded character.
101    Char6,
102    /// A blob of bytes.
103    Blob,
104}
105
106/// Codes for each `UNABBREV_RECORD` in `BLOCKINFO`.
107#[non_exhaustive]
108#[derive(Debug, PartialEq, TryFromPrimitive)]
109#[repr(u64)]
110pub enum BlockInfoCode {
111    /// SETBID: `[blockid]`
112    SetBid = 1,
113    /// BLOCKNAME: `[...name...]`
114    BlockName,
115    /// SETRECORDNAME: `[recordid, ...name...]`
116    SetRecordName,
117}
118
119/// Codes for each record in `IDENTIFICATION_BLOCK`.
120#[non_exhaustive]
121#[derive(Debug, PartialEq, TryFromPrimitive)]
122#[repr(u64)]
123pub enum IdentificationCode {
124    /// IDENTIFICATION_CODE_STRING: `[...string...]`
125    ProducerString = 1,
126    /// IDENTIFICATION_CODE_EPOCH: `[epoch]`
127    Epoch,
128}
129
130/// Codes for each record in `MODULE_BLOCK`.
131#[non_exhaustive]
132#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
133#[repr(u64)]
134pub enum ModuleCode {
135    /// MODULE_CODE_VERSION: `[version#]`
136    Version = 1,
137    /// MODULE_CODE_TRIPLE: `[...string...]`
138    Triple = 2,
139    /// MODULE_CODE_DATALAYOUT: `[...string...]`
140    DataLayout = 3,
141    /// MODULE_CODE_ASM: `[...string...]`
142    Asm = 4,
143    /// MODULE_CODE_SECTIONNAME: `[...string...]`
144    SectionName = 5,
145    /// MODULE_CODE_DEPLIB: `[...string...]`
146    DepLib = 6,
147    /// MODULE_CODE_GLOBALVAR: `[...fields...]`
148    /// See: <https://llvm.org/docs/BitCodeFormat.html#module-code-globalvar-record>
149    GlobalVar = 7,
150    /// MODULE_CODE_FUNCTION: `[...fields...]`
151    /// See: <https://llvm.org/docs/BitCodeFormat.html#module-code-function-record>
152    Function = 8,
153    /// MODULE_CODE_ALIAS_OLD: `[...fields...]`
154    /// See: <https://llvm.org/docs/BitCodeFormat.html#module-code-alias-record>
155    AliasOld = 9,
156    /// MODULE_CODE_GCNAME: `[...string...]`
157    GcName = 11,
158    /// MODULE_CODE_COMDAT
159    /// v1: `[selection_kind, name]`
160    /// v2: `[strtab_offset, strtab_size, selection_kind]`
161    /// Only `v2` is currently supported.
162    Comdat = 12,
163    /// MODULE_CODE_VSTOFFSET: `[offset]`
164    VstOffset = 13,
165    /// MODULE_CODE_ALIAS: `[...fields...]`
166    /// Not well documented; see `ModuleCodes` in `Bitcode/LLVMBitCodes.h`.
167    Alias = 14,
168    /// MODULE_CODE_METADATA_VALUES_UNUSED
169    /// Not documented at all; see `ModuleCodes` in `Bitcode/LLVMBitCodes.h`.
170    MetadataValuesUnused = 15,
171    /// MODULE_CODE_SOURCE_FILENAME: `[...string...]`
172    SourceFilename = 16,
173    /// MODULE_CODE_HASH: `[5*i32]`
174    Hash = 17,
175    /// MODULE_CODE_IFUNC: `[...fields...]`
176    /// Not well documented; see `ModuleCodes` in `Bitcode/LLVMBitCodes.h`.
177    IFunc = 18,
178}
179
180/// Codes for each record in `TYPE_BLOCK` (i.e., `TYPE_BLOCK_ID_NEW`).
181#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
182#[repr(u64)]
183pub enum TypeCode {
184    /// TYPE_CODE_NUMENTRY: `[numentries]`
185    NumEntry = 1,
186    /// TYPE_CODE_VOID
187    Void,
188    /// TYPE_CODE_FLOAT
189    Float,
190    /// TYPE_CODE_DOUBLE
191    Double,
192    /// TYPE_CODE_LABEL
193    Label,
194    /// TYPE_CODE_OPAQUE
195    Opaque,
196    /// TYPE_CODE_INTEGER: `[width]`
197    Integer,
198    /// TYPE_CODE_POINTER: `[pointee type]`
199    Pointer,
200    /// TYPE_CODE_FUNCTION_OLD: `[vararg, attrid, retty, paramty x N]`
201    FunctionOld,
202    /// TYPE_CODE_HALF
203    Half,
204    /// TYPE_CODE_ARRAY: `[numelts, eltty]`
205    Array,
206    /// TYPE_CODE_VECTOR: `[numelts, eltty]`
207    Vector,
208    /// TYPE_CODE_X86_FP80
209    X86Fp80,
210    /// TYPE_CODE_FP128
211    Fp128,
212    /// TYPE_CODE_PPC_FP128
213    PpcFp128,
214    /// TYPE_CODE_METADATA,
215    Metadata,
216    /// TYPE_CODE_X86_MMX
217    X86Mmx,
218    /// TYPE_CODE_STRUCT_ANON: `[ispacked, eltty x N]`
219    StructAnon,
220    /// TYPE_CODE_STRUCT_NAME: `[strchr x N]`
221    StructName,
222    /// TYPE_CODE_STRUCT_NAMED: `[ispacked, eltty x N]`
223    StructNamed,
224    /// TYPE_CODE_FUNCTION: `[vararg, retty, paramty x N]`
225    Function,
226    /// TYPE_CODE_TOKEN
227    Token,
228    /// TYPE_CODE_BFLOAT
229    BFloat,
230    /// TYPE_CODE_X86_AMX
231    X86Amx,
232    /// TYPE_CODE_OPAQUE_POINTER: `[addrspace]`
233    OpaquePointer,
234}
235
236/// Codes for each record in `STRTAB_BLOCK`.
237#[non_exhaustive]
238#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
239#[repr(u64)]
240pub enum StrtabCode {
241    /// STRTAB_BLOB: `[...string...]`
242    Blob = 1,
243}
244
245/// Codes for each record in `SYMTAB_BLOCK`.
246#[non_exhaustive]
247#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
248#[repr(u64)]
249pub enum SymtabCode {
250    /// SYMTAB_BLOB: `[...data...]`
251    Blob = 1,
252}
253
254/// Codes for each record in `PARAMATTR_BLOCK` or `PARAMATTR_GROUP_BLOCK`.
255// NOTE(ww): For whatever reason, these two blocks share the same enum for
256/// record codes.
257#[derive(Debug, PartialEq, IntoPrimitive, TryFromPrimitive)]
258#[repr(u64)]
259pub enum AttributeCode {
260    /// PARAMATTR_CODE_ENTRY_OLD: `[paramidx0, attr0, paramidx1, attr1...]`
261    EntryOld = 1,
262    /// PARAMATTR_CODE_ENTRY: `[attrgrp0, attrgrp1, ...]`
263    Entry,
264    /// PARAMATTR_GRP_CODE_ENTRY: `[grpid, idx, attr0, attr1, ...]`
265    GroupCodeEntry,
266}