llvm_bitcode/schema/
values.rs

1//! From the LLVM Project, under the [Apache License v2.0 with LLVM Exceptions](https://llvm.org/LICENSE.txt)
2
3use num_enum::TryFromPrimitive;
4
5#[derive(Debug, Copy, Clone, PartialEq, TryFromPrimitive)]
6#[repr(u8)]
7pub enum AttrKind {
8    // = 0 is unused
9    Alignment = 1,
10    AlwaysInline = 2,
11    ByVal = 3,
12    InlineHint = 4,
13    InReg = 5,
14    MinSize = 6,
15    Naked = 7,
16    Nest = 8,
17    NoAlias = 9,
18    NoBuiltin = 10,
19    NoCapture = 11,
20    NoDuplicate = 12,
21    NoImplicitFloat = 13,
22    NoInline = 14,
23    NonLazyBind = 15,
24    NoRedZone = 16,
25    NoReturn = 17,
26    NoUnwind = 18,
27    OptimizeForSize = 19,
28    ReadNone = 20,
29    ReadOnly = 21,
30    Returned = 22,
31    ReturnsTwice = 23,
32    SExt = 24,
33    StackAlignment = 25,
34    StackProtect = 26,
35    StackProtectReq = 27,
36    StackProtectStrong = 28,
37    StructRet = 29,
38    SanitizeAddress = 30,
39    SanitizeThread = 31,
40    SanitizeMemory = 32,
41    UwTable = 33,
42    ZExt = 34,
43    Builtin = 35,
44    Cold = 36,
45    OptimizeNone = 37,
46    InAlloca = 38,
47    NonNull = 39,
48    JumpTable = 40,
49    Dereferenceable = 41,
50    DereferenceableOrNull = 42,
51    Convergent = 43,
52    Safestack = 44,
53    /// Unused
54    ArgMemOnly = 45,
55    SwiftSelf = 46,
56    SwiftError = 47,
57    NoRecurse = 48,
58    /// Unused
59    InaccessibleMemOnly = 49,
60    /// Unused
61    InaccessiblememOrArgMemOnly = 50,
62    AllocSize = 51,
63    Writeonly = 52,
64    Speculatable = 53,
65    StrictFp = 54,
66    SanitizeHwaddress = 55,
67    NocfCheck = 56,
68    OptForFuzzing = 57,
69    Shadowcallstack = 58,
70    SpeculativeLoadHardening = 59,
71    Immarg = 60,
72    Willreturn = 61,
73    Nofree = 62,
74    Nosync = 63,
75    SanitizeMemtag = 64,
76    Preallocated = 65,
77    NoMerge = 66,
78    NullPointerIsValid = 67,
79    Noundef = 68,
80    Byref = 69,
81    Mustprogress = 70,
82    NoCallback = 71,
83    Hot = 72,
84    NoProfile = 73,
85    VscaleRange = 74,
86    SwiftAsync = 75,
87    NoSanitizeCoverage = 76,
88    Elementtype = 77,
89    DisableSanitizerInstrumentation = 78,
90    NoSanitizeBounds = 79,
91    AllocAlign = 80,
92    AllocatedPointer = 81,
93    AllocKind = 82,
94    PresplitCoroutine = 83,
95    FnretthunkExtern = 84,
96    SkipProfile = 85,
97    Memory = 86,
98    Nofpclass = 87,
99    OptimizeForDebugging = 88,
100    Writable = 89,
101    CoroOnlyDestroyWhenComplete = 90,
102    DeadOnUnwind = 91,
103    Range = 92,
104    SanitizeNumericalStability = 93,
105    Initializes = 94,
106    HybridPatchable = 95,
107}
108
109/// These are values used in the bitcode files to encode which
110/// cast a `CST_CODE_CE_CAST` refers to.
111#[derive(Debug, TryFromPrimitive)]
112#[repr(u8)]
113pub enum CastOpcode {
114    Trunc = 0,
115    ZExt = 1,
116    SExt = 2,
117    FpToUi = 3,
118    FpToSi = 4,
119    UiToFp = 5,
120    SiToFp = 6,
121    FpTrunc = 7,
122    FpExt = 8,
123    PtrToInt = 9,
124    IntToPtr = 10,
125    Bitcast = 11,
126    Addrspace = 12,
127}
128
129#[derive(Debug, TryFromPrimitive)]
130#[repr(u8)]
131pub enum Linkage {
132    External = 0,
133    Weak = 1,
134    Appending = 2,
135    Internal = 3,
136    Linkonce = 4,
137    Dllimport = 5,
138    Dllexport = 6,
139    ExternWeak = 7,
140    Common = 8,
141    Private = 9,
142    WeakOdr = 10,
143    LinkonceOdr = 11,
144    AvailableExternally = 12,
145    Deprecated1 = 13,
146    Deprecated2 = 14,
147}
148
149#[derive(Debug, TryFromPrimitive)]
150#[repr(u8)]
151pub enum DllStorageClass {
152    Default = 0,
153    Import = 1,
154    Export = 2,
155}
156
157#[derive(Debug, TryFromPrimitive)]
158#[repr(u8)]
159pub enum CallConv {
160    C = 0,
161    Fast = 8,
162    Cold = 9,
163    GHC = 10,
164    HiPE = 11,
165    AnyReg = 13,
166    PreserveMost = 14,
167    PreserveAll = 15,
168    Swift = 16,
169    /// CXX_FAST_TLS
170    CxxFastTls = 17,
171    Tail = 18,
172    /// CFGuard_Check
173    CFGuardCheck = 19,
174    SwiftTail = 20,
175    PreserveNone = 21,
176    /// X86_StdCall (first target cc)
177    X86StdCall = 64,
178    /// X86_FastCall
179    X86FastCall = 65,
180    /// ARM_APCS
181    ArmApcs = 66,
182    /// ARM_AAPCS
183    ArmAapcs = 67,
184    /// ARM_AAPCS_VFP
185    ArmAapcsVfp = 68,
186    /// MSP430_INTR
187    Msp430Intr = 69,
188    /// X86_ThisCall
189    X86ThisCall = 70,
190    /// PTX_Kernel
191    PTXKernel = 71,
192    /// PTX_Device
193    PTXDevice = 72,
194    /// SPIR_FUNC
195    SpirFunc = 75,
196    /// SPIR_KERNEL
197    SpirKernel = 76,
198    /// Intel_OCL_BI
199    IntelOclBi = 77,
200    /// X86_64_SysV
201    X8664SysV = 78,
202    /// Win64
203    Win64 = 79,
204    /// X86_VectorCall
205    X86VectorCall = 80,
206    /// DUMMY_HHVM
207    DummyHhvm = 81,
208    /// DUMMY_HHVM_C
209    DummyHhvmC = 82,
210    /// X86_INTR
211    X86Intr = 83,
212    /// AVR_INTR
213    AvrIntr = 84,
214    /// AVR_SIGNAL
215    AvrSignal = 85,
216    /// AVR_BUILTIN
217    AvrBuiltin = 86,
218    /// AMDGPU_VS
219    AmdGpuVs = 87,
220    /// AMDGPU_GS
221    AmdGpuGs = 88,
222    /// AMDGPU_PS
223    AmdGpuPs = 89,
224    /// AMDGPU_CS
225    AmdGpuCs = 90,
226    /// AMDGPU_KERNEL
227    AmdGpuKernel = 91,
228    /// X86_RegCall
229    X86RegCall = 92,
230    /// AMDGPU_HS
231    AmdGpuHs = 93,
232    /// MSP430_BUILTIN
233    Msp430Builtin = 94,
234    /// AMDGPU_LS
235    AmdGpuLs = 95,
236    /// AMDGPU_ES
237    AmdGpuEs = 96,
238    /// AArch64_VectorCall
239    AArch64VectorCall = 97,
240    /// AArch64_SVE_VectorCall
241    AArch64SVEVectorCall = 98,
242    /// WASM_EmscriptenInvoke
243    WasmEmscriptenInvoke = 99,
244    /// AMDGPU_Gfx
245    AmdGpuGfx = 100,
246    /// M68k_INTR
247    M68kIntr = 101,
248    AArch64SmeAbiSupportRoutinesPreserveMostFromX0 = 102,
249    AArch64SmeAbiSupportRoutinesPreserveMostFromX2 = 103,
250    AmdGpuCSChain = 104,
251    AmdGpuCSChainPreserve = 105,
252    M68kRTD = 106,
253    Graal = 107,
254    Arm64ECThunkX64 = 108,
255    Arm64ECThunkNative = 109,
256    RiscVVectorCall = 110,
257    AArch64SmeAbiSupportRoutinesPreserveMostFromX1 = 111,
258}
259
260/// call conv field in bitcode is often mixed with flags
261impl CallConv {
262    pub fn from_flags(ccinfo_flags: u64) -> Result<Self, String> {
263        // static_cast<CallingConv::ID>((0x7ff & CCInfo) >> bitc::CALL_CCONV));
264        let id = u8::try_from((ccinfo_flags & 0x7ff) >> 1).map_err(|e| e.to_string())?;
265        Self::try_from_primitive(id).map_err(|e| e.to_string())
266    }
267}
268
269/// These are values used in the bitcode files to encode which
270/// binop a `CST_CODE_CE_BINOP` refers to.
271#[derive(Debug, TryFromPrimitive)]
272#[repr(u8)]
273pub enum BinOpcode {
274    Add = 0,
275    Sub = 1,
276    Mul = 2,
277    Udiv = 3,
278    /// overloaded for FP
279    Sdiv = 4,
280    Urem = 5,
281    /// overloaded for FP
282    Srem = 6,
283    Shl = 7,
284    Lshr = 8,
285    Ashr = 9,
286    And = 10,
287    Or = 11,
288    Xor = 12,
289}
290
291/// Encoded `AtomicOrdering` values.
292#[derive(Debug, TryFromPrimitive, Default)]
293#[repr(u8)]
294pub enum AtomicOrdering {
295    #[default]
296    Notatomic = 0,
297    Unordered = 1,
298    Monotonic = 2,
299    Acquire = 3,
300    Release = 4,
301    AcqRel = 5,
302    SeqCst = 6,
303}
304
305/// COMDATSELECTIONKIND enumerates the possible selection mechanisms for
306/// COMDAT sections.
307#[derive(Debug, Clone, Copy, TryFromPrimitive)]
308#[repr(u8)]
309pub enum ComdatSelectionKind {
310    Any = 1,
311    ExactMatch = 2,
312    Largest = 3,
313    NoDuplicates = 4,
314    SameSize = 5,
315}
316
317/// Atomic read-modify-write operations
318#[derive(Debug, Clone, Copy, TryFromPrimitive)]
319#[repr(u8)]
320#[non_exhaustive]
321pub enum RmwOperation {
322    /// `XCHG`
323    Xchg = 0,
324
325    /// `ADD`
326    Add = 1,
327
328    /// `SUB`
329    Sub = 2,
330
331    /// `AND`
332    And = 3,
333
334    /// `NAND`
335    Nand = 4,
336
337    /// `OR`
338    Or = 5,
339
340    /// `XOR`
341    Xor = 6,
342
343    /// `MAX`
344    Max = 7,
345
346    /// `MIN`
347    Min = 8,
348
349    /// `UMAX`
350    Umax = 9,
351
352    /// `UMIN`
353    Umin = 10,
354
355    /// `FADD`
356    Fadd = 11,
357
358    /// `FSUB`
359    Fsub = 12,
360
361    /// `FMAX`
362    Fmax = 13,
363
364    /// `FMIN`
365    Fmin = 14,
366
367    /// `UINC_WRAP`
368    UincWrap = 15,
369
370    /// `UDEC_WRAP`
371    UdecWrap = 16,
372
373    /// `USUB_COND`
374    UsSubCond = 17,
375
376    /// `USUB_SAT`
377    UsSubSat = 18,
378}
379
380/// Unary Opcodes
381#[derive(Debug, Clone, Copy, TryFromPrimitive)]
382#[repr(u8)]
383#[non_exhaustive]
384pub enum UnaryOpcode {
385    /// `UNOP_FNEG`
386    Fneg = 0,
387}
388
389/// Flags for serializing
390/// OverflowingBinaryOperator's SubclassOptionalData contents.
391#[derive(Debug, Clone, Copy, TryFromPrimitive)]
392#[repr(u8)]
393#[non_exhaustive]
394pub enum OverflowingBinaryOperatorOptionalFlags {
395    NoUnsignedWrap = 0,
396    NoSignedWrap = 1,
397}
398
399/// Flags for serializing
400/// TruncInstOptionalFlags's SubclassOptionalData contents.
401#[derive(Debug, Clone, Copy, TryFromPrimitive)]
402#[repr(u8)]
403#[non_exhaustive]
404pub enum TruncInstOptionalFlags {
405    NoUnsignedWrap = 0,
406    NoSignedWrap = 1,
407}
408
409/// FastMath Flags
410/// This is a fixed layout derived from the bitcode emitted by LLVM 5.0
411/// intended to decouple the in-memory representation from the serialization.
412#[derive(Debug, Clone, Copy, TryFromPrimitive)]
413#[repr(u8)]
414pub enum FastMathMap {
415    UnsafeAlgebra = 1 << 0, // Legacy
416    NoNaNs = 1 << 1,
417    NoInfs = 1 << 2,
418    NoSignedZeros = 1 << 3,
419    AllowReciprocal = 1 << 4,
420    AllowContract = 1 << 5,
421    ApproxFunc = 1 << 6,
422    AllowReassoc = 1 << 7,
423}
424
425/// Flags for serializing
426/// GEPOperator's SubclassOptionalData contents.
427#[derive(Debug, Clone, Copy, TryFromPrimitive)]
428#[repr(u8)]
429#[non_exhaustive]
430pub enum GetElementPtrOptionalFlags {
431    Inbounds = 0,
432    Nusw = 1,
433    Nuw = 2,
434}
435
436/// Markers and flags for call instruction.
437#[derive(Debug, Clone, Copy, TryFromPrimitive)]
438#[repr(u8)]
439#[non_exhaustive]
440pub enum CallMarkersFlags {
441    Tail = 0,
442    Cconv = 1,
443    MustTail = 14,
444    ExplicitType = 15,
445    NoTail = 16,
446    Fmf = 17, // Call has optional fast-math-flags.
447}