rustc_codegen_llvm/llvm/
ffi.rs

1//! Bindings to the LLVM-C API (`LLVM*`), and to our own `extern "C"` wrapper
2//! functions around the unstable LLVM C++ API (`LLVMRust*`).
3//!
4//! ## Passing pointer/length strings as `*const c_uchar`
5//!
6//! Normally it's a good idea for Rust-side bindings to match the corresponding
7//! C-side function declarations as closely as possible. But when passing `&str`
8//! or `&[u8]` data as a pointer/length pair, it's more convenient to declare
9//! the Rust-side pointer as `*const c_uchar` instead of `*const c_char`.
10//! Both pointer types have the same ABI, and using `*const c_uchar` avoids
11//! the need for an extra cast from `*const u8` on the Rust side.
12
13#![allow(non_camel_case_types)]
14#![allow(non_upper_case_globals)]
15
16use std::fmt::Debug;
17use std::marker::PhantomData;
18use std::ptr;
19
20use bitflags::bitflags;
21use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};
22use rustc_macros::TryFromU32;
23use rustc_target::spec::SymbolVisibility;
24
25use super::RustString;
26use super::debuginfo::{
27    DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
28    DIFile, DIFlags, DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
29    DISubrange, DITemplateTypeParameter, DIType, DIVariable, DebugEmissionKind, DebugNameTableKind,
30};
31use crate::llvm;
32
33/// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`,
34/// which has a different ABI from Rust or C++ `bool`.
35pub type Bool = c_int;
36
37pub const True: Bool = 1 as Bool;
38pub const False: Bool = 0 as Bool;
39
40/// Wrapper for a raw enum value returned from LLVM's C APIs.
41///
42/// For C enums returned by LLVM, it's risky to use a Rust enum as the return
43/// type, because it would be UB if a later version of LLVM adds a new enum
44/// value and returns it. Instead, return this raw wrapper, then convert to the
45/// Rust-side enum explicitly.
46#[repr(transparent)]
47pub struct RawEnum<T> {
48    value: u32,
49    /// We don't own or consume a `T`, but we can produce one.
50    _rust_side_type: PhantomData<fn() -> T>,
51}
52
53impl<T: TryFrom<u32>> RawEnum<T> {
54    #[track_caller]
55    pub(crate) fn to_rust(self) -> T
56    where
57        T::Error: Debug,
58    {
59        // If this fails, the Rust-side enum is out of sync with LLVM's enum.
60        T::try_from(self.value).expect("enum value returned by LLVM should be known")
61    }
62}
63
64#[derive(Copy, Clone, PartialEq)]
65#[repr(C)]
66#[allow(dead_code)] // Variants constructed by C++.
67pub enum LLVMRustResult {
68    Success,
69    Failure,
70}
71
72/// Must match the layout of `LLVMRustModuleFlagMergeBehavior`.
73///
74/// When merging modules (e.g. during LTO), their metadata flags are combined. Conflicts are
75/// resolved according to the merge behaviors specified here. Flags differing only in merge
76/// behavior are still considered to be in conflict.
77///
78/// In order for Rust-C LTO to work, we must specify behaviors compatible with Clang. Notably,
79/// 'Error' and 'Warning' cannot be mixed for a given flag.
80///
81/// There is a stable LLVM-C version of this enum (`LLVMModuleFlagBehavior`),
82/// but as of LLVM 19 it does not support all of the enum values in the unstable
83/// C++ API.
84#[derive(Copy, Clone, PartialEq)]
85#[repr(C)]
86pub enum ModuleFlagMergeBehavior {
87    Error = 1,
88    Warning = 2,
89    Require = 3,
90    Override = 4,
91    Append = 5,
92    AppendUnique = 6,
93    Max = 7,
94    Min = 8,
95}
96
97// Consts for the LLVM CallConv type, pre-cast to usize.
98
99/// LLVM CallingConv::ID. Should we wrap this?
100///
101/// See <https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/CallingConv.h>
102#[derive(Copy, Clone, PartialEq, Debug, TryFromU32)]
103#[repr(C)]
104pub enum CallConv {
105    CCallConv = 0,
106    FastCallConv = 8,
107    ColdCallConv = 9,
108    PreserveMost = 14,
109    PreserveAll = 15,
110    Tail = 18,
111    X86StdcallCallConv = 64,
112    X86FastcallCallConv = 65,
113    ArmAapcsCallConv = 67,
114    Msp430Intr = 69,
115    X86_ThisCall = 70,
116    PtxKernel = 71,
117    X86_64_SysV = 78,
118    X86_64_Win64 = 79,
119    X86_VectorCall = 80,
120    X86_Intr = 83,
121    AvrNonBlockingInterrupt = 84,
122    AvrInterrupt = 85,
123    AmdgpuKernel = 91,
124}
125
126/// Must match the layout of `LLVMLinkage`.
127#[derive(Copy, Clone, PartialEq, TryFromU32)]
128#[repr(C)]
129pub enum Linkage {
130    ExternalLinkage = 0,
131    AvailableExternallyLinkage = 1,
132    LinkOnceAnyLinkage = 2,
133    LinkOnceODRLinkage = 3,
134    #[deprecated = "marked obsolete by LLVM"]
135    LinkOnceODRAutoHideLinkage = 4,
136    WeakAnyLinkage = 5,
137    WeakODRLinkage = 6,
138    AppendingLinkage = 7,
139    InternalLinkage = 8,
140    PrivateLinkage = 9,
141    #[deprecated = "marked obsolete by LLVM"]
142    DLLImportLinkage = 10,
143    #[deprecated = "marked obsolete by LLVM"]
144    DLLExportLinkage = 11,
145    ExternalWeakLinkage = 12,
146    #[deprecated = "marked obsolete by LLVM"]
147    GhostLinkage = 13,
148    CommonLinkage = 14,
149    LinkerPrivateLinkage = 15,
150    LinkerPrivateWeakLinkage = 16,
151}
152
153/// Must match the layout of `LLVMVisibility`.
154#[repr(C)]
155#[derive(Copy, Clone, PartialEq, TryFromU32)]
156pub enum Visibility {
157    Default = 0,
158    Hidden = 1,
159    Protected = 2,
160}
161
162impl Visibility {
163    pub(crate) fn from_generic(visibility: SymbolVisibility) -> Self {
164        match visibility {
165            SymbolVisibility::Hidden => Visibility::Hidden,
166            SymbolVisibility::Protected => Visibility::Protected,
167            SymbolVisibility::Interposable => Visibility::Default,
168        }
169    }
170}
171
172/// LLVMUnnamedAddr
173#[repr(C)]
174pub enum UnnamedAddr {
175    No,
176    Local,
177    Global,
178}
179
180/// LLVMDLLStorageClass
181#[derive(Copy, Clone)]
182#[repr(C)]
183pub enum DLLStorageClass {
184    #[allow(dead_code)]
185    Default = 0,
186    DllImport = 1, // Function to be imported from DLL.
187    #[allow(dead_code)]
188    DllExport = 2, // Function to be accessible from DLL.
189}
190
191/// Must match the layout of `LLVMRustAttributeKind`.
192/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
193/// though it is not ABI compatible (since it's a C++ enum)
194#[repr(C)]
195#[derive(Copy, Clone, Debug)]
196pub enum AttributeKind {
197    AlwaysInline = 0,
198    ByVal = 1,
199    Cold = 2,
200    InlineHint = 3,
201    MinSize = 4,
202    Naked = 5,
203    NoAlias = 6,
204    NoCapture = 7,
205    NoInline = 8,
206    NonNull = 9,
207    NoRedZone = 10,
208    NoReturn = 11,
209    NoUnwind = 12,
210    OptimizeForSize = 13,
211    ReadOnly = 14,
212    SExt = 15,
213    StructRet = 16,
214    UWTable = 17,
215    ZExt = 18,
216    InReg = 19,
217    SanitizeThread = 20,
218    SanitizeAddress = 21,
219    SanitizeMemory = 22,
220    NonLazyBind = 23,
221    OptimizeNone = 24,
222    ReadNone = 26,
223    SanitizeHWAddress = 28,
224    WillReturn = 29,
225    StackProtectReq = 30,
226    StackProtectStrong = 31,
227    StackProtect = 32,
228    NoUndef = 33,
229    SanitizeMemTag = 34,
230    NoCfCheck = 35,
231    ShadowCallStack = 36,
232    AllocSize = 37,
233    AllocatedPointer = 38,
234    AllocAlign = 39,
235    SanitizeSafeStack = 40,
236    FnRetThunkExtern = 41,
237    Writable = 42,
238    DeadOnUnwind = 43,
239}
240
241/// LLVMIntPredicate
242#[derive(Copy, Clone)]
243#[repr(C)]
244pub enum IntPredicate {
245    IntEQ = 32,
246    IntNE = 33,
247    IntUGT = 34,
248    IntUGE = 35,
249    IntULT = 36,
250    IntULE = 37,
251    IntSGT = 38,
252    IntSGE = 39,
253    IntSLT = 40,
254    IntSLE = 41,
255}
256
257impl IntPredicate {
258    pub(crate) fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
259        use rustc_codegen_ssa::common::IntPredicate as Common;
260        match intpre {
261            Common::IntEQ => Self::IntEQ,
262            Common::IntNE => Self::IntNE,
263            Common::IntUGT => Self::IntUGT,
264            Common::IntUGE => Self::IntUGE,
265            Common::IntULT => Self::IntULT,
266            Common::IntULE => Self::IntULE,
267            Common::IntSGT => Self::IntSGT,
268            Common::IntSGE => Self::IntSGE,
269            Common::IntSLT => Self::IntSLT,
270            Common::IntSLE => Self::IntSLE,
271        }
272    }
273}
274
275/// LLVMRealPredicate
276#[derive(Copy, Clone)]
277#[repr(C)]
278pub enum RealPredicate {
279    RealPredicateFalse = 0,
280    RealOEQ = 1,
281    RealOGT = 2,
282    RealOGE = 3,
283    RealOLT = 4,
284    RealOLE = 5,
285    RealONE = 6,
286    RealORD = 7,
287    RealUNO = 8,
288    RealUEQ = 9,
289    RealUGT = 10,
290    RealUGE = 11,
291    RealULT = 12,
292    RealULE = 13,
293    RealUNE = 14,
294    RealPredicateTrue = 15,
295}
296
297impl RealPredicate {
298    pub(crate) fn from_generic(realp: rustc_codegen_ssa::common::RealPredicate) -> Self {
299        use rustc_codegen_ssa::common::RealPredicate as Common;
300        match realp {
301            Common::RealPredicateFalse => Self::RealPredicateFalse,
302            Common::RealOEQ => Self::RealOEQ,
303            Common::RealOGT => Self::RealOGT,
304            Common::RealOGE => Self::RealOGE,
305            Common::RealOLT => Self::RealOLT,
306            Common::RealOLE => Self::RealOLE,
307            Common::RealONE => Self::RealONE,
308            Common::RealORD => Self::RealORD,
309            Common::RealUNO => Self::RealUNO,
310            Common::RealUEQ => Self::RealUEQ,
311            Common::RealUGT => Self::RealUGT,
312            Common::RealUGE => Self::RealUGE,
313            Common::RealULT => Self::RealULT,
314            Common::RealULE => Self::RealULE,
315            Common::RealUNE => Self::RealUNE,
316            Common::RealPredicateTrue => Self::RealPredicateTrue,
317        }
318    }
319}
320
321/// LLVMTypeKind
322#[derive(Copy, Clone, PartialEq, Debug)]
323#[repr(C)]
324pub enum TypeKind {
325    Void = 0,
326    Half = 1,
327    Float = 2,
328    Double = 3,
329    X86_FP80 = 4,
330    FP128 = 5,
331    PPC_FP128 = 6,
332    Label = 7,
333    Integer = 8,
334    Function = 9,
335    Struct = 10,
336    Array = 11,
337    Pointer = 12,
338    Vector = 13,
339    Metadata = 14,
340    Token = 16,
341    ScalableVector = 17,
342    BFloat = 18,
343    X86_AMX = 19,
344}
345
346impl TypeKind {
347    pub(crate) fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
348        use rustc_codegen_ssa::common::TypeKind as Common;
349        match self {
350            Self::Void => Common::Void,
351            Self::Half => Common::Half,
352            Self::Float => Common::Float,
353            Self::Double => Common::Double,
354            Self::X86_FP80 => Common::X86_FP80,
355            Self::FP128 => Common::FP128,
356            Self::PPC_FP128 => Common::PPC_FP128,
357            Self::Label => Common::Label,
358            Self::Integer => Common::Integer,
359            Self::Function => Common::Function,
360            Self::Struct => Common::Struct,
361            Self::Array => Common::Array,
362            Self::Pointer => Common::Pointer,
363            Self::Vector => Common::Vector,
364            Self::Metadata => Common::Metadata,
365            Self::Token => Common::Token,
366            Self::ScalableVector => Common::ScalableVector,
367            Self::BFloat => Common::BFloat,
368            Self::X86_AMX => Common::X86_AMX,
369        }
370    }
371}
372
373/// LLVMAtomicRmwBinOp
374#[derive(Copy, Clone)]
375#[repr(C)]
376pub enum AtomicRmwBinOp {
377    AtomicXchg = 0,
378    AtomicAdd = 1,
379    AtomicSub = 2,
380    AtomicAnd = 3,
381    AtomicNand = 4,
382    AtomicOr = 5,
383    AtomicXor = 6,
384    AtomicMax = 7,
385    AtomicMin = 8,
386    AtomicUMax = 9,
387    AtomicUMin = 10,
388}
389
390impl AtomicRmwBinOp {
391    pub(crate) fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
392        use rustc_codegen_ssa::common::AtomicRmwBinOp as Common;
393        match op {
394            Common::AtomicXchg => Self::AtomicXchg,
395            Common::AtomicAdd => Self::AtomicAdd,
396            Common::AtomicSub => Self::AtomicSub,
397            Common::AtomicAnd => Self::AtomicAnd,
398            Common::AtomicNand => Self::AtomicNand,
399            Common::AtomicOr => Self::AtomicOr,
400            Common::AtomicXor => Self::AtomicXor,
401            Common::AtomicMax => Self::AtomicMax,
402            Common::AtomicMin => Self::AtomicMin,
403            Common::AtomicUMax => Self::AtomicUMax,
404            Common::AtomicUMin => Self::AtomicUMin,
405        }
406    }
407}
408
409/// LLVMAtomicOrdering
410#[derive(Copy, Clone)]
411#[repr(C)]
412pub enum AtomicOrdering {
413    #[allow(dead_code)]
414    NotAtomic = 0,
415    Unordered = 1,
416    Monotonic = 2,
417    // Consume = 3,  // Not specified yet.
418    Acquire = 4,
419    Release = 5,
420    AcquireRelease = 6,
421    SequentiallyConsistent = 7,
422}
423
424impl AtomicOrdering {
425    pub(crate) fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
426        use rustc_codegen_ssa::common::AtomicOrdering as Common;
427        match ao {
428            Common::Unordered => Self::Unordered,
429            Common::Relaxed => Self::Monotonic,
430            Common::Acquire => Self::Acquire,
431            Common::Release => Self::Release,
432            Common::AcquireRelease => Self::AcquireRelease,
433            Common::SequentiallyConsistent => Self::SequentiallyConsistent,
434        }
435    }
436}
437
438/// LLVMRustFileType
439#[derive(Copy, Clone)]
440#[repr(C)]
441pub enum FileType {
442    AssemblyFile,
443    ObjectFile,
444}
445
446/// LLVMMetadataType
447#[derive(Copy, Clone)]
448#[repr(C)]
449pub enum MetadataType {
450    MD_dbg = 0,
451    MD_tbaa = 1,
452    MD_prof = 2,
453    MD_fpmath = 3,
454    MD_range = 4,
455    MD_tbaa_struct = 5,
456    MD_invariant_load = 6,
457    MD_alias_scope = 7,
458    MD_noalias = 8,
459    MD_nontemporal = 9,
460    MD_mem_parallel_loop_access = 10,
461    MD_nonnull = 11,
462    MD_unpredictable = 15,
463    MD_align = 17,
464    MD_type = 19,
465    MD_vcall_visibility = 28,
466    MD_noundef = 29,
467    MD_kcfi_type = 36,
468}
469
470/// LLVMRustAsmDialect
471#[derive(Copy, Clone, PartialEq)]
472#[repr(C)]
473pub enum AsmDialect {
474    Att,
475    Intel,
476}
477
478/// LLVMRustCodeGenOptLevel
479#[derive(Copy, Clone, PartialEq)]
480#[repr(C)]
481pub enum CodeGenOptLevel {
482    None,
483    Less,
484    Default,
485    Aggressive,
486}
487
488/// LLVMRustPassBuilderOptLevel
489#[repr(C)]
490pub enum PassBuilderOptLevel {
491    O0,
492    O1,
493    O2,
494    O3,
495    Os,
496    Oz,
497}
498
499/// LLVMRustOptStage
500#[derive(PartialEq)]
501#[repr(C)]
502pub enum OptStage {
503    PreLinkNoLTO,
504    PreLinkThinLTO,
505    PreLinkFatLTO,
506    ThinLTO,
507    FatLTO,
508}
509
510/// LLVMRustSanitizerOptions
511#[repr(C)]
512pub struct SanitizerOptions {
513    pub sanitize_address: bool,
514    pub sanitize_address_recover: bool,
515    pub sanitize_cfi: bool,
516    pub sanitize_dataflow: bool,
517    pub sanitize_dataflow_abilist: *const *const c_char,
518    pub sanitize_dataflow_abilist_len: size_t,
519    pub sanitize_kcfi: bool,
520    pub sanitize_memory: bool,
521    pub sanitize_memory_recover: bool,
522    pub sanitize_memory_track_origins: c_int,
523    pub sanitize_thread: bool,
524    pub sanitize_hwaddress: bool,
525    pub sanitize_hwaddress_recover: bool,
526    pub sanitize_kernel_address: bool,
527    pub sanitize_kernel_address_recover: bool,
528}
529
530/// LLVMRustRelocModel
531#[derive(Copy, Clone, PartialEq)]
532#[repr(C)]
533pub enum RelocModel {
534    Static,
535    PIC,
536    DynamicNoPic,
537    ROPI,
538    RWPI,
539    ROPI_RWPI,
540}
541
542/// LLVMRustFloatABI
543#[derive(Copy, Clone, PartialEq)]
544#[repr(C)]
545pub enum FloatAbi {
546    Default,
547    Soft,
548    Hard,
549}
550
551/// LLVMRustCodeModel
552#[derive(Copy, Clone)]
553#[repr(C)]
554pub enum CodeModel {
555    Tiny,
556    Small,
557    Kernel,
558    Medium,
559    Large,
560    None,
561}
562
563/// LLVMRustDiagnosticKind
564#[derive(Copy, Clone)]
565#[repr(C)]
566#[allow(dead_code)] // Variants constructed by C++.
567pub enum DiagnosticKind {
568    Other,
569    InlineAsm,
570    StackSize,
571    DebugMetadataVersion,
572    SampleProfile,
573    OptimizationRemark,
574    OptimizationRemarkMissed,
575    OptimizationRemarkAnalysis,
576    OptimizationRemarkAnalysisFPCommute,
577    OptimizationRemarkAnalysisAliasing,
578    OptimizationRemarkOther,
579    OptimizationFailure,
580    PGOProfile,
581    Linker,
582    Unsupported,
583    SrcMgr,
584}
585
586/// LLVMRustDiagnosticLevel
587#[derive(Copy, Clone)]
588#[repr(C)]
589#[allow(dead_code)] // Variants constructed by C++.
590pub enum DiagnosticLevel {
591    Error,
592    Warning,
593    Note,
594    Remark,
595}
596
597/// LLVMRustArchiveKind
598#[derive(Copy, Clone)]
599#[repr(C)]
600pub enum ArchiveKind {
601    K_GNU,
602    K_BSD,
603    K_DARWIN,
604    K_COFF,
605    K_AIXBIG,
606}
607
608unsafe extern "C" {
609    // LLVMRustThinLTOData
610    pub type ThinLTOData;
611
612    // LLVMRustThinLTOBuffer
613    pub type ThinLTOBuffer;
614}
615
616/// LLVMRustThinLTOModule
617#[repr(C)]
618pub struct ThinLTOModule {
619    pub identifier: *const c_char,
620    pub data: *const u8,
621    pub len: usize,
622}
623
624/// LLVMThreadLocalMode
625#[derive(Copy, Clone)]
626#[repr(C)]
627pub enum ThreadLocalMode {
628    NotThreadLocal,
629    GeneralDynamic,
630    LocalDynamic,
631    InitialExec,
632    LocalExec,
633}
634
635/// LLVMRustChecksumKind
636#[derive(Copy, Clone)]
637#[repr(C)]
638pub enum ChecksumKind {
639    None,
640    MD5,
641    SHA1,
642    SHA256,
643}
644
645/// LLVMRustMemoryEffects
646#[derive(Copy, Clone)]
647#[repr(C)]
648pub enum MemoryEffects {
649    None,
650    ReadOnly,
651    InaccessibleMemOnly,
652}
653
654/// LLVMOpcode
655#[derive(Copy, Clone, PartialEq, Eq)]
656#[repr(C)]
657pub enum Opcode {
658    Ret = 1,
659    Br = 2,
660    Switch = 3,
661    IndirectBr = 4,
662    Invoke = 5,
663    Unreachable = 7,
664    CallBr = 67,
665    FNeg = 66,
666    Add = 8,
667    FAdd = 9,
668    Sub = 10,
669    FSub = 11,
670    Mul = 12,
671    FMul = 13,
672    UDiv = 14,
673    SDiv = 15,
674    FDiv = 16,
675    URem = 17,
676    SRem = 18,
677    FRem = 19,
678    Shl = 20,
679    LShr = 21,
680    AShr = 22,
681    And = 23,
682    Or = 24,
683    Xor = 25,
684    Alloca = 26,
685    Load = 27,
686    Store = 28,
687    GetElementPtr = 29,
688    Trunc = 30,
689    ZExt = 31,
690    SExt = 32,
691    FPToUI = 33,
692    FPToSI = 34,
693    UIToFP = 35,
694    SIToFP = 36,
695    FPTrunc = 37,
696    FPExt = 38,
697    PtrToInt = 39,
698    IntToPtr = 40,
699    BitCast = 41,
700    AddrSpaceCast = 60,
701    ICmp = 42,
702    FCmp = 43,
703    PHI = 44,
704    Call = 45,
705    Select = 46,
706    UserOp1 = 47,
707    UserOp2 = 48,
708    VAArg = 49,
709    ExtractElement = 50,
710    InsertElement = 51,
711    ShuffleVector = 52,
712    ExtractValue = 53,
713    InsertValue = 54,
714    Freeze = 68,
715    Fence = 55,
716    AtomicCmpXchg = 56,
717    AtomicRMW = 57,
718    Resume = 58,
719    LandingPad = 59,
720    CleanupRet = 61,
721    CatchRet = 62,
722    CatchPad = 63,
723    CleanupPad = 64,
724    CatchSwitch = 65,
725}
726
727unsafe extern "C" {
728    type Opaque;
729}
730#[repr(C)]
731struct InvariantOpaque<'a> {
732    _marker: PhantomData<&'a mut &'a ()>,
733    _opaque: Opaque,
734}
735
736// Opaque pointer types
737unsafe extern "C" {
738    pub type Module;
739    pub type Context;
740    pub type Type;
741    pub type Value;
742    pub type ConstantInt;
743    pub type Attribute;
744    pub type Metadata;
745    pub type BasicBlock;
746    pub type Comdat;
747}
748#[repr(C)]
749pub struct Builder<'a>(InvariantOpaque<'a>);
750#[repr(C)]
751pub struct PassManager<'a>(InvariantOpaque<'a>);
752unsafe extern "C" {
753    pub type TargetMachine;
754    pub type Archive;
755}
756#[repr(C)]
757pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
758#[repr(C)]
759pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
760unsafe extern "C" {
761    pub type Twine;
762    pub type DiagnosticInfo;
763    pub type SMDiagnostic;
764}
765#[repr(C)]
766pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
767/// Opaque pointee of `LLVMOperandBundleRef`.
768#[repr(C)]
769pub(crate) struct OperandBundle<'a>(InvariantOpaque<'a>);
770#[repr(C)]
771pub struct Linker<'a>(InvariantOpaque<'a>);
772
773unsafe extern "C" {
774    pub type DiagnosticHandler;
775}
776
777pub type DiagnosticHandlerTy = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
778
779pub mod debuginfo {
780    use std::ptr;
781
782    use bitflags::bitflags;
783
784    use super::{InvariantOpaque, Metadata};
785    use crate::llvm::{self, Module};
786
787    /// Opaque target type for references to an LLVM debuginfo builder.
788    ///
789    /// `&'_ DIBuilder<'ll>` corresponds to `LLVMDIBuilderRef`, which is the
790    /// LLVM-C wrapper for `DIBuilder *`.
791    ///
792    /// Debuginfo builders are created and destroyed during codegen, so the
793    /// builder reference typically has a shorter lifetime than the LLVM
794    /// session (`'ll`) that it participates in.
795    #[repr(C)]
796    pub struct DIBuilder<'ll>(InvariantOpaque<'ll>);
797
798    /// Owning pointer to a `DIBuilder<'ll>` that will dispose of the builder
799    /// when dropped. Use `.as_ref()` to get the underlying `&DIBuilder`
800    /// needed for debuginfo FFI calls.
801    pub(crate) struct DIBuilderBox<'ll> {
802        raw: ptr::NonNull<DIBuilder<'ll>>,
803    }
804
805    impl<'ll> DIBuilderBox<'ll> {
806        pub(crate) fn new(llmod: &'ll Module) -> Self {
807            let raw = unsafe { llvm::LLVMCreateDIBuilder(llmod) };
808            let raw = ptr::NonNull::new(raw).unwrap();
809            Self { raw }
810        }
811
812        pub(crate) fn as_ref(&self) -> &DIBuilder<'ll> {
813            // SAFETY: This is an owning pointer, so `&DIBuilder` is valid
814            // for as long as `&self` is.
815            unsafe { self.raw.as_ref() }
816        }
817    }
818
819    impl<'ll> Drop for DIBuilderBox<'ll> {
820        fn drop(&mut self) {
821            unsafe { llvm::LLVMDisposeDIBuilder(self.raw) };
822        }
823    }
824
825    pub type DIDescriptor = Metadata;
826    pub type DILocation = Metadata;
827    pub type DIScope = DIDescriptor;
828    pub type DIFile = DIScope;
829    pub type DILexicalBlock = DIScope;
830    pub type DISubprogram = DIScope;
831    pub type DIType = DIDescriptor;
832    pub type DIBasicType = DIType;
833    pub type DIDerivedType = DIType;
834    pub type DICompositeType = DIDerivedType;
835    pub type DIVariable = DIDescriptor;
836    pub type DIGlobalVariableExpression = DIDescriptor;
837    pub type DIArray = DIDescriptor;
838    pub type DISubrange = DIDescriptor;
839    pub type DIEnumerator = DIDescriptor;
840    pub type DITemplateTypeParameter = DIDescriptor;
841
842    bitflags! {
843        /// Must match the layout of `LLVMDIFlags` in the LLVM-C API.
844        ///
845        /// Each value declared here must also be covered by the static
846        /// assertions in `RustWrapper.cpp` used by `fromRust(LLVMDIFlags)`.
847        #[repr(transparent)]
848        #[derive(Clone, Copy, Default)]
849        pub struct DIFlags: u32 {
850            const FlagZero                = 0;
851            const FlagPrivate             = 1;
852            const FlagProtected           = 2;
853            const FlagPublic              = 3;
854            const FlagFwdDecl             = (1 << 2);
855            const FlagAppleBlock          = (1 << 3);
856            const FlagReservedBit4        = (1 << 4);
857            const FlagVirtual             = (1 << 5);
858            const FlagArtificial          = (1 << 6);
859            const FlagExplicit            = (1 << 7);
860            const FlagPrototyped          = (1 << 8);
861            const FlagObjcClassComplete   = (1 << 9);
862            const FlagObjectPointer       = (1 << 10);
863            const FlagVector              = (1 << 11);
864            const FlagStaticMember        = (1 << 12);
865            const FlagLValueReference     = (1 << 13);
866            const FlagRValueReference     = (1 << 14);
867            const FlagReserved            = (1 << 15);
868            const FlagSingleInheritance   = (1 << 16);
869            const FlagMultipleInheritance = (2 << 16);
870            const FlagVirtualInheritance  = (3 << 16);
871            const FlagIntroducedVirtual   = (1 << 18);
872            const FlagBitField            = (1 << 19);
873            const FlagNoReturn            = (1 << 20);
874            // The bit at (1 << 21) is unused, but was `LLVMDIFlagMainSubprogram`.
875            const FlagTypePassByValue     = (1 << 22);
876            const FlagTypePassByReference = (1 << 23);
877            const FlagEnumClass           = (1 << 24);
878            const FlagThunk               = (1 << 25);
879            const FlagNonTrivial          = (1 << 26);
880            const FlagBigEndian           = (1 << 27);
881            const FlagLittleEndian        = (1 << 28);
882        }
883    }
884
885    // These values **must** match with LLVMRustDISPFlags!!
886    bitflags! {
887        #[repr(transparent)]
888        #[derive(Clone, Copy, Default)]
889        pub struct DISPFlags: u32 {
890            const SPFlagZero              = 0;
891            const SPFlagVirtual           = 1;
892            const SPFlagPureVirtual       = 2;
893            const SPFlagLocalToUnit       = (1 << 2);
894            const SPFlagDefinition        = (1 << 3);
895            const SPFlagOptimized         = (1 << 4);
896            const SPFlagMainSubprogram    = (1 << 5);
897        }
898    }
899
900    /// LLVMRustDebugEmissionKind
901    #[derive(Copy, Clone)]
902    #[repr(C)]
903    pub enum DebugEmissionKind {
904        NoDebug,
905        FullDebug,
906        LineTablesOnly,
907        DebugDirectivesOnly,
908    }
909
910    impl DebugEmissionKind {
911        pub(crate) fn from_generic(kind: rustc_session::config::DebugInfo) -> Self {
912            // We should be setting LLVM's emission kind to `LineTablesOnly` if
913            // we are compiling with "limited" debuginfo. However, some of the
914            // existing tools relied on slightly more debuginfo being generated than
915            // would be the case with `LineTablesOnly`, and we did not want to break
916            // these tools in a "drive-by fix", without a good idea or plan about
917            // what limited debuginfo should exactly look like. So for now we are
918            // instead adding a new debuginfo option "line-tables-only" so as to
919            // not break anything and to allow users to have 'limited' debug info.
920            //
921            // See https://github.com/rust-lang/rust/issues/60020 for details.
922            use rustc_session::config::DebugInfo;
923            match kind {
924                DebugInfo::None => DebugEmissionKind::NoDebug,
925                DebugInfo::LineDirectivesOnly => DebugEmissionKind::DebugDirectivesOnly,
926                DebugInfo::LineTablesOnly => DebugEmissionKind::LineTablesOnly,
927                DebugInfo::Limited | DebugInfo::Full => DebugEmissionKind::FullDebug,
928            }
929        }
930    }
931
932    /// LLVMRustDebugNameTableKind
933    #[derive(Clone, Copy)]
934    #[repr(C)]
935    pub enum DebugNameTableKind {
936        Default,
937        Gnu,
938        None,
939    }
940}
941
942// These values **must** match with LLVMRustAllocKindFlags
943bitflags! {
944    #[repr(transparent)]
945    #[derive(Default)]
946    pub struct AllocKindFlags : u64 {
947        const Unknown = 0;
948        const Alloc = 1;
949        const Realloc = 1 << 1;
950        const Free = 1 << 2;
951        const Uninitialized = 1 << 3;
952        const Zeroed = 1 << 4;
953        const Aligned = 1 << 5;
954    }
955}
956
957// These values **must** match with LLVMGEPNoWrapFlags
958bitflags! {
959    #[repr(transparent)]
960    #[derive(Default)]
961    pub struct GEPNoWrapFlags : c_uint {
962        const InBounds = 1 << 0;
963        const NUSW = 1 << 1;
964        const NUW = 1 << 2;
965    }
966}
967
968unsafe extern "C" {
969    pub type ModuleBuffer;
970}
971
972pub type SelfProfileBeforePassCallback =
973    unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
974pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
975
976pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
977pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
978
979#[derive(Copy, Clone)]
980#[repr(transparent)]
981pub struct MetadataKindId(c_uint);
982
983impl From<MetadataType> for MetadataKindId {
984    fn from(value: MetadataType) -> Self {
985        Self(value as c_uint)
986    }
987}
988
989unsafe extern "C" {
990    // Create and destroy contexts.
991    pub(crate) fn LLVMContextDispose(C: &'static mut Context);
992    pub(crate) fn LLVMGetMDKindIDInContext(
993        C: &Context,
994        Name: *const c_char,
995        SLen: c_uint,
996    ) -> MetadataKindId;
997
998    // Create modules.
999    pub(crate) fn LLVMModuleCreateWithNameInContext(
1000        ModuleID: *const c_char,
1001        C: &Context,
1002    ) -> &Module;
1003    pub(crate) fn LLVMCloneModule(M: &Module) -> &Module;
1004
1005    /// Data layout. See Module::getDataLayout.
1006    pub(crate) fn LLVMGetDataLayoutStr(M: &Module) -> *const c_char;
1007    pub(crate) fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
1008
1009    /// See Module::setModuleInlineAsm.
1010    pub(crate) fn LLVMAppendModuleInlineAsm(M: &Module, Asm: *const c_char, Len: size_t);
1011
1012    // Operations on integer types
1013    pub(crate) fn LLVMInt1TypeInContext(C: &Context) -> &Type;
1014    pub(crate) fn LLVMInt8TypeInContext(C: &Context) -> &Type;
1015    pub(crate) fn LLVMInt16TypeInContext(C: &Context) -> &Type;
1016    pub(crate) fn LLVMInt32TypeInContext(C: &Context) -> &Type;
1017    pub(crate) fn LLVMInt64TypeInContext(C: &Context) -> &Type;
1018    pub(crate) fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
1019
1020    pub(crate) fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
1021
1022    // Operations on real types
1023    pub(crate) fn LLVMHalfTypeInContext(C: &Context) -> &Type;
1024    pub(crate) fn LLVMFloatTypeInContext(C: &Context) -> &Type;
1025    pub(crate) fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
1026    pub(crate) fn LLVMFP128TypeInContext(C: &Context) -> &Type;
1027
1028    // Operations on function types
1029    pub(crate) fn LLVMFunctionType<'a>(
1030        ReturnType: &'a Type,
1031        ParamTypes: *const &'a Type,
1032        ParamCount: c_uint,
1033        IsVarArg: Bool,
1034    ) -> &'a Type;
1035    pub(crate) fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
1036    pub(crate) fn LLVMGetParamTypes<'a>(FunctionTy: &'a Type, Dest: *mut &'a Type);
1037
1038    // Operations on struct types
1039    pub(crate) fn LLVMStructTypeInContext<'a>(
1040        C: &'a Context,
1041        ElementTypes: *const &'a Type,
1042        ElementCount: c_uint,
1043        Packed: Bool,
1044    ) -> &'a Type;
1045
1046    // Operations on array, pointer, and vector types (sequence types)
1047    pub(crate) fn LLVMPointerTypeInContext(C: &Context, AddressSpace: c_uint) -> &Type;
1048    pub(crate) fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
1049
1050    pub(crate) fn LLVMGetElementType(Ty: &Type) -> &Type;
1051    pub(crate) fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
1052
1053    // Operations on other types
1054    pub(crate) fn LLVMVoidTypeInContext(C: &Context) -> &Type;
1055    pub(crate) fn LLVMTokenTypeInContext(C: &Context) -> &Type;
1056    pub(crate) fn LLVMMetadataTypeInContext(C: &Context) -> &Type;
1057
1058    // Operations on all values
1059    pub(crate) fn LLVMTypeOf(Val: &Value) -> &Type;
1060    pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char;
1061    pub(crate) fn LLVMSetValueName2(Val: &Value, Name: *const c_char, NameLen: size_t);
1062    pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value);
1063    pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value);
1064    pub(crate) fn LLVMGlobalSetMetadata<'a>(Val: &'a Value, KindID: c_uint, Metadata: &'a Metadata);
1065    pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata;
1066
1067    // Operations on constants of any type
1068    pub(crate) fn LLVMConstNull(Ty: &Type) -> &Value;
1069    pub(crate) fn LLVMGetUndef(Ty: &Type) -> &Value;
1070    pub(crate) fn LLVMGetPoison(Ty: &Type) -> &Value;
1071
1072    // Operations on metadata
1073    pub(crate) fn LLVMMDStringInContext2(
1074        C: &Context,
1075        Str: *const c_char,
1076        SLen: size_t,
1077    ) -> &Metadata;
1078    pub(crate) fn LLVMMDNodeInContext2<'a>(
1079        C: &'a Context,
1080        Vals: *const &'a Metadata,
1081        Count: size_t,
1082    ) -> &'a Metadata;
1083    pub(crate) fn LLVMAddNamedMetadataOperand<'a>(
1084        M: &'a Module,
1085        Name: *const c_char,
1086        Val: &'a Value,
1087    );
1088
1089    // Operations on scalar constants
1090    pub(crate) fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
1091    pub(crate) fn LLVMConstIntOfArbitraryPrecision(
1092        IntTy: &Type,
1093        Wn: c_uint,
1094        Ws: *const u64,
1095    ) -> &Value;
1096    pub(crate) fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
1097
1098    // Operations on composite constants
1099    pub(crate) fn LLVMConstArray2<'a>(
1100        ElementTy: &'a Type,
1101        ConstantVals: *const &'a Value,
1102        Length: u64,
1103    ) -> &'a Value;
1104    pub(crate) fn LLVMArrayType2(ElementType: &Type, ElementCount: u64) -> &Type;
1105    pub(crate) fn LLVMConstStringInContext2(
1106        C: &Context,
1107        Str: *const c_char,
1108        Length: size_t,
1109        DontNullTerminate: Bool,
1110    ) -> &Value;
1111    pub(crate) fn LLVMConstStructInContext<'a>(
1112        C: &'a Context,
1113        ConstantVals: *const &'a Value,
1114        Count: c_uint,
1115        Packed: Bool,
1116    ) -> &'a Value;
1117    pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
1118
1119    // Constant expressions
1120    pub(crate) fn LLVMConstInBoundsGEP2<'a>(
1121        ty: &'a Type,
1122        ConstantVal: &'a Value,
1123        ConstantIndices: *const &'a Value,
1124        NumIndices: c_uint,
1125    ) -> &'a Value;
1126    pub(crate) fn LLVMConstPtrToInt<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1127    pub(crate) fn LLVMConstIntToPtr<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1128    pub(crate) fn LLVMConstBitCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1129    pub(crate) fn LLVMConstPointerCast<'a>(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
1130    pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>;
1131    pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode;
1132    pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>;
1133
1134    // Operations on global variables, functions, and aliases (globals)
1135    pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool;
1136    pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum<Linkage>;
1137    pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage);
1138    pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char);
1139    pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum<Visibility>;
1140    pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility);
1141    pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint;
1142    pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
1143    pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
1144    pub(crate) fn LLVMGlobalGetValueType(Global: &Value) -> &Type;
1145
1146    // Operations on global variables
1147    pub(crate) fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
1148    pub(crate) fn LLVMAddGlobal<'a>(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1149    pub(crate) fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
1150    pub(crate) fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
1151    pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
1152    pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value);
1153    pub(crate) fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
1154    pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value);
1155    pub(crate) fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool;
1156    pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
1157    pub(crate) fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
1158    pub(crate) fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
1159    pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
1160
1161    // Operations on attributes
1162    pub(crate) fn LLVMCreateStringAttribute(
1163        C: &Context,
1164        Name: *const c_char,
1165        NameLen: c_uint,
1166        Value: *const c_char,
1167        ValueLen: c_uint,
1168    ) -> &Attribute;
1169
1170    // Operations on functions
1171    pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
1172
1173    // Operations on parameters
1174    pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>;
1175    pub(crate) fn LLVMCountParams(Fn: &Value) -> c_uint;
1176    pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
1177
1178    // Operations on basic blocks
1179    pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
1180    pub(crate) fn LLVMAppendBasicBlockInContext<'a>(
1181        C: &'a Context,
1182        Fn: &'a Value,
1183        Name: *const c_char,
1184    ) -> &'a BasicBlock;
1185
1186    // Operations on instructions
1187    pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>;
1188    pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
1189    pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>;
1190
1191    // Operations on call sites
1192    pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
1193
1194    // Operations on load/store instructions (only)
1195    pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
1196
1197    // Operations on phi nodes
1198    pub(crate) fn LLVMAddIncoming<'a>(
1199        PhiNode: &'a Value,
1200        IncomingValues: *const &'a Value,
1201        IncomingBlocks: *const &'a BasicBlock,
1202        Count: c_uint,
1203    );
1204
1205    // Instruction builders
1206    pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1207    pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
1208    pub(crate) fn LLVMGetInsertBlock<'a>(Builder: &Builder<'a>) -> &'a BasicBlock;
1209    pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
1210
1211    // Metadata
1212    pub(crate) fn LLVMSetCurrentDebugLocation2<'a>(Builder: &Builder<'a>, Loc: *const Metadata);
1213    pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>;
1214
1215    // Terminators
1216    pub(crate) safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value;
1217    pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value;
1218    pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
1219    pub(crate) fn LLVMBuildCondBr<'a>(
1220        B: &Builder<'a>,
1221        If: &'a Value,
1222        Then: &'a BasicBlock,
1223        Else: &'a BasicBlock,
1224    ) -> &'a Value;
1225    pub(crate) fn LLVMBuildSwitch<'a>(
1226        B: &Builder<'a>,
1227        V: &'a Value,
1228        Else: &'a BasicBlock,
1229        NumCases: c_uint,
1230    ) -> &'a Value;
1231    pub(crate) fn LLVMBuildLandingPad<'a>(
1232        B: &Builder<'a>,
1233        Ty: &'a Type,
1234        PersFn: Option<&'a Value>,
1235        NumClauses: c_uint,
1236        Name: *const c_char,
1237    ) -> &'a Value;
1238    pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
1239    pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value;
1240
1241    pub(crate) fn LLVMBuildCleanupPad<'a>(
1242        B: &Builder<'a>,
1243        ParentPad: Option<&'a Value>,
1244        Args: *const &'a Value,
1245        NumArgs: c_uint,
1246        Name: *const c_char,
1247    ) -> Option<&'a Value>;
1248    pub(crate) fn LLVMBuildCleanupRet<'a>(
1249        B: &Builder<'a>,
1250        CleanupPad: &'a Value,
1251        BB: Option<&'a BasicBlock>,
1252    ) -> Option<&'a Value>;
1253    pub(crate) fn LLVMBuildCatchPad<'a>(
1254        B: &Builder<'a>,
1255        ParentPad: &'a Value,
1256        Args: *const &'a Value,
1257        NumArgs: c_uint,
1258        Name: *const c_char,
1259    ) -> Option<&'a Value>;
1260    pub(crate) fn LLVMBuildCatchRet<'a>(
1261        B: &Builder<'a>,
1262        CatchPad: &'a Value,
1263        BB: &'a BasicBlock,
1264    ) -> Option<&'a Value>;
1265    pub(crate) fn LLVMBuildCatchSwitch<'a>(
1266        Builder: &Builder<'a>,
1267        ParentPad: Option<&'a Value>,
1268        UnwindBB: Option<&'a BasicBlock>,
1269        NumHandlers: c_uint,
1270        Name: *const c_char,
1271    ) -> Option<&'a Value>;
1272    pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock);
1273    pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value);
1274
1275    // Add a case to the switch instruction
1276    pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
1277
1278    // Add a clause to the landing pad instruction
1279    pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value);
1280
1281    // Set the cleanup on a landing pad instruction
1282    pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
1283
1284    // Arithmetic
1285    pub(crate) fn LLVMBuildAdd<'a>(
1286        B: &Builder<'a>,
1287        LHS: &'a Value,
1288        RHS: &'a Value,
1289        Name: *const c_char,
1290    ) -> &'a Value;
1291    pub(crate) fn LLVMBuildFAdd<'a>(
1292        B: &Builder<'a>,
1293        LHS: &'a Value,
1294        RHS: &'a Value,
1295        Name: *const c_char,
1296    ) -> &'a Value;
1297    pub(crate) fn LLVMBuildSub<'a>(
1298        B: &Builder<'a>,
1299        LHS: &'a Value,
1300        RHS: &'a Value,
1301        Name: *const c_char,
1302    ) -> &'a Value;
1303    pub(crate) fn LLVMBuildFSub<'a>(
1304        B: &Builder<'a>,
1305        LHS: &'a Value,
1306        RHS: &'a Value,
1307        Name: *const c_char,
1308    ) -> &'a Value;
1309    pub(crate) fn LLVMBuildMul<'a>(
1310        B: &Builder<'a>,
1311        LHS: &'a Value,
1312        RHS: &'a Value,
1313        Name: *const c_char,
1314    ) -> &'a Value;
1315    pub(crate) fn LLVMBuildFMul<'a>(
1316        B: &Builder<'a>,
1317        LHS: &'a Value,
1318        RHS: &'a Value,
1319        Name: *const c_char,
1320    ) -> &'a Value;
1321    pub(crate) fn LLVMBuildUDiv<'a>(
1322        B: &Builder<'a>,
1323        LHS: &'a Value,
1324        RHS: &'a Value,
1325        Name: *const c_char,
1326    ) -> &'a Value;
1327    pub(crate) fn LLVMBuildExactUDiv<'a>(
1328        B: &Builder<'a>,
1329        LHS: &'a Value,
1330        RHS: &'a Value,
1331        Name: *const c_char,
1332    ) -> &'a Value;
1333    pub(crate) fn LLVMBuildSDiv<'a>(
1334        B: &Builder<'a>,
1335        LHS: &'a Value,
1336        RHS: &'a Value,
1337        Name: *const c_char,
1338    ) -> &'a Value;
1339    pub(crate) fn LLVMBuildExactSDiv<'a>(
1340        B: &Builder<'a>,
1341        LHS: &'a Value,
1342        RHS: &'a Value,
1343        Name: *const c_char,
1344    ) -> &'a Value;
1345    pub(crate) fn LLVMBuildFDiv<'a>(
1346        B: &Builder<'a>,
1347        LHS: &'a Value,
1348        RHS: &'a Value,
1349        Name: *const c_char,
1350    ) -> &'a Value;
1351    pub(crate) fn LLVMBuildURem<'a>(
1352        B: &Builder<'a>,
1353        LHS: &'a Value,
1354        RHS: &'a Value,
1355        Name: *const c_char,
1356    ) -> &'a Value;
1357    pub(crate) fn LLVMBuildSRem<'a>(
1358        B: &Builder<'a>,
1359        LHS: &'a Value,
1360        RHS: &'a Value,
1361        Name: *const c_char,
1362    ) -> &'a Value;
1363    pub(crate) fn LLVMBuildFRem<'a>(
1364        B: &Builder<'a>,
1365        LHS: &'a Value,
1366        RHS: &'a Value,
1367        Name: *const c_char,
1368    ) -> &'a Value;
1369    pub(crate) fn LLVMBuildShl<'a>(
1370        B: &Builder<'a>,
1371        LHS: &'a Value,
1372        RHS: &'a Value,
1373        Name: *const c_char,
1374    ) -> &'a Value;
1375    pub(crate) fn LLVMBuildLShr<'a>(
1376        B: &Builder<'a>,
1377        LHS: &'a Value,
1378        RHS: &'a Value,
1379        Name: *const c_char,
1380    ) -> &'a Value;
1381    pub(crate) fn LLVMBuildAShr<'a>(
1382        B: &Builder<'a>,
1383        LHS: &'a Value,
1384        RHS: &'a Value,
1385        Name: *const c_char,
1386    ) -> &'a Value;
1387    pub(crate) fn LLVMBuildNSWAdd<'a>(
1388        B: &Builder<'a>,
1389        LHS: &'a Value,
1390        RHS: &'a Value,
1391        Name: *const c_char,
1392    ) -> &'a Value;
1393    pub(crate) fn LLVMBuildNUWAdd<'a>(
1394        B: &Builder<'a>,
1395        LHS: &'a Value,
1396        RHS: &'a Value,
1397        Name: *const c_char,
1398    ) -> &'a Value;
1399    pub(crate) fn LLVMBuildNSWSub<'a>(
1400        B: &Builder<'a>,
1401        LHS: &'a Value,
1402        RHS: &'a Value,
1403        Name: *const c_char,
1404    ) -> &'a Value;
1405    pub(crate) fn LLVMBuildNUWSub<'a>(
1406        B: &Builder<'a>,
1407        LHS: &'a Value,
1408        RHS: &'a Value,
1409        Name: *const c_char,
1410    ) -> &'a Value;
1411    pub(crate) fn LLVMBuildNSWMul<'a>(
1412        B: &Builder<'a>,
1413        LHS: &'a Value,
1414        RHS: &'a Value,
1415        Name: *const c_char,
1416    ) -> &'a Value;
1417    pub(crate) fn LLVMBuildNUWMul<'a>(
1418        B: &Builder<'a>,
1419        LHS: &'a Value,
1420        RHS: &'a Value,
1421        Name: *const c_char,
1422    ) -> &'a Value;
1423    pub(crate) fn LLVMBuildAnd<'a>(
1424        B: &Builder<'a>,
1425        LHS: &'a Value,
1426        RHS: &'a Value,
1427        Name: *const c_char,
1428    ) -> &'a Value;
1429    pub(crate) fn LLVMBuildOr<'a>(
1430        B: &Builder<'a>,
1431        LHS: &'a Value,
1432        RHS: &'a Value,
1433        Name: *const c_char,
1434    ) -> &'a Value;
1435    pub(crate) fn LLVMBuildXor<'a>(
1436        B: &Builder<'a>,
1437        LHS: &'a Value,
1438        RHS: &'a Value,
1439        Name: *const c_char,
1440    ) -> &'a Value;
1441    pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)
1442    -> &'a Value;
1443    pub(crate) fn LLVMBuildFNeg<'a>(
1444        B: &Builder<'a>,
1445        V: &'a Value,
1446        Name: *const c_char,
1447    ) -> &'a Value;
1448    pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char)
1449    -> &'a Value;
1450
1451    // Extra flags on arithmetic
1452    pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool);
1453    pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool);
1454    pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool);
1455
1456    // Memory
1457    pub(crate) fn LLVMBuildAlloca<'a>(
1458        B: &Builder<'a>,
1459        Ty: &'a Type,
1460        Name: *const c_char,
1461    ) -> &'a Value;
1462    pub(crate) fn LLVMBuildArrayAlloca<'a>(
1463        B: &Builder<'a>,
1464        Ty: &'a Type,
1465        Val: &'a Value,
1466        Name: *const c_char,
1467    ) -> &'a Value;
1468    pub(crate) fn LLVMBuildLoad2<'a>(
1469        B: &Builder<'a>,
1470        Ty: &'a Type,
1471        PointerVal: &'a Value,
1472        Name: *const c_char,
1473    ) -> &'a Value;
1474
1475    pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1476
1477    pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'a>(
1478        B: &Builder<'a>,
1479        Ty: &'a Type,
1480        Pointer: &'a Value,
1481        Indices: *const &'a Value,
1482        NumIndices: c_uint,
1483        Name: *const c_char,
1484        Flags: GEPNoWrapFlags,
1485    ) -> &'a Value;
1486
1487    // Casts
1488    pub(crate) fn LLVMBuildTrunc<'a>(
1489        B: &Builder<'a>,
1490        Val: &'a Value,
1491        DestTy: &'a Type,
1492        Name: *const c_char,
1493    ) -> &'a Value;
1494    pub(crate) fn LLVMBuildZExt<'a>(
1495        B: &Builder<'a>,
1496        Val: &'a Value,
1497        DestTy: &'a Type,
1498        Name: *const c_char,
1499    ) -> &'a Value;
1500    pub(crate) fn LLVMBuildSExt<'a>(
1501        B: &Builder<'a>,
1502        Val: &'a Value,
1503        DestTy: &'a Type,
1504        Name: *const c_char,
1505    ) -> &'a Value;
1506    pub(crate) fn LLVMBuildFPToUI<'a>(
1507        B: &Builder<'a>,
1508        Val: &'a Value,
1509        DestTy: &'a Type,
1510        Name: *const c_char,
1511    ) -> &'a Value;
1512    pub(crate) fn LLVMBuildFPToSI<'a>(
1513        B: &Builder<'a>,
1514        Val: &'a Value,
1515        DestTy: &'a Type,
1516        Name: *const c_char,
1517    ) -> &'a Value;
1518    pub(crate) fn LLVMBuildUIToFP<'a>(
1519        B: &Builder<'a>,
1520        Val: &'a Value,
1521        DestTy: &'a Type,
1522        Name: *const c_char,
1523    ) -> &'a Value;
1524    pub(crate) fn LLVMBuildSIToFP<'a>(
1525        B: &Builder<'a>,
1526        Val: &'a Value,
1527        DestTy: &'a Type,
1528        Name: *const c_char,
1529    ) -> &'a Value;
1530    pub(crate) fn LLVMBuildFPTrunc<'a>(
1531        B: &Builder<'a>,
1532        Val: &'a Value,
1533        DestTy: &'a Type,
1534        Name: *const c_char,
1535    ) -> &'a Value;
1536    pub(crate) fn LLVMBuildFPExt<'a>(
1537        B: &Builder<'a>,
1538        Val: &'a Value,
1539        DestTy: &'a Type,
1540        Name: *const c_char,
1541    ) -> &'a Value;
1542    pub(crate) fn LLVMBuildPtrToInt<'a>(
1543        B: &Builder<'a>,
1544        Val: &'a Value,
1545        DestTy: &'a Type,
1546        Name: *const c_char,
1547    ) -> &'a Value;
1548    pub(crate) fn LLVMBuildIntToPtr<'a>(
1549        B: &Builder<'a>,
1550        Val: &'a Value,
1551        DestTy: &'a Type,
1552        Name: *const c_char,
1553    ) -> &'a Value;
1554    pub(crate) fn LLVMBuildBitCast<'a>(
1555        B: &Builder<'a>,
1556        Val: &'a Value,
1557        DestTy: &'a Type,
1558        Name: *const c_char,
1559    ) -> &'a Value;
1560    pub(crate) fn LLVMBuildPointerCast<'a>(
1561        B: &Builder<'a>,
1562        Val: &'a Value,
1563        DestTy: &'a Type,
1564        Name: *const c_char,
1565    ) -> &'a Value;
1566    pub(crate) fn LLVMBuildIntCast2<'a>(
1567        B: &Builder<'a>,
1568        Val: &'a Value,
1569        DestTy: &'a Type,
1570        IsSigned: Bool,
1571        Name: *const c_char,
1572    ) -> &'a Value;
1573
1574    // Comparisons
1575    pub(crate) fn LLVMBuildICmp<'a>(
1576        B: &Builder<'a>,
1577        Op: c_uint,
1578        LHS: &'a Value,
1579        RHS: &'a Value,
1580        Name: *const c_char,
1581    ) -> &'a Value;
1582    pub(crate) fn LLVMBuildFCmp<'a>(
1583        B: &Builder<'a>,
1584        Op: c_uint,
1585        LHS: &'a Value,
1586        RHS: &'a Value,
1587        Name: *const c_char,
1588    ) -> &'a Value;
1589
1590    // Miscellaneous instructions
1591    pub(crate) fn LLVMBuildPhi<'a>(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char)
1592    -> &'a Value;
1593    pub(crate) fn LLVMBuildSelect<'a>(
1594        B: &Builder<'a>,
1595        If: &'a Value,
1596        Then: &'a Value,
1597        Else: &'a Value,
1598        Name: *const c_char,
1599    ) -> &'a Value;
1600    pub(crate) fn LLVMBuildVAArg<'a>(
1601        B: &Builder<'a>,
1602        list: &'a Value,
1603        Ty: &'a Type,
1604        Name: *const c_char,
1605    ) -> &'a Value;
1606    pub(crate) fn LLVMBuildExtractElement<'a>(
1607        B: &Builder<'a>,
1608        VecVal: &'a Value,
1609        Index: &'a Value,
1610        Name: *const c_char,
1611    ) -> &'a Value;
1612    pub(crate) fn LLVMBuildInsertElement<'a>(
1613        B: &Builder<'a>,
1614        VecVal: &'a Value,
1615        EltVal: &'a Value,
1616        Index: &'a Value,
1617        Name: *const c_char,
1618    ) -> &'a Value;
1619    pub(crate) fn LLVMBuildShuffleVector<'a>(
1620        B: &Builder<'a>,
1621        V1: &'a Value,
1622        V2: &'a Value,
1623        Mask: &'a Value,
1624        Name: *const c_char,
1625    ) -> &'a Value;
1626    pub(crate) fn LLVMBuildExtractValue<'a>(
1627        B: &Builder<'a>,
1628        AggVal: &'a Value,
1629        Index: c_uint,
1630        Name: *const c_char,
1631    ) -> &'a Value;
1632    pub(crate) fn LLVMBuildInsertValue<'a>(
1633        B: &Builder<'a>,
1634        AggVal: &'a Value,
1635        EltVal: &'a Value,
1636        Index: c_uint,
1637        Name: *const c_char,
1638    ) -> &'a Value;
1639
1640    // Atomic Operations
1641    pub(crate) fn LLVMBuildAtomicCmpXchg<'a>(
1642        B: &Builder<'a>,
1643        LHS: &'a Value,
1644        CMP: &'a Value,
1645        RHS: &'a Value,
1646        Order: AtomicOrdering,
1647        FailureOrder: AtomicOrdering,
1648        SingleThreaded: Bool,
1649    ) -> &'a Value;
1650
1651    pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool);
1652
1653    pub(crate) fn LLVMBuildAtomicRMW<'a>(
1654        B: &Builder<'a>,
1655        Op: AtomicRmwBinOp,
1656        LHS: &'a Value,
1657        RHS: &'a Value,
1658        Order: AtomicOrdering,
1659        SingleThreaded: Bool,
1660    ) -> &'a Value;
1661
1662    pub(crate) fn LLVMBuildFence<'a>(
1663        B: &Builder<'a>,
1664        Order: AtomicOrdering,
1665        SingleThreaded: Bool,
1666        Name: *const c_char,
1667    ) -> &'a Value;
1668
1669    /// Writes a module to the specified path. Returns 0 on success.
1670    pub(crate) fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1671
1672    /// Creates a legacy pass manager -- only used for final codegen.
1673    pub(crate) fn LLVMCreatePassManager<'a>() -> &'a mut PassManager<'a>;
1674
1675    pub(crate) fn LLVMAddAnalysisPasses<'a>(T: &'a TargetMachine, PM: &PassManager<'a>);
1676
1677    pub(crate) fn LLVMGetHostCPUFeatures() -> *mut c_char;
1678
1679    pub(crate) fn LLVMDisposeMessage(message: *mut c_char);
1680
1681    pub(crate) fn LLVMIsMultithreaded() -> Bool;
1682
1683    pub(crate) fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1684
1685    pub(crate) fn LLVMStructSetBody<'a>(
1686        StructTy: &'a Type,
1687        ElementTypes: *const &'a Type,
1688        ElementCount: c_uint,
1689        Packed: Bool,
1690    );
1691
1692    pub(crate) safe fn LLVMMetadataAsValue<'a>(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1693
1694    pub(crate) fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr);
1695
1696    pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>;
1697
1698    pub(crate) fn LLVMGetOrInsertComdat(M: &Module, Name: *const c_char) -> &Comdat;
1699    pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat);
1700
1701    pub(crate) fn LLVMCreateOperandBundle(
1702        Tag: *const c_char,
1703        TagLen: size_t,
1704        Args: *const &'_ Value,
1705        NumArgs: c_uint,
1706    ) -> *mut OperandBundle<'_>;
1707    pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull<OperandBundle<'_>>);
1708
1709    pub(crate) fn LLVMBuildCallWithOperandBundles<'a>(
1710        B: &Builder<'a>,
1711        Ty: &'a Type,
1712        Fn: &'a Value,
1713        Args: *const &'a Value,
1714        NumArgs: c_uint,
1715        Bundles: *const &OperandBundle<'a>,
1716        NumBundles: c_uint,
1717        Name: *const c_char,
1718    ) -> &'a Value;
1719    pub(crate) fn LLVMBuildInvokeWithOperandBundles<'a>(
1720        B: &Builder<'a>,
1721        Ty: &'a Type,
1722        Fn: &'a Value,
1723        Args: *const &'a Value,
1724        NumArgs: c_uint,
1725        Then: &'a BasicBlock,
1726        Catch: &'a BasicBlock,
1727        Bundles: *const &OperandBundle<'a>,
1728        NumBundles: c_uint,
1729        Name: *const c_char,
1730    ) -> &'a Value;
1731    pub(crate) fn LLVMBuildCallBr<'a>(
1732        B: &Builder<'a>,
1733        Ty: &'a Type,
1734        Fn: &'a Value,
1735        DefaultDest: &'a BasicBlock,
1736        IndirectDests: *const &'a BasicBlock,
1737        NumIndirectDests: c_uint,
1738        Args: *const &'a Value,
1739        NumArgs: c_uint,
1740        Bundles: *const &OperandBundle<'a>,
1741        NumBundles: c_uint,
1742        Name: *const c_char,
1743    ) -> &'a Value;
1744}
1745
1746// FFI bindings for `DIBuilder` functions in the LLVM-C API.
1747// Try to keep these in the same order as in `llvm/include/llvm-c/DebugInfo.h`.
1748//
1749// FIXME(#134001): Audit all `Option` parameters, especially in lists, to check
1750// that they really are nullable on the C/C++ side. LLVM doesn't appear to
1751// actually document which ones are nullable.
1752unsafe extern "C" {
1753    pub(crate) fn LLVMCreateDIBuilder<'ll>(M: &'ll Module) -> *mut DIBuilder<'ll>;
1754    pub(crate) fn LLVMDisposeDIBuilder<'ll>(Builder: ptr::NonNull<DIBuilder<'ll>>);
1755
1756    pub(crate) fn LLVMDIBuilderFinalize<'ll>(Builder: &DIBuilder<'ll>);
1757
1758    pub(crate) fn LLVMDIBuilderCreateNameSpace<'ll>(
1759        Builder: &DIBuilder<'ll>,
1760        ParentScope: Option<&'ll Metadata>,
1761        Name: *const c_uchar,
1762        NameLen: size_t,
1763        ExportSymbols: llvm::Bool,
1764    ) -> &'ll Metadata;
1765
1766    pub(crate) fn LLVMDIBuilderCreateLexicalBlock<'ll>(
1767        Builder: &DIBuilder<'ll>,
1768        Scope: &'ll Metadata,
1769        File: &'ll Metadata,
1770        Line: c_uint,
1771        Column: c_uint,
1772    ) -> &'ll Metadata;
1773
1774    pub(crate) fn LLVMDIBuilderCreateLexicalBlockFile<'ll>(
1775        Builder: &DIBuilder<'ll>,
1776        Scope: &'ll Metadata,
1777        File: &'ll Metadata,
1778        Discriminator: c_uint, // (optional "DWARF path discriminator"; default is 0)
1779    ) -> &'ll Metadata;
1780
1781    pub(crate) fn LLVMDIBuilderCreateDebugLocation<'ll>(
1782        Ctx: &'ll Context,
1783        Line: c_uint,
1784        Column: c_uint,
1785        Scope: &'ll Metadata,
1786        InlinedAt: Option<&'ll Metadata>,
1787    ) -> &'ll Metadata;
1788}
1789
1790#[link(name = "llvm-wrapper", kind = "static")]
1791unsafe extern "C" {
1792    pub(crate) fn LLVMRustInstallErrorHandlers();
1793    pub(crate) fn LLVMRustDisableSystemDialogsOnCrash();
1794
1795    // Create and destroy contexts.
1796    pub(crate) fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
1797
1798    /// See llvm::LLVMTypeKind::getTypeID.
1799    pub(crate) fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
1800
1801    // Operations on all values
1802    pub(crate) fn LLVMRustGlobalAddMetadata<'a>(
1803        Val: &'a Value,
1804        KindID: c_uint,
1805        Metadata: &'a Metadata,
1806    );
1807    pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;
1808
1809    // Operations on scalar constants
1810    pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;
1811    pub(crate) fn LLVMRustConstInt128Get(
1812        ConstantVal: &ConstantInt,
1813        SExt: bool,
1814        high: &mut u64,
1815        low: &mut u64,
1816    ) -> bool;
1817
1818    // Operations on global variables, functions, and aliases (globals)
1819    pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool);
1820
1821    // Operations on global variables
1822    pub(crate) fn LLVMRustGetOrInsertGlobal<'a>(
1823        M: &'a Module,
1824        Name: *const c_char,
1825        NameLen: size_t,
1826        T: &'a Type,
1827    ) -> &'a Value;
1828    pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
1829    pub(crate) fn LLVMRustGetNamedValue(
1830        M: &Module,
1831        Name: *const c_char,
1832        NameLen: size_t,
1833    ) -> Option<&Value>;
1834
1835    // Operations on attributes
1836    pub(crate) fn LLVMRustCreateAttrNoValue(C: &Context, attr: AttributeKind) -> &Attribute;
1837    pub(crate) fn LLVMRustCreateAlignmentAttr(C: &Context, bytes: u64) -> &Attribute;
1838    pub(crate) fn LLVMRustCreateDereferenceableAttr(C: &Context, bytes: u64) -> &Attribute;
1839    pub(crate) fn LLVMRustCreateDereferenceableOrNullAttr(C: &Context, bytes: u64) -> &Attribute;
1840    pub(crate) fn LLVMRustCreateByValAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1841    pub(crate) fn LLVMRustCreateStructRetAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1842    pub(crate) fn LLVMRustCreateElementTypeAttr<'a>(C: &'a Context, ty: &'a Type) -> &'a Attribute;
1843    pub(crate) fn LLVMRustCreateUWTableAttr(C: &Context, async_: bool) -> &Attribute;
1844    pub(crate) fn LLVMRustCreateAllocSizeAttr(C: &Context, size_arg: u32) -> &Attribute;
1845    pub(crate) fn LLVMRustCreateAllocKindAttr(C: &Context, size_arg: u64) -> &Attribute;
1846    pub(crate) fn LLVMRustCreateMemoryEffectsAttr(
1847        C: &Context,
1848        effects: MemoryEffects,
1849    ) -> &Attribute;
1850    pub(crate) fn LLVMRustCreateRangeAttribute(
1851        C: &Context,
1852        num_bits: c_uint,
1853        lower_words: *const u64,
1854        upper_words: *const u64,
1855    ) -> &Attribute;
1856
1857    // Operations on functions
1858    pub(crate) fn LLVMRustGetOrInsertFunction<'a>(
1859        M: &'a Module,
1860        Name: *const c_char,
1861        NameLen: size_t,
1862        FunctionTy: &'a Type,
1863    ) -> &'a Value;
1864    pub(crate) fn LLVMRustAddFunctionAttributes<'a>(
1865        Fn: &'a Value,
1866        index: c_uint,
1867        Attrs: *const &'a Attribute,
1868        AttrsLen: size_t,
1869    );
1870
1871    // Operations on call sites
1872    pub(crate) fn LLVMRustAddCallSiteAttributes<'a>(
1873        Instr: &'a Value,
1874        index: c_uint,
1875        Attrs: *const &'a Attribute,
1876        AttrsLen: size_t,
1877    );
1878
1879    pub(crate) fn LLVMRustSetFastMath(Instr: &Value);
1880    pub(crate) fn LLVMRustSetAlgebraicMath(Instr: &Value);
1881    pub(crate) fn LLVMRustSetAllowReassoc(Instr: &Value);
1882
1883    // Miscellaneous instructions
1884    pub(crate) fn LLVMRustBuildMemCpy<'a>(
1885        B: &Builder<'a>,
1886        Dst: &'a Value,
1887        DstAlign: c_uint,
1888        Src: &'a Value,
1889        SrcAlign: c_uint,
1890        Size: &'a Value,
1891        IsVolatile: bool,
1892    ) -> &'a Value;
1893    pub(crate) fn LLVMRustBuildMemMove<'a>(
1894        B: &Builder<'a>,
1895        Dst: &'a Value,
1896        DstAlign: c_uint,
1897        Src: &'a Value,
1898        SrcAlign: c_uint,
1899        Size: &'a Value,
1900        IsVolatile: bool,
1901    ) -> &'a Value;
1902    pub(crate) fn LLVMRustBuildMemSet<'a>(
1903        B: &Builder<'a>,
1904        Dst: &'a Value,
1905        DstAlign: c_uint,
1906        Val: &'a Value,
1907        Size: &'a Value,
1908        IsVolatile: bool,
1909    ) -> &'a Value;
1910
1911    pub(crate) fn LLVMRustBuildVectorReduceFAdd<'a>(
1912        B: &Builder<'a>,
1913        Acc: &'a Value,
1914        Src: &'a Value,
1915    ) -> &'a Value;
1916    pub(crate) fn LLVMRustBuildVectorReduceFMul<'a>(
1917        B: &Builder<'a>,
1918        Acc: &'a Value,
1919        Src: &'a Value,
1920    ) -> &'a Value;
1921    pub(crate) fn LLVMRustBuildVectorReduceAdd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1922    pub(crate) fn LLVMRustBuildVectorReduceMul<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1923    pub(crate) fn LLVMRustBuildVectorReduceAnd<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1924    pub(crate) fn LLVMRustBuildVectorReduceOr<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1925    pub(crate) fn LLVMRustBuildVectorReduceXor<'a>(B: &Builder<'a>, Src: &'a Value) -> &'a Value;
1926    pub(crate) fn LLVMRustBuildVectorReduceMin<'a>(
1927        B: &Builder<'a>,
1928        Src: &'a Value,
1929        IsSigned: bool,
1930    ) -> &'a Value;
1931    pub(crate) fn LLVMRustBuildVectorReduceMax<'a>(
1932        B: &Builder<'a>,
1933        Src: &'a Value,
1934        IsSigned: bool,
1935    ) -> &'a Value;
1936    pub(crate) fn LLVMRustBuildVectorReduceFMin<'a>(
1937        B: &Builder<'a>,
1938        Src: &'a Value,
1939        IsNaN: bool,
1940    ) -> &'a Value;
1941    pub(crate) fn LLVMRustBuildVectorReduceFMax<'a>(
1942        B: &Builder<'a>,
1943        Src: &'a Value,
1944        IsNaN: bool,
1945    ) -> &'a Value;
1946
1947    pub(crate) fn LLVMRustBuildMinNum<'a>(
1948        B: &Builder<'a>,
1949        LHS: &'a Value,
1950        LHS: &'a Value,
1951    ) -> &'a Value;
1952    pub(crate) fn LLVMRustBuildMaxNum<'a>(
1953        B: &Builder<'a>,
1954        LHS: &'a Value,
1955        LHS: &'a Value,
1956    ) -> &'a Value;
1957
1958    // Atomic Operations
1959    pub(crate) fn LLVMRustBuildAtomicLoad<'a>(
1960        B: &Builder<'a>,
1961        ElementType: &'a Type,
1962        PointerVal: &'a Value,
1963        Name: *const c_char,
1964        Order: AtomicOrdering,
1965    ) -> &'a Value;
1966
1967    pub(crate) fn LLVMRustBuildAtomicStore<'a>(
1968        B: &Builder<'a>,
1969        Val: &'a Value,
1970        Ptr: &'a Value,
1971        Order: AtomicOrdering,
1972    ) -> &'a Value;
1973
1974    pub(crate) fn LLVMRustTimeTraceProfilerInitialize();
1975
1976    pub(crate) fn LLVMRustTimeTraceProfilerFinishThread();
1977
1978    pub(crate) fn LLVMRustTimeTraceProfilerFinish(FileName: *const c_char);
1979
1980    /// Returns a string describing the last error caused by an LLVMRust* call.
1981    pub(crate) fn LLVMRustGetLastError() -> *const c_char;
1982
1983    /// Prints the timing information collected by `-Ztime-llvm-passes`.
1984    pub(crate) fn LLVMRustPrintPassTimings(OutStr: &RustString);
1985
1986    /// Prints the statistics collected by `-Zprint-codegen-stats`.
1987    pub(crate) fn LLVMRustPrintStatistics(OutStr: &RustString);
1988
1989    /// Prepares inline assembly.
1990    pub(crate) fn LLVMRustInlineAsm(
1991        Ty: &Type,
1992        AsmString: *const c_char,
1993        AsmStringLen: size_t,
1994        Constraints: *const c_char,
1995        ConstraintsLen: size_t,
1996        SideEffects: Bool,
1997        AlignStack: Bool,
1998        Dialect: AsmDialect,
1999        CanThrow: Bool,
2000    ) -> &Value;
2001    pub(crate) fn LLVMRustInlineAsmVerify(
2002        Ty: &Type,
2003        Constraints: *const c_char,
2004        ConstraintsLen: size_t,
2005    ) -> bool;
2006
2007    pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
2008        Filenames: *const *const c_char,
2009        FilenamesLen: size_t,
2010        Lengths: *const size_t,
2011        LengthsLen: size_t,
2012        BufferOut: &RustString,
2013    );
2014
2015    pub(crate) fn LLVMRustCoverageWriteFunctionMappingsToBuffer(
2016        VirtualFileMappingIDs: *const c_uint,
2017        NumVirtualFileMappingIDs: size_t,
2018        Expressions: *const crate::coverageinfo::ffi::CounterExpression,
2019        NumExpressions: size_t,
2020        CodeRegions: *const crate::coverageinfo::ffi::CodeRegion,
2021        NumCodeRegions: size_t,
2022        ExpansionRegions: *const crate::coverageinfo::ffi::ExpansionRegion,
2023        NumExpansionRegions: size_t,
2024        BranchRegions: *const crate::coverageinfo::ffi::BranchRegion,
2025        NumBranchRegions: size_t,
2026        MCDCBranchRegions: *const crate::coverageinfo::ffi::MCDCBranchRegion,
2027        NumMCDCBranchRegions: size_t,
2028        MCDCDecisionRegions: *const crate::coverageinfo::ffi::MCDCDecisionRegion,
2029        NumMCDCDecisionRegions: size_t,
2030        BufferOut: &RustString,
2031    );
2032
2033    pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar(
2034        F: &Value,
2035        FuncName: *const c_char,
2036        FuncNameLen: size_t,
2037    ) -> &Value;
2038    pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
2039
2040    pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
2041
2042    pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
2043
2044    pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
2045
2046    pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
2047    pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;
2048    pub(crate) fn LLVMRustVersionMajor() -> u32;
2049    pub(crate) fn LLVMRustVersionMinor() -> u32;
2050    pub(crate) fn LLVMRustVersionPatch() -> u32;
2051
2052    /// Add LLVM module flags.
2053    ///
2054    /// In order for Rust-C LTO to work, module flags must be compatible with Clang. What
2055    /// "compatible" means depends on the merge behaviors involved.
2056    pub(crate) fn LLVMRustAddModuleFlagU32(
2057        M: &Module,
2058        MergeBehavior: ModuleFlagMergeBehavior,
2059        Name: *const c_char,
2060        NameLen: size_t,
2061        Value: u32,
2062    );
2063
2064    pub(crate) fn LLVMRustAddModuleFlagString(
2065        M: &Module,
2066        MergeBehavior: ModuleFlagMergeBehavior,
2067        Name: *const c_char,
2068        NameLen: size_t,
2069        Value: *const c_char,
2070        ValueLen: size_t,
2071    );
2072
2073    pub(crate) fn LLVMRustDIBuilderCreateCompileUnit<'a>(
2074        Builder: &DIBuilder<'a>,
2075        Lang: c_uint,
2076        File: &'a DIFile,
2077        Producer: *const c_char,
2078        ProducerLen: size_t,
2079        isOptimized: bool,
2080        Flags: *const c_char,
2081        RuntimeVer: c_uint,
2082        SplitName: *const c_char,
2083        SplitNameLen: size_t,
2084        kind: DebugEmissionKind,
2085        DWOId: u64,
2086        SplitDebugInlining: bool,
2087        DebugNameTableKind: DebugNameTableKind,
2088    ) -> &'a DIDescriptor;
2089
2090    pub(crate) fn LLVMRustDIBuilderCreateFile<'a>(
2091        Builder: &DIBuilder<'a>,
2092        Filename: *const c_char,
2093        FilenameLen: size_t,
2094        Directory: *const c_char,
2095        DirectoryLen: size_t,
2096        CSKind: ChecksumKind,
2097        Checksum: *const c_char,
2098        ChecksumLen: size_t,
2099        Source: *const c_char,
2100        SourceLen: size_t,
2101    ) -> &'a DIFile;
2102
2103    pub(crate) fn LLVMRustDIBuilderCreateSubroutineType<'a>(
2104        Builder: &DIBuilder<'a>,
2105        ParameterTypes: &'a DIArray,
2106    ) -> &'a DICompositeType;
2107
2108    pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>(
2109        Builder: &DIBuilder<'a>,
2110        Scope: &'a DIDescriptor,
2111        Name: *const c_char,
2112        NameLen: size_t,
2113        LinkageName: *const c_char,
2114        LinkageNameLen: size_t,
2115        File: &'a DIFile,
2116        LineNo: c_uint,
2117        Ty: &'a DIType,
2118        ScopeLine: c_uint,
2119        Flags: DIFlags,
2120        SPFlags: DISPFlags,
2121        MaybeFn: Option<&'a Value>,
2122        TParam: &'a DIArray,
2123        Decl: Option<&'a DIDescriptor>,
2124    ) -> &'a DISubprogram;
2125
2126    pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>(
2127        Builder: &DIBuilder<'a>,
2128        Scope: &'a DIDescriptor,
2129        Name: *const c_char,
2130        NameLen: size_t,
2131        LinkageName: *const c_char,
2132        LinkageNameLen: size_t,
2133        File: &'a DIFile,
2134        LineNo: c_uint,
2135        Ty: &'a DIType,
2136        Flags: DIFlags,
2137        SPFlags: DISPFlags,
2138        TParam: &'a DIArray,
2139    ) -> &'a DISubprogram;
2140
2141    pub(crate) fn LLVMRustDIBuilderCreateBasicType<'a>(
2142        Builder: &DIBuilder<'a>,
2143        Name: *const c_char,
2144        NameLen: size_t,
2145        SizeInBits: u64,
2146        Encoding: c_uint,
2147    ) -> &'a DIBasicType;
2148
2149    pub(crate) fn LLVMRustDIBuilderCreateTypedef<'a>(
2150        Builder: &DIBuilder<'a>,
2151        Type: &'a DIBasicType,
2152        Name: *const c_char,
2153        NameLen: size_t,
2154        File: &'a DIFile,
2155        LineNo: c_uint,
2156        Scope: Option<&'a DIScope>,
2157    ) -> &'a DIDerivedType;
2158
2159    pub(crate) fn LLVMRustDIBuilderCreatePointerType<'a>(
2160        Builder: &DIBuilder<'a>,
2161        PointeeTy: &'a DIType,
2162        SizeInBits: u64,
2163        AlignInBits: u32,
2164        AddressSpace: c_uint,
2165        Name: *const c_char,
2166        NameLen: size_t,
2167    ) -> &'a DIDerivedType;
2168
2169    pub(crate) fn LLVMRustDIBuilderCreateStructType<'a>(
2170        Builder: &DIBuilder<'a>,
2171        Scope: Option<&'a DIDescriptor>,
2172        Name: *const c_char,
2173        NameLen: size_t,
2174        File: &'a DIFile,
2175        LineNumber: c_uint,
2176        SizeInBits: u64,
2177        AlignInBits: u32,
2178        Flags: DIFlags,
2179        DerivedFrom: Option<&'a DIType>,
2180        Elements: &'a DIArray,
2181        RunTimeLang: c_uint,
2182        VTableHolder: Option<&'a DIType>,
2183        UniqueId: *const c_char,
2184        UniqueIdLen: size_t,
2185    ) -> &'a DICompositeType;
2186
2187    pub(crate) fn LLVMRustDIBuilderCreateMemberType<'a>(
2188        Builder: &DIBuilder<'a>,
2189        Scope: &'a DIDescriptor,
2190        Name: *const c_char,
2191        NameLen: size_t,
2192        File: &'a DIFile,
2193        LineNo: c_uint,
2194        SizeInBits: u64,
2195        AlignInBits: u32,
2196        OffsetInBits: u64,
2197        Flags: DIFlags,
2198        Ty: &'a DIType,
2199    ) -> &'a DIDerivedType;
2200
2201    pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>(
2202        Builder: &DIBuilder<'a>,
2203        Scope: &'a DIScope,
2204        Name: *const c_char,
2205        NameLen: size_t,
2206        File: &'a DIFile,
2207        LineNumber: c_uint,
2208        SizeInBits: u64,
2209        AlignInBits: u32,
2210        OffsetInBits: u64,
2211        Discriminant: Option<&'a Value>,
2212        Flags: DIFlags,
2213        Ty: &'a DIType,
2214    ) -> &'a DIType;
2215
2216    pub(crate) fn LLVMRustDIBuilderCreateStaticMemberType<'a>(
2217        Builder: &DIBuilder<'a>,
2218        Scope: &'a DIDescriptor,
2219        Name: *const c_char,
2220        NameLen: size_t,
2221        File: &'a DIFile,
2222        LineNo: c_uint,
2223        Ty: &'a DIType,
2224        Flags: DIFlags,
2225        val: Option<&'a Value>,
2226        AlignInBits: u32,
2227    ) -> &'a DIDerivedType;
2228
2229    pub(crate) fn LLVMRustDIBuilderCreateQualifiedType<'a>(
2230        Builder: &DIBuilder<'a>,
2231        Tag: c_uint,
2232        Type: &'a DIType,
2233    ) -> &'a DIDerivedType;
2234
2235    pub(crate) fn LLVMRustDIBuilderCreateStaticVariable<'a>(
2236        Builder: &DIBuilder<'a>,
2237        Context: Option<&'a DIScope>,
2238        Name: *const c_char,
2239        NameLen: size_t,
2240        LinkageName: *const c_char,
2241        LinkageNameLen: size_t,
2242        File: &'a DIFile,
2243        LineNo: c_uint,
2244        Ty: &'a DIType,
2245        isLocalToUnit: bool,
2246        Val: &'a Value,
2247        Decl: Option<&'a DIDescriptor>,
2248        AlignInBits: u32,
2249    ) -> &'a DIGlobalVariableExpression;
2250
2251    pub(crate) fn LLVMRustDIBuilderCreateVariable<'a>(
2252        Builder: &DIBuilder<'a>,
2253        Tag: c_uint,
2254        Scope: &'a DIDescriptor,
2255        Name: *const c_char,
2256        NameLen: size_t,
2257        File: &'a DIFile,
2258        LineNo: c_uint,
2259        Ty: &'a DIType,
2260        AlwaysPreserve: bool,
2261        Flags: DIFlags,
2262        ArgNo: c_uint,
2263        AlignInBits: u32,
2264    ) -> &'a DIVariable;
2265
2266    pub(crate) fn LLVMRustDIBuilderCreateArrayType<'a>(
2267        Builder: &DIBuilder<'a>,
2268        Size: u64,
2269        AlignInBits: u32,
2270        Ty: &'a DIType,
2271        Subscripts: &'a DIArray,
2272    ) -> &'a DIType;
2273
2274    pub(crate) fn LLVMRustDIBuilderGetOrCreateSubrange<'a>(
2275        Builder: &DIBuilder<'a>,
2276        Lo: i64,
2277        Count: i64,
2278    ) -> &'a DISubrange;
2279
2280    pub(crate) fn LLVMRustDIBuilderGetOrCreateArray<'a>(
2281        Builder: &DIBuilder<'a>,
2282        Ptr: *const Option<&'a DIDescriptor>,
2283        Count: c_uint,
2284    ) -> &'a DIArray;
2285
2286    pub(crate) fn LLVMRustDIBuilderInsertDeclareAtEnd<'a>(
2287        Builder: &DIBuilder<'a>,
2288        Val: &'a Value,
2289        VarInfo: &'a DIVariable,
2290        AddrOps: *const u64,
2291        AddrOpsCount: c_uint,
2292        DL: &'a DILocation,
2293        InsertAtEnd: &'a BasicBlock,
2294    );
2295
2296    pub(crate) fn LLVMRustDIBuilderCreateEnumerator<'a>(
2297        Builder: &DIBuilder<'a>,
2298        Name: *const c_char,
2299        NameLen: size_t,
2300        Value: *const u64,
2301        SizeInBits: c_uint,
2302        IsUnsigned: bool,
2303    ) -> &'a DIEnumerator;
2304
2305    pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>(
2306        Builder: &DIBuilder<'a>,
2307        Scope: &'a DIScope,
2308        Name: *const c_char,
2309        NameLen: size_t,
2310        File: &'a DIFile,
2311        LineNumber: c_uint,
2312        SizeInBits: u64,
2313        AlignInBits: u32,
2314        Elements: &'a DIArray,
2315        ClassType: &'a DIType,
2316        IsScoped: bool,
2317    ) -> &'a DIType;
2318
2319    pub(crate) fn LLVMRustDIBuilderCreateUnionType<'a>(
2320        Builder: &DIBuilder<'a>,
2321        Scope: Option<&'a DIScope>,
2322        Name: *const c_char,
2323        NameLen: size_t,
2324        File: &'a DIFile,
2325        LineNumber: c_uint,
2326        SizeInBits: u64,
2327        AlignInBits: u32,
2328        Flags: DIFlags,
2329        Elements: Option<&'a DIArray>,
2330        RunTimeLang: c_uint,
2331        UniqueId: *const c_char,
2332        UniqueIdLen: size_t,
2333    ) -> &'a DIType;
2334
2335    pub(crate) fn LLVMRustDIBuilderCreateVariantPart<'a>(
2336        Builder: &DIBuilder<'a>,
2337        Scope: &'a DIScope,
2338        Name: *const c_char,
2339        NameLen: size_t,
2340        File: &'a DIFile,
2341        LineNo: c_uint,
2342        SizeInBits: u64,
2343        AlignInBits: u32,
2344        Flags: DIFlags,
2345        Discriminator: Option<&'a DIDerivedType>,
2346        Elements: &'a DIArray,
2347        UniqueId: *const c_char,
2348        UniqueIdLen: size_t,
2349    ) -> &'a DIDerivedType;
2350
2351    pub(crate) fn LLVMRustDIBuilderCreateTemplateTypeParameter<'a>(
2352        Builder: &DIBuilder<'a>,
2353        Scope: Option<&'a DIScope>,
2354        Name: *const c_char,
2355        NameLen: size_t,
2356        Ty: &'a DIType,
2357    ) -> &'a DITemplateTypeParameter;
2358
2359    pub(crate) fn LLVMRustDICompositeTypeReplaceArrays<'a>(
2360        Builder: &DIBuilder<'a>,
2361        CompositeType: &'a DIType,
2362        Elements: Option<&'a DIArray>,
2363        Params: Option<&'a DIArray>,
2364    );
2365
2366    pub(crate) fn LLVMRustDILocationCloneWithBaseDiscriminator<'a>(
2367        Location: &'a DILocation,
2368        BD: c_uint,
2369    ) -> Option<&'a DILocation>;
2370
2371    pub(crate) fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
2372    pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
2373
2374    pub(crate) fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2375
2376    pub(crate) fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString);
2377    pub(crate) fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;
2378    pub(crate) fn LLVMRustGetTargetFeature(
2379        T: &TargetMachine,
2380        Index: size_t,
2381        Feature: &mut *const c_char,
2382        Desc: &mut *const c_char,
2383    );
2384
2385    pub(crate) fn LLVMRustGetHostCPUName(LenOut: &mut size_t) -> *const u8;
2386
2387    // This function makes copies of pointed to data, so the data's lifetime may end after this
2388    // function returns.
2389    pub(crate) fn LLVMRustCreateTargetMachine(
2390        Triple: *const c_char,
2391        CPU: *const c_char,
2392        Features: *const c_char,
2393        Abi: *const c_char,
2394        Model: CodeModel,
2395        Reloc: RelocModel,
2396        Level: CodeGenOptLevel,
2397        FloatABIType: FloatAbi,
2398        FunctionSections: bool,
2399        DataSections: bool,
2400        UniqueSectionNames: bool,
2401        TrapUnreachable: bool,
2402        Singlethread: bool,
2403        VerboseAsm: bool,
2404        EmitStackSizeSection: bool,
2405        RelaxELFRelocations: bool,
2406        UseInitArray: bool,
2407        SplitDwarfFile: *const c_char,
2408        OutputObjFile: *const c_char,
2409        DebugInfoCompression: *const c_char,
2410        UseEmulatedTls: bool,
2411        ArgsCstrBuff: *const c_char,
2412        ArgsCstrBuffLen: usize,
2413    ) -> *mut TargetMachine;
2414
2415    pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);
2416    pub(crate) fn LLVMRustAddLibraryInfo<'a>(
2417        PM: &PassManager<'a>,
2418        M: &'a Module,
2419        DisableSimplifyLibCalls: bool,
2420    );
2421    pub(crate) fn LLVMRustWriteOutputFile<'a>(
2422        T: &'a TargetMachine,
2423        PM: *mut PassManager<'a>,
2424        M: &'a Module,
2425        Output: *const c_char,
2426        DwoOutput: *const c_char,
2427        FileType: FileType,
2428        VerifyIR: bool,
2429    ) -> LLVMRustResult;
2430    pub(crate) fn LLVMRustOptimize<'a>(
2431        M: &'a Module,
2432        TM: &'a TargetMachine,
2433        OptLevel: PassBuilderOptLevel,
2434        OptStage: OptStage,
2435        IsLinkerPluginLTO: bool,
2436        NoPrepopulatePasses: bool,
2437        VerifyIR: bool,
2438        LintIR: bool,
2439        ThinLTOBuffer: Option<&mut *mut ThinLTOBuffer>,
2440        EmitThinLTO: bool,
2441        EmitThinLTOSummary: bool,
2442        MergeFunctions: bool,
2443        UnrollLoops: bool,
2444        SLPVectorize: bool,
2445        LoopVectorize: bool,
2446        DisableSimplifyLibCalls: bool,
2447        EmitLifetimeMarkers: bool,
2448        RunEnzyme: bool,
2449        SanitizerOptions: Option<&SanitizerOptions>,
2450        PGOGenPath: *const c_char,
2451        PGOUsePath: *const c_char,
2452        InstrumentCoverage: bool,
2453        InstrProfileOutput: *const c_char,
2454        PGOSampleUsePath: *const c_char,
2455        DebugInfoForProfiling: bool,
2456        llvm_selfprofiler: *mut c_void,
2457        begin_callback: SelfProfileBeforePassCallback,
2458        end_callback: SelfProfileAfterPassCallback,
2459        ExtraPasses: *const c_char,
2460        ExtraPassesLen: size_t,
2461        LLVMPlugins: *const c_char,
2462        LLVMPluginsLen: size_t,
2463    ) -> LLVMRustResult;
2464    pub(crate) fn LLVMRustPrintModule(
2465        M: &Module,
2466        Output: *const c_char,
2467        Demangle: extern "C" fn(*const c_char, size_t, *mut c_char, size_t) -> size_t,
2468    ) -> LLVMRustResult;
2469    pub(crate) fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2470    pub(crate) fn LLVMRustPrintPasses();
2471    pub(crate) fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
2472    pub(crate) fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
2473
2474    pub(crate) fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2475    pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2476    pub(crate) fn LLVMRustArchiveIteratorNext<'a>(
2477        AIR: &ArchiveIterator<'a>,
2478    ) -> Option<&'a mut ArchiveChild<'a>>;
2479    pub(crate) fn LLVMRustArchiveChildName(
2480        ACR: &ArchiveChild<'_>,
2481        size: &mut size_t,
2482    ) -> *const c_char;
2483    pub(crate) fn LLVMRustArchiveChildFree<'a>(ACR: &'a mut ArchiveChild<'a>);
2484    pub(crate) fn LLVMRustArchiveIteratorFree<'a>(AIR: &'a mut ArchiveIterator<'a>);
2485    pub(crate) fn LLVMRustDestroyArchive(AR: &'static mut Archive);
2486
2487    pub(crate) fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
2488
2489    pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'a>(
2490        DI: &'a DiagnosticInfo,
2491        pass_name_out: &RustString,
2492        function_out: &mut Option<&'a Value>,
2493        loc_line_out: &mut c_uint,
2494        loc_column_out: &mut c_uint,
2495        loc_filename_out: &RustString,
2496        message_out: &RustString,
2497    );
2498
2499    pub(crate) fn LLVMRustUnpackInlineAsmDiagnostic<'a>(
2500        DI: &'a DiagnosticInfo,
2501        level_out: &mut DiagnosticLevel,
2502        cookie_out: &mut u64,
2503        message_out: &mut Option<&'a Twine>,
2504    );
2505
2506    pub(crate) fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
2507    pub(crate) fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
2508
2509    pub(crate) fn LLVMRustGetSMDiagnostic<'a>(
2510        DI: &'a DiagnosticInfo,
2511        cookie_out: &mut u64,
2512    ) -> &'a SMDiagnostic;
2513
2514    pub(crate) fn LLVMRustUnpackSMDiagnostic(
2515        d: &SMDiagnostic,
2516        message_out: &RustString,
2517        buffer_out: &RustString,
2518        level_out: &mut DiagnosticLevel,
2519        loc_out: &mut c_uint,
2520        ranges_out: *mut c_uint,
2521        num_ranges: &mut usize,
2522    ) -> bool;
2523
2524    pub(crate) fn LLVMRustWriteArchive(
2525        Dst: *const c_char,
2526        NumMembers: size_t,
2527        Members: *const &RustArchiveMember<'_>,
2528        WriteSymbtab: bool,
2529        Kind: ArchiveKind,
2530        isEC: bool,
2531    ) -> LLVMRustResult;
2532    pub(crate) fn LLVMRustArchiveMemberNew<'a>(
2533        Filename: *const c_char,
2534        Name: *const c_char,
2535        Child: Option<&ArchiveChild<'a>>,
2536    ) -> &'a mut RustArchiveMember<'a>;
2537    pub(crate) fn LLVMRustArchiveMemberFree<'a>(Member: &'a mut RustArchiveMember<'a>);
2538
2539    pub(crate) fn LLVMRustSetDataLayoutFromTargetMachine<'a>(M: &'a Module, TM: &'a TargetMachine);
2540
2541    pub(crate) fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock);
2542
2543    pub(crate) fn LLVMRustSetModulePICLevel(M: &Module);
2544    pub(crate) fn LLVMRustSetModulePIELevel(M: &Module);
2545    pub(crate) fn LLVMRustSetModuleCodeModel(M: &Module, Model: CodeModel);
2546    pub(crate) fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
2547    pub(crate) fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
2548    pub(crate) fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
2549    pub(crate) fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
2550    pub(crate) fn LLVMRustModuleCost(M: &Module) -> u64;
2551    pub(crate) fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
2552
2553    pub(crate) fn LLVMRustThinLTOBufferCreate(
2554        M: &Module,
2555        is_thin: bool,
2556        emit_summary: bool,
2557    ) -> &'static mut ThinLTOBuffer;
2558    pub(crate) fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
2559    pub(crate) fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
2560    pub(crate) fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2561    pub(crate) fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char;
2562    pub(crate) fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t;
2563    pub(crate) fn LLVMRustCreateThinLTOData(
2564        Modules: *const ThinLTOModule,
2565        NumModules: size_t,
2566        PreservedSymbols: *const *const c_char,
2567        PreservedSymbolsLen: size_t,
2568    ) -> Option<&'static mut ThinLTOData>;
2569    pub(crate) fn LLVMRustPrepareThinLTORename(
2570        Data: &ThinLTOData,
2571        Module: &Module,
2572        Target: &TargetMachine,
2573    );
2574    pub(crate) fn LLVMRustPrepareThinLTOResolveWeak(Data: &ThinLTOData, Module: &Module) -> bool;
2575    pub(crate) fn LLVMRustPrepareThinLTOInternalize(Data: &ThinLTOData, Module: &Module) -> bool;
2576    pub(crate) fn LLVMRustPrepareThinLTOImport(
2577        Data: &ThinLTOData,
2578        Module: &Module,
2579        Target: &TargetMachine,
2580    ) -> bool;
2581    pub(crate) fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
2582    pub(crate) fn LLVMRustParseBitcodeForLTO(
2583        Context: &Context,
2584        Data: *const u8,
2585        len: usize,
2586        Identifier: *const c_char,
2587    ) -> Option<&Module>;
2588    pub(crate) fn LLVMRustGetSliceFromObjectDataByName(
2589        data: *const u8,
2590        len: usize,
2591        name: *const u8,
2592        name_len: usize,
2593        out_len: &mut usize,
2594    ) -> *const u8;
2595
2596    pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2597    pub(crate) fn LLVMRustLinkerAdd(
2598        linker: &Linker<'_>,
2599        bytecode: *const c_char,
2600        bytecode_len: usize,
2601    ) -> bool;
2602    pub(crate) fn LLVMRustLinkerFree<'a>(linker: &'a mut Linker<'a>);
2603    pub(crate) fn LLVMRustComputeLTOCacheKey(
2604        key_out: &RustString,
2605        mod_id: *const c_char,
2606        data: &ThinLTOData,
2607    );
2608
2609    pub(crate) fn LLVMRustContextGetDiagnosticHandler(
2610        Context: &Context,
2611    ) -> Option<&DiagnosticHandler>;
2612    pub(crate) fn LLVMRustContextSetDiagnosticHandler(
2613        context: &Context,
2614        diagnostic_handler: Option<&DiagnosticHandler>,
2615    );
2616    pub(crate) fn LLVMRustContextConfigureDiagnosticHandler(
2617        context: &Context,
2618        diagnostic_handler_callback: DiagnosticHandlerTy,
2619        diagnostic_handler_context: *mut c_void,
2620        remark_all_passes: bool,
2621        remark_passes: *const *const c_char,
2622        remark_passes_len: usize,
2623        remark_file: *const c_char,
2624        pgo_available: bool,
2625    );
2626
2627    pub(crate) fn LLVMRustGetMangledName(V: &Value, out: &RustString);
2628
2629    pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32;
2630
2631    pub(crate) fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool;
2632
2633    pub(crate) fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool;
2634
2635    pub(crate) fn LLVMRustGetSymbols(
2636        buf_ptr: *const u8,
2637        buf_len: usize,
2638        state: *mut c_void,
2639        callback: GetSymbolsCallback,
2640        error_callback: GetSymbolsErrorCallback,
2641    ) -> *mut c_void;
2642
2643    pub(crate) fn LLVMRustIs64BitSymbolicFile(buf_ptr: *const u8, buf_len: usize) -> bool;
2644
2645    pub(crate) fn LLVMRustIsECObject(buf_ptr: *const u8, buf_len: usize) -> bool;
2646
2647    pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value);
2648    pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value);
2649}