Skip to main content

llvm_sys/
lib.rs

1//! Bindings to LLVM's C API.
2//!
3//! Refer to the [LLVM documentation](http://llvm.org/docs/) for more
4//! information.
5
6#![allow(non_upper_case_globals)]
7#![allow(non_camel_case_types)]
8
9extern crate libc;
10
11use self::prelude::*;
12
13#[derive(Debug)]
14pub enum LLVMMemoryBuffer {}
15
16#[derive(Debug)]
17pub enum LLVMContext {}
18
19#[derive(Debug)]
20pub enum LLVMModule {}
21
22#[derive(Debug)]
23pub enum LLVMType {}
24
25#[derive(Debug)]
26pub enum LLVMValue {}
27
28#[derive(Debug)]
29pub enum LLVMBasicBlock {}
30
31#[derive(Debug)]
32pub enum LLVMOpaqueMetadata {}
33
34#[derive(Debug)]
35pub enum LLVMOpaqueNamedMDNode {}
36
37#[derive(Debug)]
38pub enum LLVMOpaqueValueMetadataEntry {}
39
40#[derive(Debug)]
41pub enum LLVMBuilder {}
42
43#[derive(Debug)]
44pub enum LLVMOpaqueDIBuilder {}
45
46#[derive(Debug)]
47pub enum LLVMModuleProvider {}
48
49#[derive(Debug)]
50pub enum LLVMPassManager {}
51
52#[derive(Debug)]
53pub enum LLVMUse {}
54
55#[derive(Debug)]
56pub enum LLVMOpaqueOperandBundle {}
57
58#[derive(Debug)]
59pub enum LLVMDiagnosticInfo {}
60
61#[derive(Debug)]
62pub enum LLVMComdat {}
63
64#[derive(Debug)]
65pub enum LLVMOpaqueModuleFlagEntry {}
66
67#[derive(Debug)]
68pub enum LLVMOpaqueJITEventListener {}
69
70#[derive(Debug)]
71pub enum LLVMOpaqueAttributeRef {}
72
73#[derive(Debug)]
74pub enum LLVMOpaqueDbgRecord {}
75
76/// Core types used throughout LLVM.
77///
78/// In most cases you will want to `use llvm::prelude::*`.
79pub mod prelude {
80    pub type LLVMBool = ::libc::c_int;
81    pub type LLVMMemoryBufferRef = *mut super::LLVMMemoryBuffer;
82    pub type LLVMContextRef = *mut super::LLVMContext;
83    pub type LLVMModuleRef = *mut super::LLVMModule;
84    pub type LLVMTypeRef = *mut super::LLVMType;
85    pub type LLVMValueRef = *mut super::LLVMValue;
86    pub type LLVMBasicBlockRef = *mut super::LLVMBasicBlock;
87    pub type LLVMMetadataRef = *mut super::LLVMOpaqueMetadata;
88    pub type LLVMNamedMDNodeRef = *mut super::LLVMOpaqueNamedMDNode;
89    pub type LLVMValueMetadataEntry = *mut super::LLVMOpaqueValueMetadataEntry;
90    pub type LLVMBuilderRef = *mut super::LLVMBuilder;
91    pub type LLVMDIBuilderRef = *mut super::LLVMOpaqueDIBuilder;
92    pub type LLVMModuleProviderRef = *mut super::LLVMModuleProvider;
93    pub type LLVMPassManagerRef = *mut super::LLVMPassManager;
94    pub type LLVMUseRef = *mut super::LLVMUse;
95    pub type LLVMOperandBundleRef = *mut super::LLVMOpaqueOperandBundle;
96    pub type LLVMDiagnosticInfoRef = *mut super::LLVMDiagnosticInfo;
97    pub type LLVMComdatRef = *mut super::LLVMComdat;
98    pub type LLVMModuleFlagEntry = *mut super::LLVMOpaqueModuleFlagEntry;
99    pub type LLVMJITEventListenerRef = *mut super::LLVMOpaqueJITEventListener;
100    pub type LLVMAttributeRef = *mut super::LLVMOpaqueAttributeRef;
101    pub type LLVMDbgRecordRef = *mut super::LLVMOpaqueDbgRecord;
102}
103
104pub mod analysis;
105pub mod bit_reader;
106pub mod bit_writer;
107pub mod blake3;
108pub mod comdat;
109pub mod core;
110pub mod debuginfo;
111pub mod disassembler;
112pub mod error;
113pub mod error_handling;
114pub mod execution_engine;
115pub mod ir_reader;
116pub mod linker;
117pub mod lto;
118pub mod object;
119pub mod orc2;
120pub mod remarks;
121pub mod support;
122pub mod target;
123pub mod target_machine;
124
125pub mod transforms {
126    pub mod pass_builder;
127}
128
129#[repr(C)]
130#[derive(Clone, Copy, Debug, PartialEq)]
131pub enum LLVMOpcode {
132    LLVMRet = 1,
133    // LLVMBr = 2 was removed in LLVM 23
134    LLVMUncondBr = 70,
135    LLVMCondBr = 71,
136    LLVMSwitch = 3,
137    LLVMIndirectBr = 4,
138    LLVMInvoke = 5,
139    LLVMUnreachable = 7,
140    LLVMCallBr = 67,
141    LLVMFNeg = 66,
142    LLVMAdd = 8,
143    LLVMFAdd = 9,
144    LLVMSub = 10,
145    LLVMFSub = 11,
146    LLVMMul = 12,
147    LLVMFMul = 13,
148    LLVMUDiv = 14,
149    LLVMSDiv = 15,
150    LLVMFDiv = 16,
151    LLVMURem = 17,
152    LLVMSRem = 18,
153    LLVMFRem = 19,
154    LLVMShl = 20,
155    LLVMLShr = 21,
156    LLVMAShr = 22,
157    LLVMAnd = 23,
158    LLVMOr = 24,
159    LLVMXor = 25,
160    LLVMAlloca = 26,
161    LLVMLoad = 27,
162    LLVMStore = 28,
163    LLVMGetElementPtr = 29,
164    LLVMTrunc = 30,
165    LLVMZExt = 31,
166    LLVMSExt = 32,
167    LLVMFPToUI = 33,
168    LLVMFPToSI = 34,
169    LLVMUIToFP = 35,
170    LLVMSIToFP = 36,
171    LLVMFPTrunc = 37,
172    LLVMFPExt = 38,
173    LLVMPtrToInt = 39,
174    LLVMPtrToAddr = 69,
175    LLVMIntToPtr = 40,
176    LLVMBitCast = 41,
177    LLVMAddrSpaceCast = 60,
178    LLVMICmp = 42,
179    LLVMFCmp = 43,
180    LLVMPHI = 44,
181    LLVMCall = 45,
182    LLVMSelect = 46,
183    LLVMUserOp1 = 47,
184    LLVMUserOp2 = 48,
185    LLVMVAArg = 49,
186    LLVMExtractElement = 50,
187    LLVMInsertElement = 51,
188    LLVMShuffleVector = 52,
189    LLVMExtractValue = 53,
190    LLVMInsertValue = 54,
191    LLVMFreeze = 68,
192    LLVMFence = 55,
193    LLVMAtomicCmpXchg = 56,
194    LLVMAtomicRMW = 57,
195    LLVMResume = 58,
196    LLVMLandingPad = 59,
197    LLVMCleanupRet = 61,
198    LLVMCatchRet = 62,
199    LLVMCatchPad = 63,
200    LLVMCleanupPad = 64,
201    LLVMCatchSwitch = 65,
202}
203
204#[repr(C)]
205#[derive(Clone, Copy, Debug, PartialEq)]
206pub enum LLVMTypeKind {
207    LLVMVoidTypeKind = 0,
208    LLVMHalfTypeKind = 1,
209    LLVMFloatTypeKind = 2,
210    LLVMDoubleTypeKind = 3,
211    LLVMX86_FP80TypeKind = 4,
212    LLVMFP128TypeKind = 5,
213    LLVMPPC_FP128TypeKind = 6,
214    LLVMLabelTypeKind = 7,
215    LLVMIntegerTypeKind = 8,
216    LLVMFunctionTypeKind = 9,
217    LLVMStructTypeKind = 10,
218    LLVMArrayTypeKind = 11,
219    LLVMPointerTypeKind = 12,
220    LLVMVectorTypeKind = 13,
221    LLVMMetadataTypeKind = 14,
222    // 15 previously used by LLVMX86_MMXTypeKind
223    LLVMTokenTypeKind = 16,
224    LLVMScalableVectorTypeKind = 17,
225    LLVMBFloatTypeKind = 18,
226    LLVMX86_AMXTypeKind = 19,
227    LLVMTargetExtTypeKind = 20,
228    /// Arbitrary bit width bytes
229    LLVMByteTypeKind = 21,
230}
231
232#[repr(C)]
233#[derive(Clone, Copy, Debug, PartialEq)]
234pub enum LLVMLinkage {
235    LLVMExternalLinkage = 0,
236    LLVMAvailableExternallyLinkage = 1,
237    LLVMLinkOnceAnyLinkage = 2,
238    LLVMLinkOnceODRLinkage = 3,
239    LLVMLinkOnceODRAutoHideLinkage = 4,
240    LLVMWeakAnyLinkage = 5,
241    LLVMWeakODRLinkage = 6,
242    LLVMAppendingLinkage = 7,
243    LLVMInternalLinkage = 8,
244    LLVMPrivateLinkage = 9,
245    LLVMDLLImportLinkage = 10,
246    LLVMDLLExportLinkage = 11,
247    LLVMExternalWeakLinkage = 12,
248    LLVMGhostLinkage = 13,
249    LLVMCommonLinkage = 14,
250    LLVMLinkerPrivateLinkage = 15,
251    LLVMLinkerPrivateWeakLinkage = 16,
252}
253
254#[repr(C)]
255#[derive(Clone, Copy, Debug, PartialEq)]
256pub enum LLVMVisibility {
257    LLVMDefaultVisibility = 0,
258    LLVMHiddenVisibility = 1,
259    LLVMProtectedVisibility = 2,
260}
261
262#[repr(C)]
263#[derive(Clone, Copy, Debug, PartialEq)]
264pub enum LLVMUnnamedAddr {
265    /// Address of the GV is significant.
266    LLVMNoUnnamedAddr,
267    /// Address of the GV is locally insignificant.
268    LLVMLocalUnnamedAddr,
269    /// Address of the GV is globally insignificant.
270    LLVMGlobalUnnamedAddr,
271}
272
273#[repr(C)]
274#[derive(Clone, Copy, Debug, PartialEq)]
275pub enum LLVMDLLStorageClass {
276    LLVMDefaultStorageClass = 0,
277    LLVMDLLImportStorageClass = 1,
278    LLVMDLLExportStorageClass = 2,
279}
280
281#[repr(C)]
282#[derive(Clone, Copy, Debug, PartialEq)]
283pub enum LLVMCallConv {
284    LLVMCCallConv = 0,
285    LLVMFastCallConv = 8,
286    LLVMColdCallConv = 9,
287    LLVMGHCCallConv = 10,
288    LLVMHiPECallConv = 11,
289    LLVMAnyRegCallConv = 13,
290    LLVMPreserveMostCallConv = 14,
291    LLVMPreserveAllCallConv = 15,
292    LLVMSwiftCallConv = 16,
293    LLVMCXXFASTTLSCallConv = 17,
294    LLVMX86StdcallCallConv = 64,
295    LLVMX86FastcallCallConv = 65,
296    LLVMARMAPCSCallConv = 66,
297    LLVMARMAAPCSCallConv = 67,
298    LLVMARMAAPCSVFPCallConv = 68,
299    LLVMMSP430INTRCallConv = 69,
300    LLVMX86ThisCallCallConv = 70,
301    LLVMPTXKernelCallConv = 71,
302    LLVMPTXDeviceCallConv = 72,
303    LLVMSPIRFUNCCallConv = 75,
304    LLVMSPIRKERNELCallConv = 76,
305    LLVMIntelOCLBICallConv = 77,
306    LLVMX8664SysVCallConv = 78,
307    LLVMWin64CallConv = 79,
308    LLVMX86VectorCallCallConv = 80,
309    LLVMHHVMCallConv = 81,
310    LLVMHHVMCCallConv = 82,
311    LLVMX86INTRCallConv = 83,
312    LLVMAVRINTRCallConv = 84,
313    LLVMAVRSIGNALCallConv = 85,
314    LLVMAVRBUILTINCallConv = 86,
315    LLVMAMDGPUVSCallConv = 87,
316    LLVMAMDGPUGSCallConv = 88,
317    LLVMAMDGPUPSCallConv = 89,
318    LLVMAMDGPUCSCallConv = 90,
319    LLVMAMDGPUKERNELCallConv = 91,
320    LLVMX86RegCallCallConv = 92,
321    LLVMAMDGPUHSCallConv = 93,
322    LLVMMSP430BUILTINCallConv = 94,
323    LLVMAMDGPULSCallConv = 95,
324    LLVMAMDGPUESCallConv = 96,
325}
326
327#[repr(C)]
328#[derive(Clone, Copy, Debug, PartialEq)]
329pub enum LLVMValueKind {
330    LLVMArgumentValueKind,
331    LLVMBasicBlockValueKind,
332    LLVMMemoryUseValueKind,
333    LLVMMemoryDefValueKind,
334    LLVMMemoryPhiValueKind,
335
336    LLVMFunctionValueKind,
337    LLVMGlobalAliasValueKind,
338    LLVMGlobalIFuncValueKind,
339    LLVMGlobalVariableValueKind,
340    LLVMBlockAddressValueKind,
341    LLVMConstantExprValueKind,
342    LLVMConstantArrayValueKind,
343    LLVMConstantStructValueKind,
344    LLVMConstantVectorValueKind,
345    LLVMUndefValueValueKind,
346    LLVMConstantAggregateZeroValueKind,
347    LLVMConstantDataArrayValueKind,
348    LLVMConstantDataVectorValueKind,
349    LLVMConstantIntValueKind,
350    LLVMConstantByteValueKind,
351    LLVMConstantFPValueKind,
352    LLVMConstantPointerNullValueKind,
353    LLVMConstantTokenNoneValueKind,
354
355    LLVMMetadataAsValueValueKind,
356    LLVMInlineAsmValueKind,
357
358    LLVMInstructionValueKind,
359    LLVMPoisonValueKind,
360    LLVMConstantTargetNoneValueKind,
361    LLVMConstantPtrAuthValueKind,
362}
363
364#[repr(C)]
365#[derive(Clone, Copy, Debug, PartialEq)]
366pub enum LLVMIntPredicate {
367    LLVMIntEQ = 32,
368    LLVMIntNE = 33,
369    LLVMIntUGT = 34,
370    LLVMIntUGE = 35,
371    LLVMIntULT = 36,
372    LLVMIntULE = 37,
373    LLVMIntSGT = 38,
374    LLVMIntSGE = 39,
375    LLVMIntSLT = 40,
376    LLVMIntSLE = 41,
377}
378
379#[repr(C)]
380#[derive(Clone, Copy, Debug, PartialEq)]
381pub enum LLVMRealPredicate {
382    LLVMRealPredicateFalse = 0,
383    LLVMRealOEQ = 1,
384    LLVMRealOGT = 2,
385    LLVMRealOGE = 3,
386    LLVMRealOLT = 4,
387    LLVMRealOLE = 5,
388    LLVMRealONE = 6,
389    LLVMRealORD = 7,
390    LLVMRealUNO = 8,
391    LLVMRealUEQ = 9,
392    LLVMRealUGT = 10,
393    LLVMRealUGE = 11,
394    LLVMRealULT = 12,
395    LLVMRealULE = 13,
396    LLVMRealUNE = 14,
397    LLVMRealPredicateTrue = 15,
398}
399
400#[repr(C)]
401#[derive(Clone, Copy, Debug, PartialEq)]
402pub enum LLVMThreadLocalMode {
403    LLVMNotThreadLocal = 0,
404    LLVMGeneralDynamicTLSModel = 1,
405    LLVMLocalDynamicTLSModel = 2,
406    LLVMInitialExecTLSModel = 3,
407    LLVMLocalExecTLSModel = 4,
408}
409
410#[repr(C)]
411#[derive(Clone, Copy, Debug, PartialEq)]
412pub enum LLVMAtomicOrdering {
413    LLVMAtomicOrderingNotAtomic = 0,
414    LLVMAtomicOrderingUnordered = 1,
415    LLVMAtomicOrderingMonotonic = 2,
416    LLVMAtomicOrderingAcquire = 4,
417    LLVMAtomicOrderingRelease = 5,
418    LLVMAtomicOrderingAcquireRelease = 6,
419    LLVMAtomicOrderingSequentiallyConsistent = 7,
420}
421
422#[repr(C)]
423#[derive(Clone, Copy, Debug, PartialEq)]
424pub enum LLVMAtomicRMWBinOp {
425    LLVMAtomicRMWBinOpXchg = 0,
426    LLVMAtomicRMWBinOpAdd = 1,
427    LLVMAtomicRMWBinOpSub = 2,
428    LLVMAtomicRMWBinOpAnd = 3,
429    LLVMAtomicRMWBinOpNand = 4,
430    LLVMAtomicRMWBinOpOr = 5,
431    LLVMAtomicRMWBinOpXor = 6,
432    LLVMAtomicRMWBinOpMax = 7,
433    LLVMAtomicRMWBinOpMin = 8,
434    LLVMAtomicRMWBinOpUMax = 9,
435    LLVMAtomicRMWBinOpUMin = 10,
436    LLVMAtomicRMWBinOpFAdd = 11,
437    LLVMAtomicRMWBinOpFSub = 12,
438    LLVMAtomicRMWBinOpFMax = 13,
439    LLVMAtomicRMWBinOpFMin = 14,
440    LLVMAtomicRMWBinOpUIncWrap = 15,
441    LLVMAtomicRMWBinOpUDecWrap = 16,
442    /// Subtracts the value only if no unsigned overflow.
443    LLVMAtomicRMWBinOpUSubCond,
444    /// Subtracts the value, clamping to zero.
445    LLVMAtomicRMWBinOpUSubSat,
446    /// Sets the value if it's greater than the original using an floating
447    /// point comparison and return the old one.
448    LLVMAtomicRMWBinOpFMaximum,
449    /// Sets the value if it's smaller than the original using an floating
450    /// point comparison and return the old one.
451    LLVMAtomicRMWBinOpFMinimum,
452    /// Sets the value if it's greater than the original using a floating
453    /// point comparison and return the old one.
454    LLVMAtomicRMWBinOpFMaximumNum,
455    /// Sets the value if it's smaller than the original using a floating
456    /// point comparison and return the old one.
457    LLVMAtomicRMWBinOpFMinimumNum,
458}
459
460#[repr(C)]
461#[derive(Clone, Copy, Debug, PartialEq)]
462pub enum LLVMDiagnosticSeverity {
463    LLVMDSError = 0,
464    LLVMDSWarning = 1,
465    LLVMDSRemark = 2,
466    LLVMDSNote = 3,
467}
468
469#[repr(C)]
470#[derive(Clone, Copy, Debug, PartialEq)]
471pub enum LLVMInlineAsmDialect {
472    LLVMInlineAsmDialectATT,
473    LLVMInlineAsmDialectIntel,
474}
475
476#[repr(C)]
477#[derive(Clone, Copy, Debug, PartialEq)]
478pub enum LLVMModuleFlagBehavior {
479    /// Emits an error if two values disagree, otherwise the resulting value is that of the operands.
480    LLVMModuleFlagBehaviorError,
481    /// Emits a warning if two values disagree. The result value will be the operand for the flag from the first module being linked.
482    LLVMModuleFlagBehaviorWarning,
483    /// Adds a requirement that another module flag be present and have a specified value after linking is performed. The value must be a metadata pair, where the first element of the pair is the ID of the module flag to be restricted, and the second element of the pair is the value the module flag should be restricted to. This behavior can be used to restrict the allowable results (via triggering of an error) of linking IDs with the **Override** behavior.
484    LLVMModuleFlagBehaviorRequire,
485    /// Uses the specified value, regardless of the behavior or value of the other module. If both modules specify **Override**, but the values differ, an error will be emitted.
486    LLVMModuleFlagBehaviorOverride,
487    /// Appends the two values, which are required to be metadata nodes.
488    LLVMModuleFlagBehaviorAppend,
489    /// Appends the two values, which are required to be metadata nodes. However, duplicate entries in the second list are dropped during the append operation.
490    LLVMModuleFlagBehaviorAppendUnique,
491}
492
493pub const LLVMAttributeReturnIndex: ::libc::c_uint = 0;
494pub const LLVMAttributeFunctionIndex: ::libc::c_uint = !0; // -1
495/// Either LLVMAttributeReturnIndex, LLVMAttributeFunctionIndex, or a parameter
496/// number from 1 to N.
497pub type LLVMAttributeIndex = ::libc::c_uint;
498
499/// Tail call kind for LLVMSetTailCallKind and LLVMGetTailCallKind.
500///
501/// Note that `musttail` implies `tail`.
502#[repr(C)]
503#[derive(Clone, Copy, Debug, PartialEq)]
504pub enum LLVMTailCallKind {
505    LLVMTailCallKindNone = 0,
506    LLVMTailCallKindTail = 1,
507    LLVMTailCallKindMustTail = 2,
508    LLVMTailCallKindNoTail = 3,
509}
510
511pub const LLVMFastMathAllowReassoc: ::libc::c_uint = 1 << 0;
512pub const LLVMFastMathNoNaNs: ::libc::c_uint = 1 << 1;
513pub const LLVMFastMathNoInfs: ::libc::c_uint = 1 << 2;
514pub const LLVMFastMathNoSignedZeros: ::libc::c_uint = 1 << 3;
515pub const LLVMFastMathAllowReciprocal: ::libc::c_uint = 1 << 4;
516pub const LLVMFastMathAllowContract: ::libc::c_uint = 1 << 5;
517pub const LLVMFastMathApproxFunc: ::libc::c_uint = 1 << 6;
518pub const LLVMFastMathNone: ::libc::c_uint = 0;
519pub const LLVMFastMathAll: ::libc::c_uint = LLVMFastMathAllowReassoc
520    | LLVMFastMathNoNaNs
521    | LLVMFastMathNoInfs
522    | LLVMFastMathNoSignedZeros
523    | LLVMFastMathAllowReciprocal
524    | LLVMFastMathAllowContract
525    | LLVMFastMathApproxFunc;
526
527/// Flags to indicate what fast-math-style optimizations are allowed on operations.
528///
529/// See <https://llvm.org/docs/LangRef.html#fast-math-flags>
530pub type LLVMFastMathFlags = ::libc::c_uint;
531
532/// Flags that constrain the allowed wrap semantics of a gelementptr instruction.
533pub type LLVMGEPNoWrapFlags = ::libc::c_uint;
534
535#[repr(C)]
536#[derive(Clone, Copy, Debug, PartialEq)]
537pub enum LLVMDbgRecordKind {
538    LLVMDbgRecordLabel,
539    LLVMDbgRecordDeclare,
540    LLVMDbgRecordValue,
541    LLVMDbgRecordAssign,
542}
543
544#[repr(C)]
545#[derive(Clone, Copy, Debug, PartialEq)]
546pub enum LLVMDenormalModeKind {
547    LLVMDenormalModeKindIEEE = 0,
548    LLVMDenormalModeKindPreserveSign = 1,
549    LLVMDenormalModeKindPositiveZero = 2,
550    LLVMDenormalModeKindDynamic = 3,
551}
552
553pub const LLVMGEPFlagInBounds: LLVMGEPNoWrapFlags = 1;
554pub const LLVMGEPFlagNUSW: LLVMGEPNoWrapFlags = 1 << 1;
555pub const LLVMGEPFlagNUW: LLVMGEPNoWrapFlags = 1 << 2;
556
557pub type LLVMDiagnosticHandler =
558    Option<extern "C" fn(arg1: LLVMDiagnosticInfoRef, arg2: *mut ::libc::c_void)>;
559pub type LLVMYieldCallback = Option<extern "C" fn(arg1: LLVMContextRef, arg2: *mut ::libc::c_void)>;
560
561#[cfg(all(not(doc), not(feature = "no-llvm-linking"), LLVM_SYS_NOT_FOUND))]
562std::compile_error!(concat!(
563    "No suitable version of LLVM was found system-wide or pointed
564       to by LLVM_SYS_",
565    env!("CARGO_PKG_VERSION_MAJOR"),
566    "_PREFIX.
567
568       Consider using `llvmenv` to compile an appropriate copy of LLVM, and
569       refer to the llvm-sys documentation for more information.
570
571       llvm-sys: https://crates.io/crates/llvm-sys
572       llvmenv: https://crates.io/crates/llvmenv"
573));